当前位置: 首页>>代码示例>>Java>>正文


Java VirtualMachineRelocateSpec类代码示例

本文整理汇总了Java中com.vmware.vim25.VirtualMachineRelocateSpec的典型用法代码示例。如果您正苦于以下问题:Java VirtualMachineRelocateSpec类的具体用法?Java VirtualMachineRelocateSpec怎么用?Java VirtualMachineRelocateSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


VirtualMachineRelocateSpec类属于com.vmware.vim25包,在下文中一共展示了VirtualMachineRelocateSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFullClone

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs)
        throws Exception {

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
    cloneSpec.setLocation(relocSpec);
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);

    relocSpec.setDatastore(morDs);
    relocSpec.setPool(morResourcePool);
    ManagedObjectReference morTask = _context.getService().cloneVMTask(_mor, morFolder, cloneName, cloneSpec);

    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }

    return false;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:24,代码来源:VirtualMachineMO.java

示例2: getVirtualMachineRelocateSpec

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public VirtualMachineRelocateSpec getVirtualMachineRelocateSpec(ManagedObjectReference resourcePool,
                                                                ManagedObjectReference host,
                                                                ManagedObjectReference dataStore,
                                                                VmInputs vmInputs) {
    VirtualMachineRelocateSpec vmRelocateSpec = new VirtualMachineRelocateSpec();
    vmRelocateSpec.setPool(resourcePool);
    vmRelocateSpec.setHost(host);
    vmRelocateSpec.setDatastore(dataStore);

    if (vmInputs.isThickProvision()) {
        vmRelocateSpec.setTransform(VirtualMachineRelocateTransformation.FLAT);
    } else {
        vmRelocateSpec.setTransform(VirtualMachineRelocateTransformation.SPARSE);
    }

    return vmRelocateSpec;
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:18,代码来源:VmUtils.java

示例3: relocate

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public boolean relocate(ManagedObjectReference morTargetHost) throws Exception {
    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
    relocateSpec.setHost(morTargetHost);

    ManagedObjectReference morTask = _context.getService().relocateVMTask(_mor, relocateSpec, null);

    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware relocateVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }

    return false;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:17,代码来源:VirtualMachineMO.java

示例4: configureRelocateSpec

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
private VirtualMachineRelocateSpec configureRelocateSpec(ResourcePool resourcePool, Datastore datastore, VirtualMachine master)
        throws Exception, InvalidProperty, RuntimeFault, RemoteException {
   VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
   if (cloningStrategy.equals("linked")) {
      ArrayList<Integer> diskKeys = getIndependentVirtualDiskKeys(master);
      if (diskKeys.size() > 0) {
         Datastore[] dss = master.getDatastores();

         VirtualMachineRelocateSpecDiskLocator[] diskLocator = new VirtualMachineRelocateSpecDiskLocator[diskKeys.size()];
         int count = 0;
         for (Integer key : diskKeys) {
            diskLocator[count] = new VirtualMachineRelocateSpecDiskLocator();
            diskLocator[count].setDatastore(dss[0].getMOR());
            diskLocator[count]
                    .setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.moveAllDiskBackingsAndDisallowSharing
                            .toString());
            diskLocator[count].setDiskId(key);
            count = count + 1;
         }
         rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString());
         rSpec.setDisk(diskLocator);
      } else {
         rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString());
      }
   } else if (cloningStrategy.equals("full")) {
      rSpec.setDatastore(datastore.getMOR());
      rSpec.setPool(resourcePool.getMOR());
      //rSpec.setHost();
   } else
      throw new Exception(String.format("Cloning strategy %s not supported", cloningStrategy));
   return rSpec;
}
 
开发者ID:igreenfield,项目名称:jcloud-vsphere,代码行数:33,代码来源:MasterToVirtualMachineCloneSpec.java

示例5: configureVirtualMachineCloneSpec

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
private VirtualMachineCloneSpec configureVirtualMachineCloneSpec(VirtualMachineRelocateSpec rSpec, String linuxName, boolean postConfiguration) throws Exception {

      VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
      cloneSpec.setPowerOn(true);
      cloneSpec.setTemplate(false);
      //cloneSpec.setSnapshot(currentSnapshot.getMOR());
      cloneSpec.setLocation(rSpec);
      if (postConfiguration) {
         CustomizationSpec customizationSpec = new CustomizationSpec();
         CustomizationLinuxPrep linuxPrep = new CustomizationLinuxPrep();
         CustomizationFixedName fixedName = new CustomizationFixedName();
         fixedName.setName(linuxName);
         linuxPrep.setHostName(fixedName);
         linuxPrep.setDomain("");
         linuxPrep.setHwClockUTC(true);
         //linuxPrep.setTimeZone("Etc/UTC");
         customizationSpec.setIdentity(linuxPrep);
         customizationSpec.setGlobalIPSettings(new CustomizationGlobalIPSettings());
         CustomizationAdapterMapping[] nicSettingMap = new CustomizationAdapterMapping[1];
         nicSettingMap[0] = new CustomizationAdapterMapping();
         nicSettingMap[0].adapter = new CustomizationIPSettings();
         nicSettingMap[0].adapter.setIp(new CustomizationDhcpIpGenerator());
         customizationSpec.setNicSettingMap(nicSettingMap);
         cloneSpec.setCustomization(customizationSpec);
      }


      return cloneSpec;
   }
 
开发者ID:igreenfield,项目名称:jcloud-vsphere,代码行数:30,代码来源:MasterToVirtualMachineCloneSpec.java

示例6: createCloneSpec

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
protected VirtualMachineCloneSpec createCloneSpec(String computeResourceName, String resourcePoolName,
        String datastoreName) {
    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();

    // ComputeResource
    ComputeResource computeResource = vmwareClient.search(ComputeResource.class, computeResourceName);
    if (computeResource == null) {
        // ComputeResourceが見つからない場合
        throw new AutoException("EPROCESS-000503", computeResourceName);
    }

    // ResourcePool
    if (StringUtils.isEmpty(resourcePoolName)) {
        resourcePoolName = "Resources";
    }
    ResourcePool resourcePool = vmwareClient.search(computeResource, ResourcePool.class, resourcePoolName);
    if (resourcePool == null) {
        // ResourcePoolが見つからない場合
        throw new AutoException("EPROCESS-000504", resourcePoolName);
    }
    relocateSpec.setPool(resourcePool.getMOR());

    // Datastore
    if (StringUtils.isNotEmpty(datastoreName)) {
        // データストアが指定されている場合
        Datastore datastore = vmwareClient.search(Datastore.class, datastoreName);
        if (datastore == null) {
            // データストアが見つからない場合
            throw new AutoException("EPROCESS-000505", datastoreName);
        }
        relocateSpec.setDatastore(datastore.getMOR());
    }

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setLocation(relocateSpec);
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);

    return cloneSpec;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:41,代码来源:VmwareProcessClient.java

示例7: cloneVM

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
/**
 * Method used to connect to data center and clone a virtual machine identified by the inputs provided.
 *
 * @param httpInputs Object that has all the inputs necessary to made a connection to data center
 * @param vmInputs   Object that has all the specific inputs necessary to identify the virtual machine that will be
 *                   cloned
 * @return Map with String as key and value that contains returnCode of the operation, success message with task id
 *         of the execution or failure message and the exception if there is one
 * @throws Exception
 */
public Map<String, String> cloneVM(HttpInputs httpInputs, VmInputs vmInputs) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs);
    try {
        ManagedObjectReference vmMor = new MorObjectHandler().getMor(connectionResources,
                ManagedObjectType.VIRTUAL_MACHINE.getValue(), vmInputs.getVirtualMachineName());

        if (vmMor != null) {
            VmUtils utils = new VmUtils();
            ManagedObjectReference folder = utils.getMorFolder(vmInputs.getFolderName(), connectionResources);
            ManagedObjectReference resourcePool = utils.getMorResourcePool(vmInputs.getCloneResourcePool(), connectionResources);
            ManagedObjectReference host = utils.getMorHost(vmInputs.getCloneHost(), connectionResources, vmMor);
            ManagedObjectReference dataStore = utils.getMorDataStore(vmInputs.getCloneDataStore(), connectionResources,
                    vmMor, vmInputs);

            VirtualMachineRelocateSpec vmRelocateSpec = utils.getVirtualMachineRelocateSpec(resourcePool, host, dataStore, vmInputs);

            VirtualMachineCloneSpec cloneSpec = new VmConfigSpecs().getCloneSpec(vmInputs, vmRelocateSpec);

            ManagedObjectReference taskMor = connectionResources.getVimPortType()
                    .cloneVMTask(vmMor, folder, vmInputs.getCloneName(), cloneSpec);

            return new ResponseHelper(connectionResources, taskMor).getResultsMap("Success: The [" +
                    vmInputs.getVirtualMachineName() + "] VM was successfully cloned. The taskId is: " +
                    taskMor.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be cloned.");
        } else {
            return ResponseUtils.getVmNotFoundResultsMap(vmInputs);
        }
    } catch (Exception ex) {
        return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE);
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:47,代码来源:VmService.java

示例8: changeDatastore

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public boolean changeDatastore(VirtualMachineRelocateSpec relocateSpec) throws Exception {
    ManagedObjectReference morTask = _context.getVimClient().getService().relocateVMTask(_mor, relocateSpec, VirtualMachineMovePriority.DEFAULT_PRIORITY);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware RelocateVM_Task to change datastore failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:12,代码来源:VirtualMachineMO.java

示例9: changeHost

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public boolean changeHost(VirtualMachineRelocateSpec relocateSpec) throws Exception {
    ManagedObjectReference morTask = _context.getService().relocateVMTask(_mor, relocateSpec, VirtualMachineMovePriority.DEFAULT_PRIORITY);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware RelocateVM_Task to change host failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:12,代码来源:VirtualMachineMO.java

示例10: createInstanceFromSnapshot

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public ComputeState createInstanceFromSnapshot() throws Exception {
    String message = "";
    if (this.ctx.snapshotMoRef == null) {
        message = String.format("No MoRef found for the specified snapshot %s",
              this.ctx.child.documentSelfLink);

        logger.error(message);

        this.ctx.fail(new IllegalStateException(message));
    }

    if (this.ctx.referenceComputeMoRef == null) {
        if (this.ctx.snapshotMoRef == null) {
            message = String.format("No MoRef found for the reference compute for linkedclone creation for %s.",
                  this.ctx.child.documentSelfLink);

            logger.error(message);

            this.ctx.fail(new IllegalStateException(message));
        }
    }

    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
    relocateSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions
            .CREATE_NEW_CHILD_DISK_BACKING.value());

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setPowerOn(false);
    cloneSpec.setLocation(relocateSpec);
    cloneSpec.setSnapshot(this.ctx.snapshotMoRef);
    cloneSpec.setTemplate(false);

    ManagedObjectReference folder = getVmFolder();
    String displayName = this.ctx.child.name;

    ManagedObjectReference linkedCloneTask = getVimPort()
            .cloneVMTask(this.ctx.referenceComputeMoRef, folder, displayName, cloneSpec);

    TaskInfo info = waitTaskEnd(linkedCloneTask);

    if (info.getState() == TaskInfoState.ERROR) {
        MethodFault fault = info.getError().getFault();
        if (fault instanceof FileAlreadyExists) {
            // a .vmx file already exists, assume someone won the race to create the vm
            return null;
        } else {
            return VimUtils.rethrow(info.getError());
        }
    }

    ManagedObjectReference clonedVM = (ManagedObjectReference) info.getResult();
    if (clonedVM == null) {
        // vm was created by someone else
        return null;
    }
    // store reference to created vm for further processing
    this.vm = clonedVM;

    customizeAfterClone();

    ComputeState state = new ComputeState();
    state.resourcePoolLink = VimUtils
          .firstNonNull(this.ctx.child.resourcePoolLink, this.ctx.parent.resourcePoolLink);

    return state;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:67,代码来源:InstanceClient.java

示例11: cloneVm

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
private ManagedObjectReference cloneVm(ManagedObjectReference template) throws Exception {
    ManagedObjectReference folder = getVmFolder();
    List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.bootDisk);
    ManagedObjectReference datastore = getDataStoreForDisk(this.bootDisk, pbmSpec);
    ManagedObjectReference resourcePool = getResourcePool();

    Map<String, Object> props = this.get.entityProps(template, VimPath.vm_config_hardware_device);

    ArrayOfVirtualDevice devices = (ArrayOfVirtualDevice) props
            .get(VimPath.vm_config_hardware_device);

    VirtualDisk vd = devices.getVirtualDevice().stream()
            .filter(d -> d instanceof VirtualDisk)
            .map(d -> (VirtualDisk) d).findFirst().orElse(null);

    VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
    relocSpec.setDatastore(datastore);
    if (pbmSpec != null) {
        pbmSpec.stream().forEach(spec -> {
            relocSpec.getProfile().add(spec);
        });
    }
    relocSpec.setFolder(folder);
    relocSpec.setPool(resourcePool);
    relocSpec.setDiskMoveType(computeDiskMoveType().value());

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setLocation(relocSpec);

    //Set the provisioning type of the parent disk.
    VirtualMachineRelocateSpecDiskLocator diskProvisionTypeLocator = setProvisioningType(vd, datastore,
            pbmSpec);
    if (diskProvisionTypeLocator != null) {
        cloneSpec.getLocation().getDisk().add(diskProvisionTypeLocator);
    }

    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);

    String displayName = this.ctx.child.name;

    ManagedObjectReference cloneTask = getVimPort()
            .cloneVMTask(template, folder, displayName, cloneSpec);

    TaskInfo info = waitTaskEnd(cloneTask);

    if (info.getState() == TaskInfoState.ERROR) {
        MethodFault fault = info.getError().getFault();
        if (fault instanceof FileAlreadyExists) {
            // a .vmx file already exists, assume someone won the race to create the vm
            return null;
        } else {
            return VimUtils.rethrow(info.getError());
        }
    }

    return (ManagedObjectReference) info.getResult();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:59,代码来源:InstanceClient.java

示例12: checkRelocate_Task

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public Task checkRelocate_Task(VirtualMachine vm, VirtualMachineRelocateSpec spec, String[] testType) throws InvalidState, RuntimeFault, RemoteException
{
	ManagedObjectReference taskMor = getVimService().checkRelocate_Task(getMOR(), 
			vm.getMOR(), spec, testType);
	return new Task(getServerConnection(), taskMor);
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:7,代码来源:VirtualMachineProvisioningChecker.java

示例13: main

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public static void main(String[] args) throws Exception
  {
   CommandLineParser clp = new CommandLineParser(constructOptions(), args);
   
   String urlStr = clp.get_option("url");
   String username = clp.get_option("username");
   String password = clp.get_option("password");
   String cloneName = clp.get_option("CloneName");
   String vmPath = clp.get_option("vmPath");
   String datacenterName= clp.get_option("DatacenterName");

   try
   {
	   ServiceInstance si = new ServiceInstance(new URL(urlStr), username, password, true);
	   VirtualMachine vm = (VirtualMachine) si.getSearchIndex().findByInventoryPath(vmPath);
	   Datacenter dc = (Datacenter) si.getSearchIndex().findByInventoryPath(datacenterName);
	   
	   if(vm==null || dc ==null)
	   {
		   System.out.println("VirtualMachine or Datacenter path is NOT correct. Pls double check. ");
		   return;
	   }
	   Folder vmFolder = dc.getVmFolder();

	   VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
	   cloneSpec.setLocation(new VirtualMachineRelocateSpec());
	   cloneSpec.setPowerOn(false);
	   cloneSpec.setTemplate(false);

	   Task task = vm.cloneVM_Task(vmFolder, cloneName, cloneSpec);
	   System.out.println("Launching the VM clone task. It might take a while. Please wait for the result ...");
	   
	   String status = 	task.waitForMe();
	   if(status==Task.SUCCESS)
	   {
            System.out.println("Virtual Machine got cloned successfully.");
	   }
	   else
	   {
		   System.out.println("Failure -: Virtual Machine cannot be cloned");
	   }
   }
   catch(RemoteException re)
   {
	   re.printStackTrace();
   }
   catch(MalformedURLException mue)
   {
	   mue.printStackTrace();
   }
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:52,代码来源:VMClone.java

示例14: main

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
  if(args.length!=5)
  {
    System.out.println("Usage: java CloneVM <url> " +
    "<username> <password> <vmname> <clonename>");
    System.exit(0);
  }

  String vmname = args[3];
  String cloneName = args[4];

  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  Folder rootFolder = si.getRootFolder();
  VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
      rootFolder).searchManagedEntity(
          "VirtualMachine", vmname);

  if(vm==null)
  {
    System.out.println("No VM " + vmname + " found");
    si.getServerConnection().logout();
    return;
  }

  VirtualMachineCloneSpec cloneSpec = 
    new VirtualMachineCloneSpec();
  cloneSpec.setLocation(new VirtualMachineRelocateSpec());
  cloneSpec.setPowerOn(false);
  cloneSpec.setTemplate(false);

  Task task = vm.cloneVM_Task((Folder) vm.getParent(), 
      cloneName, cloneSpec);
  System.out.println("Launching the VM clone task. " +
  		"Please wait ...");

  String status = task.waitForMe();
  if(status==Task.SUCCESS)
  {
    System.out.println("VM got cloned successfully.");
  }
  else
  {
    System.out.println("Failure -: VM cannot be cloned");
  }
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:49,代码来源:CloneVM.java

示例15: createMachine

import com.vmware.vim25.VirtualMachineRelocateSpec; //导入依赖的package包/类
@Override
public String createMachine( TargetHandlerParameters parameters ) throws TargetException {

	this.logger.fine( "Creating a new VM @ VMware." );

	// For IaaS, we only expect root instance names to be passed
	if( InstanceHelpers.countInstances( parameters.getScopedInstancePath()) > 1 )
		throw new TargetException( "Only root instances can be passed in arguments." );

	String rootInstanceName = InstanceHelpers.findRootInstancePath( parameters.getScopedInstancePath());

	// Deal with the creation
	try {
		System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser");
		Map<String,String> targetProperties = parameters.getTargetProperties();
		final String machineImageId = targetProperties.get( TEMPLATE );
		final ServiceInstance vmwareServiceInstance = getServiceInstance( targetProperties );

		final ComputeResource vmwareComputeResource = (ComputeResource)(
				new InventoryNavigator( vmwareServiceInstance.getRootFolder())
				.searchManagedEntity("ComputeResource", targetProperties.get( CLUSTER )));

		// Generate the user data first, so that nothing has been done on the IaaS if it fails
		String userData = UserDataHelpers.writeUserDataAsString(
				parameters.getMessagingProperties(),
				parameters.getDomain(),
				parameters.getApplicationName(),
				rootInstanceName );

		VirtualMachine vm = getVirtualMachine( vmwareServiceInstance, machineImageId );
		String vmwareDataCenter = targetProperties.get( DATA_CENTER );
		Folder vmFolder =
				((Datacenter)(new InventoryNavigator( vmwareServiceInstance.getRootFolder())
				.searchManagedEntity("Datacenter", vmwareDataCenter)))
				.getVmFolder();

		this.logger.fine("machineImageId=" + machineImageId);
		if (vm == null || vmFolder == null)
			throw new TargetException("VirtualMachine (= " + vm + " ) or Datacenter path (= " + vmFolder + " ) is NOT correct. Please, double check.");

		VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
		cloneSpec.setLocation(new VirtualMachineRelocateSpec());
		cloneSpec.setPowerOn(false);
		cloneSpec.setTemplate(true);

		VirtualMachineConfigSpec vmSpec = new VirtualMachineConfigSpec();
		vmSpec.setAnnotation( userData );
		cloneSpec.setConfig(vmSpec);

		Task task = vm.cloneVM_Task( vmFolder, rootInstanceName, cloneSpec );
		this.logger.fine("Cloning the template: "+ machineImageId +" ...");
		String status = task.waitForTask();
		if (!status.equals(Task.SUCCESS))
			throw new TargetException("Failure: Virtual Machine cannot be cloned." );

		VirtualMachine vm2 = getVirtualMachine( vmwareServiceInstance, rootInstanceName );
		this.logger.fine("Transforming the clone template to Virtual machine ...");
		vm2.markAsVirtualMachine( vmwareComputeResource.getResourcePool(), null);

		DynamicProperty dprop = new DynamicProperty();
		dprop.setName("guestinfo.userdata");
		dprop.setVal(userData);
		vm2.getGuest().setDynamicProperty(new DynamicProperty[]{dprop});

		task = vm2.powerOnVM_Task(null);
		this.logger.fine("Starting the virtual machine: "+ rootInstanceName +" ...");
		status = task.waitForTask();
		if( ! status.equals( Task.SUCCESS ))
			throw new TargetException("Failure: Virtual Machine cannot be started." );

		return vm2.getName();

	} catch( Exception e ) {
		throw new TargetException( e );
	}
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:77,代码来源:VmwareIaasHandler.java


注:本文中的com.vmware.vim25.VirtualMachineRelocateSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。