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


Java VirtualMachineCloneSpec.setTemplate方法代码示例

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


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

示例1: createFullClone

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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: configureVirtualMachineCloneSpec

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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

示例3: createCloneSpec

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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

示例4: createInstanceFromSnapshot

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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

示例5: cloneVm

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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

示例6: main

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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

示例7: main

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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

示例8: createMachine

import com.vmware.vim25.VirtualMachineCloneSpec; //导入方法依赖的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

示例9: createLinkedClone

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

    assert (morBaseSnapshot != null);
    assert (morFolder != null);
    assert (morResourcePool != null);
    assert (morDs != null);

    VirtualDisk[] independentDisks = getAllIndependentDiskDevice();
    VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
    if (independentDisks.length > 0) {
        List<VirtualMachineRelocateSpecDiskLocator> diskLocator = new ArrayList<VirtualMachineRelocateSpecDiskLocator>(independentDisks.length);
        for (int i = 0; i < independentDisks.length; i++) {
            VirtualMachineRelocateSpecDiskLocator loc = new VirtualMachineRelocateSpecDiskLocator();
            loc.setDatastore(morDs);
            loc.setDiskId(independentDisks[i].getKey());
            loc.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.value());
            diskLocator.add(loc);
        }

        rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
        rSpec.getDisk().addAll(diskLocator);
    } else {
        rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
    }
    rSpec.setPool(morResourcePool);

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);
    cloneSpec.setLocation(rSpec);
    cloneSpec.setSnapshot(morBaseSnapshot);

    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,代码行数:46,代码来源:VirtualMachineMO.java


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