@Before
  public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    storageCmd = PowerMockito.mock(CopyCommand.class);
    doReturn(context).when(_resource).getServiceContext(null);
    when(cmd.getVirtualMachine()).thenReturn(vmSpec);

    when(storageCmd.getSrcTO()).thenReturn(srcDataTO);
    when(srcDataTO.getDataStore()).thenReturn(srcDataNfsTO);
    when(srcDataNfsTO.getNfsVersion()).thenReturn(NFS_VERSION);
    when(videoCard.getVideoRamSizeInKB()).thenReturn(VIDEO_CARD_MEMORY_SIZE);
    when(volume.getPath()).thenReturn(VOLUME_PATH);

    when(storageCmd.getDestTO()).thenReturn(destDataTO);
    when(destDataTO.getHypervisorType()).thenReturn(HypervisorType.VMware);
    when(destDataTO.getDataStore()).thenReturn(destDataStoreTO);
    when(destDataStoreTO.isFullCloneFlag()).thenReturn(FULL_CLONE_FLAG);
    when(volume.getPath()).thenReturn(VOLUME_PATH);
    when(vmSpec.getDetails()).thenReturn(specsArray);

    when(vmMo.getContext()).thenReturn(context);
    when(vmMo.getRunningHost()).thenReturn(host);
    when(host.getMor()).thenReturn(hostRef);
    when(context.getVimClient()).thenReturn(client);
    when(client.getMoRefProp(hostRef, "parent")).thenReturn(computeRef);
    when(client.getMoRefProp(computeRef, "environmentBrowser")).thenReturn(envRef);
    when(context.getService()).thenReturn(vimService);
    when(vimService.queryTargetCapabilities(envRef, hostRef)).thenReturn(hostCapability);
    when(hostCapability.isNestedHVSupported()).thenReturn(true);
  }
Ejemplo n.º 2
0
  @Deprecated
  private ManagedObjectReference addHostToVCenterCluster(
      VmwareContext serviceContext,
      ManagedObjectReference morCluster,
      String host,
      String userName,
      String password)
      throws Exception {

    VmwareClient vclient = serviceContext.getVimClient();
    ManagedObjectReference morHost = vclient.getDecendentMoRef(morCluster, "HostSystem", host);
    if (morHost == null) {
      HostConnectSpec hostSpec = new HostConnectSpec();
      hostSpec.setUserName(userName);
      hostSpec.setPassword(password);
      hostSpec.setHostName(host);
      hostSpec.setForce(true); // forcely take over the host

      ManagedObjectReference morTask =
          serviceContext.getService().addHostTask(morCluster, hostSpec, true, null, null);
      boolean taskResult = vclient.waitForTask(morTask);
      if (!taskResult) {
        s_logger.error(
            "Unable to add host "
                + host
                + " to vSphere cluster due to "
                + TaskMO.getTaskFailureInfo(serviceContext, morTask));
        throw new CloudRuntimeException(
            "Unable to add host " + host + " to vSphere cluster due to " + taskResult);
      }
      serviceContext.waitForTaskProgressDone(morTask);

      // init morHost after it has been created
      morHost = vclient.getDecendentMoRef(morCluster, "HostSystem", host);
      if (morHost == null) {
        throw new CloudRuntimeException(
            "Successfully added host into vSphere but unable to find it later on?!. Please make sure you are either using IP address or full qualified domain name for host");
      }
    }

    // For ESX host, we need to enable host firewall to allow VNC access
    HostMO hostMo = new HostMO(serviceContext, morHost);
    HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
    if (firewallMo != null) {
      firewallMo.enableRuleset("vncServer");
      firewallMo.refreshFirewall();
    }
    return morHost;
  }