Java Code Examples for com.vmware.vim25.VirtualMachineConfigSpec#setNumCPUs()
The following examples show how to use
com.vmware.vim25.VirtualMachineConfigSpec#setNumCPUs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VmUtils.java From cs-actions with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: VmwareHelper.java From cloudstack with Apache License 2.0 | 6 votes |
public static void setVmScaleUpConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB, boolean limitCpuUse) { // VM config for scaling up vmConfig.setMemoryMB((long)memoryMB); vmConfig.setNumCPUs(cpuCount); ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo(); if (limitCpuUse) { cpuInfo.setLimit((long)(cpuSpeedMHz * cpuCount)); } else { cpuInfo.setLimit(-1L); } cpuInfo.setReservation((long)cpuReservedMhz); vmConfig.setCpuAllocation(cpuInfo); ResourceAllocationInfo memInfo = new ResourceAllocationInfo(); memInfo.setLimit((long)memoryMB); memInfo.setReservation((long)memoryReserveMB); vmConfig.setMemoryAllocation(memInfo); }
Example 3
Source File: VM.java From development with Apache License 2.0 | 5 votes |
/** * 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"); }
Example 4
Source File: VmwareHelper.java From cloudstack with Apache License 2.0 | 5 votes |
public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB, String guestOsIdentifier, boolean limitCpuUse) { // VM config basics vmConfig.setMemoryMB((long)memoryMB); vmConfig.setNumCPUs(cpuCount); ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo(); if (limitCpuUse) { cpuInfo.setLimit(((long)cpuSpeedMHz * cpuCount)); } else { cpuInfo.setLimit(-1L); } cpuInfo.setReservation((long)cpuReservedMhz); vmConfig.setCpuAllocation(cpuInfo); if (cpuSpeedMHz != cpuReservedMhz) { vmConfig.setCpuHotAddEnabled(true); } if (memoryMB != memoryReserveMB) { vmConfig.setMemoryHotAddEnabled(true); } ResourceAllocationInfo memInfo = new ResourceAllocationInfo(); memInfo.setLimit((long)memoryMB); memInfo.setReservation((long)memoryReserveMB); vmConfig.setMemoryAllocation(memInfo); vmConfig.setGuestId(guestOsIdentifier); }
Example 5
Source File: HypervisorHostHelper.java From cloudstack with Apache License 2.0 | 4 votes |
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName) throws Exception { // Allow worker VM to float within cluster so that we will have better chance to // create it successfully ManagedObjectReference morCluster = hyperHost.getHyperHostCluster(); if (morCluster != null) hyperHost = new ClusterMO(hyperHost.getContext(), morCluster); VirtualMachineMO workingVM = null; VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); vmConfig.setName(vmName); vmConfig.setMemoryMB((long)4); vmConfig.setNumCPUs(1); vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value()); VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo(); fileInfo.setVmPathName(dsMo.getDatastoreRootPath()); vmConfig.setFiles(fileInfo); VirtualLsiLogicController scsiController = new VirtualLsiLogicController(); scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING); scsiController.setBusNumber(0); scsiController.setKey(1); VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec(); scsiControllerSpec.setDevice(scsiController); scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(scsiControllerSpec); if (hyperHost.createVm(vmConfig)) { // Ugly work-around, it takes time for newly created VM to appear for (int i = 0; i < 10 && workingVM == null; i++) { workingVM = hyperHost.findVmOnHyperHost(vmName); try { Thread.sleep(1000); } catch (InterruptedException e) { s_logger.debug("[ignored] interupted while waiting to config vm."); } } } if (workingVM != null) { workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER, "true"); String workerTag = String.format("%d-%s", System.currentTimeMillis(), hyperHost.getContext().getStockObject("noderuninfo")); workingVM.setCustomFieldValue(CustomFieldConstants.CLOUD_WORKER_TAG, workerTag); } return workingVM; }