本文整理汇总了Java中com.vmware.vim25.mo.VirtualMachine.cloneVM_Task方法的典型用法代码示例。如果您正苦于以下问题:Java VirtualMachine.cloneVM_Task方法的具体用法?Java VirtualMachine.cloneVM_Task怎么用?Java VirtualMachine.cloneVM_Task使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vmware.vim25.mo.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.cloneVM_Task方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cloneMaster
import com.vmware.vim25.mo.VirtualMachine; //导入方法依赖的package包/类
private VirtualMachine cloneMaster(VirtualMachine master, String tag, String name, VirtualMachineCloneSpec cloneSpec, String folderName) {
VirtualMachine cloned = null;
try {
FolderNameToFolderManagedEntity toFolderManagedEntity = new FolderNameToFolderManagedEntity(serviceInstance, master);
Folder folder = toFolderManagedEntity.apply(folderName);
Task task = master.cloneVM_Task(folder, name, cloneSpec);
String result = task.waitForTask();
if (result.equals(Task.SUCCESS)) {
logger.trace("<< after clone search for VM with name: " + name);
Retryer<VirtualMachine> retryer = RetryerBuilder.<VirtualMachine>newBuilder()
.retryIfResult(Predicates.<VirtualMachine>isNull())
.withStopStrategy(StopStrategies.stopAfterAttempt(5))
.retryIfException().withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
.build();
cloned = retryer.call(new GetVirtualMachineCallable(name, folder, serviceInstance.get().getInstance().getRootFolder()));
} else {
String errorMessage = task.getTaskInfo().getError().getLocalizedMessage();
logger.error(errorMessage);
}
} catch (Exception e) {
if (e instanceof NoPermission){
NoPermission noPermission = (NoPermission)e;
logger.error("NoPermission: " + noPermission.getPrivilegeId());
}
logger.error("Can't clone vm: " + e.toString(), e);
propagate(e);
}
if (cloned == null)
logger.error("<< Failed to get cloned VM. " + name);
return checkNotNull(cloned, "cloned");
}
示例2: main
import com.vmware.vim25.mo.VirtualMachine; //导入方法依赖的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();
}
}
示例3: main
import com.vmware.vim25.mo.VirtualMachine; //导入方法依赖的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");
}
}
示例4: createMachine
import com.vmware.vim25.mo.VirtualMachine; //导入方法依赖的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 );
}
}