本文整理汇总了Java中com.vmware.vim25.VirtualMachineConfigSpec.setAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java VirtualMachineConfigSpec.setAnnotation方法的具体用法?Java VirtualMachineConfigSpec.setAnnotation怎么用?Java VirtualMachineConfigSpec.setAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vmware.vim25.VirtualMachineConfigSpec
的用法示例。
在下文中一共展示了VirtualMachineConfigSpec.setAnnotation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPopulatedVmConfigSpec
import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
VirtualMachineConfigSpec getPopulatedVmConfigSpec(VirtualMachineConfigSpec vmConfigSpec, VmInputs vmInputs, String name) {
vmConfigSpec.setName(name);
vmConfigSpec.setNumCPUs(vmInputs.getIntNumCPUs());
vmConfigSpec.setMemoryMB(vmInputs.getLongVmMemorySize());
vmConfigSpec.setAnnotation(vmInputs.getDescription());
if (vmInputs.getCoresPerSocket() != null) {
vmConfigSpec.setNumCoresPerSocket(InputUtils.getIntInput(vmInputs.getCoresPerSocket(), DEFAULT_CORES_PER_SOCKET));
}
if (vmInputs.getGuestOsId() != null) {
vmConfigSpec.setGuestId(vmInputs.getGuestOsId());
}
return vmConfigSpec;
}
示例2: reconfigureVirtualMachine
import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
/**
* Reconfigures VMware instance. Memory, CPU, disk space and network
* adapter. The VM has been created and must be stopped to reconfigure the
* hardware.
*/
public TaskInfo reconfigureVirtualMachine(VMPropertyHandler paramHandler)
throws Exception {
LOG.debug("instanceName: " + instanceName);
VimPortType service = vmw.getConnection().getService();
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
vmConfigSpec
.setMemoryMB(Long.valueOf(paramHandler.getConfigMemoryMB()));
vmConfigSpec.setNumCPUs(Integer.valueOf(paramHandler.getConfigCPUs()));
String reqUser = paramHandler
.getServiceSetting(VMPropertyHandler.REQUESTING_USER);
String comment = Messages.get(paramHandler.getLocale(), "vm_comment",
new Object[] { paramHandler.getSettings().getOrganizationName(),
paramHandler.getSettings().getSubscriptionId(),
reqUser });
String annotation = vmConfigSpec.getAnnotation();
comment = updateComment(comment, annotation);
vmConfigSpec.setAnnotation(comment);
DiskManager diskManager = new DiskManager(vmw, paramHandler);
diskManager.reconfigureDisks(vmConfigSpec, vmInstance);
NetworkManager.configureNetworkAdapter(vmw, vmConfigSpec, paramHandler,
vmInstance);
LOG.debug("Call vSphere API: reconfigVMTask()");
ManagedObjectReference reconfigureTask = service
.reconfigVMTask(vmInstance, vmConfigSpec);
return (TaskInfo) vmw.getServiceUtil()
.getDynamicProperty(reconfigureTask, "info");
}
示例3: updateCommentField
import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public TaskInfo updateCommentField(String comment) throws Exception {
LOG.debug("instanceName: " + instanceName + " comment: " + comment);
VimPortType service = vmw.getConnection().getService();
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
String annotation = vmConfigSpec.getAnnotation();
comment = updateComment(comment, annotation);
vmConfigSpec.setAnnotation(comment);
LOG.debug("Call vSphere API: reconfigVMTask()");
ManagedObjectReference reconfigureTask = service
.reconfigVMTask(vmInstance, vmConfigSpec);
return (TaskInfo) vmw.getServiceUtil()
.getDynamicProperty(reconfigureTask, "info");
}
示例4: main
import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
if(args.length!=3)
{
System.out.println("Usage: java CreateVM <url> " +
"<username> <password>");
System.exit(0);
}
String dcName = "ha-datacenter";
String vmName = "vimasterVM";
long memorySizeMB = 500;
int cupCount = 1;
String guestOsId = "sles10Guest";
long diskSizeKB = 1000000;
// mode: persistent|independent_persistent,
// independent_nonpersistent
String diskMode = "persistent";
String datastoreName = "storage1 (2)";
String netName = "VM Network";
String nicName = "Network Adapter 1";
ServiceInstance si = new ServiceInstance(
new URL(args[0]), args[1], args[2], true);
Folder rootFolder = si.getRootFolder();
Datacenter dc = (Datacenter) new InventoryNavigator(
rootFolder).searchManagedEntity("Datacenter", dcName);
ResourcePool rp = (ResourcePool) new InventoryNavigator(
dc).searchManagedEntities("ResourcePool")[0];
Folder vmFolder = dc.getVmFolder();
// create vm config spec
VirtualMachineConfigSpec vmSpec =
new VirtualMachineConfigSpec();
vmSpec.setName(vmName);
vmSpec.setAnnotation("VirtualMachine Annotation");
vmSpec.setMemoryMB(memorySizeMB);
vmSpec.setNumCPUs(cupCount);
vmSpec.setGuestId(guestOsId);
// create virtual devices
int cKey = 1000;
VirtualDeviceConfigSpec scsiSpec = createScsiSpec(cKey);
VirtualDeviceConfigSpec diskSpec = createDiskSpec(
datastoreName, cKey, diskSizeKB, diskMode);
VirtualDeviceConfigSpec nicSpec = createNicSpec(
netName, nicName);
vmSpec.setDeviceChange(new VirtualDeviceConfigSpec[]
{scsiSpec, diskSpec, nicSpec});
// create vm file info for the vmx file
VirtualMachineFileInfo vmfi = new VirtualMachineFileInfo();
vmfi.setVmPathName("["+ datastoreName +"]");
vmSpec.setFiles(vmfi);
// call the createVM_Task method on the vm folder
Task task = vmFolder.createVM_Task(vmSpec, rp, null);
String result = task.waitForMe();
if(result == Task.SUCCESS)
{
System.out.println("VM Created Sucessfully");
}
else
{
System.out.println("VM could not be created. ");
}
}
示例5: createMachine
import com.vmware.vim25.VirtualMachineConfigSpec; //导入方法依赖的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 );
}
}