com.vmware.vim25.VirtualDeviceConfigSpecOperation Java Examples
The following examples show how to use
com.vmware.vim25.VirtualDeviceConfigSpecOperation.
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: NetworkManager.java From development with Apache License 2.0 | 6 votes |
private static void replaceNetworkAdapter( VirtualMachineConfigSpec vmConfigSpec, VirtualDevice oldNIC, ManagedObjectReference newNetworkRef, String newNetworkName) throws Exception { logger.debug("new network: " + newNetworkName); VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo(); nicBacking.setDeviceName(newNetworkName); nicBacking.setNetwork(newNetworkRef); nicBacking.setUseAutoDetect(true); oldNIC.setBacking(nicBacking); VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo(); info.setConnected(true); info.setStartConnected(true); info.setAllowGuestControl(true); oldNIC.setConnectable(info); // oldNIC.getConnectable().setConnected(true); // oldNIC.getConnectable().setStartConnected(true); VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec(); vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT); vmDeviceSpec.setDevice(oldNIC); vmConfigSpec.getDeviceChange().add(vmDeviceSpec); }
Example #2
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 6 votes |
public void ensureLsiLogicSasDeviceControllers(int count, int availableBusNum) throws Exception { int scsiControllerKey = getLsiLogicSasDeviceControllerKeyNoException(); if (scsiControllerKey < 0) { VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); int busNum = availableBusNum; while (busNum < count) { VirtualLsiLogicSASController scsiController = new VirtualLsiLogicSASController(); scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING); scsiController.setBusNumber(busNum); scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT); VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec(); scsiControllerSpec.setDevice(scsiController); scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(scsiControllerSpec); busNum++; } if (configureVm(vmConfig)) { throw new Exception("Unable to add Scsi controller of type LsiLogic SAS."); } } }
Example #3
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 6 votes |
public void ensureScsiDeviceControllers(int count, int availableBusNum) throws Exception { int scsiControllerKey = getScsiDeviceControllerKeyNoException(); if (scsiControllerKey < 0) { VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); int busNum = availableBusNum; while (busNum < count) { VirtualLsiLogicController scsiController = new VirtualLsiLogicController(); scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING); scsiController.setBusNumber(busNum); scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT); VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec(); scsiControllerSpec.setDevice(scsiController); scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(scsiControllerSpec); busNum++; } if (configureVm(vmConfig)) { throw new Exception("Unable to add Scsi controllers to the VM " + getName()); } else { s_logger.info("Successfully added " + count + " SCSI controllers."); } } }
Example #4
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 6 votes |
public void ensureScsiDeviceController() throws Exception { int scsiControllerKey = getScsiDeviceControllerKeyNoException(); if (scsiControllerKey < 0) { VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); // Scsi controller 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 (configureVm(vmConfig)) { throw new Exception("Unable to add Scsi controller"); } } }
Example #5
Source File: VmUtils.java From cs-actions with Apache License 2.0 | 6 votes |
VirtualDeviceConfigSpec getNicSpecs(String fileName, List<VirtualDevice> virtualDevicesList, VirtualDeviceConfigSpecOperation operation, String addressType, Integer key, String parameter, VmInputs vmInputs) { VirtualDeviceConfigSpec nicSpecs = new VirtualDeviceConfigSpec(); VirtualEthernetCard nic; if (Operation.ADD.toString().equalsIgnoreCase(parameter)) { nic = getEth(fileName, addressType, key); return getNicOpSpec(nicSpecs, operation, nic); } else { nic = findVirtualDevice(VirtualEthernetCard.class, virtualDevicesList, vmInputs); if (nic != null) { return getNicOpSpec(nicSpecs, operation, nic); } } throw new RuntimeException("No nic named: [" + vmInputs.getUpdateValue() + "] can be found."); }
Example #6
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 6 votes |
public void ensureLsiLogicDeviceControllers(int count, int availableBusNum) throws Exception { int scsiControllerKey = getLsiLogicDeviceControllerKeyNoException(); if (scsiControllerKey < 0) { VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); int busNum = availableBusNum; while (busNum < count) { VirtualLsiLogicController scsiController = new VirtualLsiLogicController(); scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING); scsiController.setBusNumber(busNum); scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT); VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec(); scsiControllerSpec.setDevice(scsiController); scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(scsiControllerSpec); busNum++; } if (configureVm(vmConfig)) { throw new Exception("Unable to add Lsi Logic controllers to the VM " + getName()); } else { s_logger.info("Successfully added " + count + " LsiLogic Parallel SCSI controllers."); } } }
Example #7
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 6 votes |
public void ensurePvScsiDeviceController(int requiredNumScsiControllers, int availableBusNum) throws Exception { VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); int busNum = availableBusNum; while (busNum < requiredNumScsiControllers) { ParaVirtualSCSIController scsiController = new ParaVirtualSCSIController(); scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING); scsiController.setBusNumber(busNum); scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT); VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec(); scsiControllerSpec.setDevice(scsiController); scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(scsiControllerSpec); busNum++; } if (configureVm(vmConfig)) { throw new Exception("Unable to add Scsi controllers to the VM " + getName()); } else { s_logger.info("Successfully added " + requiredNumScsiControllers + " SCSI controllers."); } }
Example #8
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 6 votes |
public void tearDownDevices(Class<?>[] deviceClasses) throws Exception { VirtualDevice[] devices = getMatchedDevices(deviceClasses); if (devices.length > 0) { VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length]; for (int i = 0; i < devices.length; i++) { deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec(); deviceConfigSpecArray[i].setDevice(devices[i]); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.REMOVE); vmConfigSpec.getDeviceChange().add(deviceConfigSpecArray[i]); } if (!configureVm(vmConfigSpec)) { throw new Exception("Failed to detach devices"); } } }
Example #9
Source File: NetworkManager.java From development with Apache License 2.0 | 5 votes |
private static void connectNIC(VirtualMachineConfigSpec vmConfigSpec, VirtualDevice oldNIC, String vmNetworkName) throws Exception { logger.debug("networkName: " + vmNetworkName); VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo(); info.setConnected(true); info.setStartConnected(true); info.setAllowGuestControl(true); oldNIC.setConnectable(info); VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec(); vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT); vmDeviceSpec.setDevice(oldNIC); vmConfigSpec.getDeviceChange().add(vmDeviceSpec); }
Example #10
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public void ensureBusLogicDeviceControllers(int count, int availableBusNum) throws Exception { int scsiControllerKey = getBusLogicDeviceControllerKeyNoException(); if (scsiControllerKey < 0) { VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); int busNum = availableBusNum; while (busNum < count) { VirtualBusLogicController scsiController = new VirtualBusLogicController(); scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING); scsiController.setBusNumber(busNum); scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT); VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec(); scsiControllerSpec.setDevice(scsiController); scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(scsiControllerSpec); busNum++; } if (configureVm(vmConfig)) { throw new Exception("Unable to add Scsi BusLogic controllers to the VM " + getName()); } else { s_logger.info("Successfully added " + count + " SCSI BusLogic controllers."); } } }
Example #11
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public void tearDownDevice(VirtualDevice device) throws Exception { VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); deviceConfigSpec.setDevice(device); deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE); vmConfigSpec.getDeviceChange().add(deviceConfigSpec); if (!configureVm(vmConfigSpec)) { throw new Exception("Failed to detach devices"); } }
Example #12
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public void plugDevice(VirtualDevice device) throws Exception { VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); deviceConfigSpec.setDevice(device); deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfigSpec.getDeviceChange().add(deviceConfigSpec); if (!configureVm(vmConfigSpec)) { throw new Exception("Failed to add devices"); } }
Example #13
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public VirtualMachineMO cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception { assert (disks != null); assert (disks.length >= 1); HostMO hostMo = getRunningHost(); VirtualMachineMO clonedVmMo = HypervisorHostHelper.createWorkerVM(hostMo, new DatastoreMO(hostMo.getContext(), morDs), clonedVmName); if (clonedVmMo == null) throw new Exception("Unable to find just-created blank VM"); boolean bSuccess = false; try { VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, null, -1, disks, morDs, -1, 1); deviceConfigSpec.setDevice(device); deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfigSpec.getDeviceChange().add(deviceConfigSpec); clonedVmMo.configureVm(vmConfigSpec); bSuccess = true; return clonedVmMo; } finally { if (!bSuccess) { clonedVmMo.detachAllDisks(); clonedVmMo.destroy(); } } }
Example #14
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public void detachAllDisks() throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - detachAllDisk(). target MOR: " + _mor.getValue()); VirtualDisk[] disks = getAllDiskDevice(); if (disks.length > 0) { VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[disks.length]; for (int i = 0; i < disks.length; i++) { deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec(); deviceConfigSpecArray[i].setDevice(disks[i]); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.REMOVE); } reConfigSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray)); ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec); boolean result = _context.getVimClient().waitForTask(morTask); if (!result) { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - detachAllDisk() done(failed)"); throw new Exception("Failed to detach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask)); } _context.waitForTaskProgressDone(morTask); } if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - detachAllDisk() done(successfully)"); }
Example #15
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public void attachDisk(Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain, int controllerKey) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " + new Gson().toJson(vmdkDatastorePathChain)); synchronized (_mor.getValue().intern()) { VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey, vmdkDatastorePathChain, -1, 1); VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); deviceConfigSpec.setDevice(newDisk); deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); reConfigSpec.getDeviceChange().add(deviceConfigSpec); ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec); boolean result = _context.getVimClient().waitForTask(morTask); if (!result) { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachDisk() done(failed)"); throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask)); } _context.waitForTaskProgressDone(morTask); } if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachDisk() done(successfully)"); }
Example #16
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public void attachDisk(String[] vmdkDatastorePathChain, ManagedObjectReference morDs) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " + new Gson().toJson(vmdkDatastorePathChain) + ", datastore: " + morDs.getValue()); synchronized (_mor.getValue().intern()) { VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, null, getScsiDeviceControllerKey(), vmdkDatastorePathChain, morDs, -1, 1); VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); deviceConfigSpec.setDevice(newDisk); deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); reConfigSpec.getDeviceChange().add(deviceConfigSpec); ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec); boolean result = _context.getVimClient().waitForTask(morTask); if (!result) { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachDisk() done(failed)"); throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask)); } _context.waitForTaskProgressDone(morTask); } if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachDisk() done(successfully)"); }
Example #17
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public boolean configureVm(Ternary<VirtualDevice, VirtualDeviceConfigSpecOperation, VirtualDeviceConfigSpecFileOperation>[] devices) throws Exception { assert (devices != null); VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length]; int i = 0; for (Ternary<VirtualDevice, VirtualDeviceConfigSpecOperation, VirtualDeviceConfigSpecFileOperation> deviceTernary : devices) { VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); deviceConfigSpec.setDevice(deviceTernary.first()); deviceConfigSpec.setOperation(deviceTernary.second()); deviceConfigSpec.setFileOperation(deviceTernary.third()); deviceConfigSpecArray[i++] = deviceConfigSpec; } configSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray)); ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, configSpec); boolean result = _context.getVimClient().waitForTask(morTask); if (result) { _context.waitForTaskProgressDone(morTask); return true; } else { s_logger.error("VMware reconfigVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask)); } return false; }
Example #18
Source File: DiskManager.java From development with Apache License 2.0 | 5 votes |
private void updateDiskConfiguration(VirtualMachineConfigSpec vmConfigSpec, List<VirtualDevice> devices, int vdKey, long newDiskSpace) throws Exception { VirtualDisk vdDataDisk = findDataDisk(devices, vdKey); if (vdDataDisk != null && newDiskSpace > vdDataDisk.getCapacityInKB()) { logger.info("reconfigureDisks() extend data disk #" + vdKey + " space to " + newDiskSpace + " (" + vdDataDisk.getDeviceInfo().getLabel() + ")"); if (newDiskSpace < vdDataDisk.getCapacityInKB()) { logger.error("Cannot reduce size of data disk " + vdDataDisk.getDeviceInfo().getLabel()); logger.error("Current disk space: " + vdDataDisk.getCapacityInKB() + " new disk space: " + newDiskSpace); throw new Exception(Messages .getAll("error_invalid_diskspacereduction").get(0) .getText()); } else if (newDiskSpace > vdDataDisk.getCapacityInKB()) { vdDataDisk.setCapacityInKB(newDiskSpace); VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec(); vmDeviceSpec .setOperation(VirtualDeviceConfigSpecOperation.EDIT); vmDeviceSpec.setDevice(vdDataDisk); vmConfigSpec.getDeviceChange().add(vmDeviceSpec); } else { logger.debug("Data disk size has not been changed. " + newDiskSpace + " KB"); } } }
Example #19
Source File: DiskManager.java From development with Apache License 2.0 | 5 votes |
private VirtualDeviceConfigSpec createNewDataDisk(VirtualDisk vdSystemDisk, long newDiskSpace, int deviceKey, int unitNumber) throws Exception { logger.info("reconfigureDisks() create data disk space with " + newDiskSpace + " KB"); ManagedObjectReference vmDatastore = ((VirtualDeviceFileBackingInfo) vdSystemDisk .getBacking()).getDatastore(); String vmDatastoreName = (String) vmw.getServiceUtil() .getDynamicProperty(vmDatastore, "summary.name"); VirtualDisk vdDataDisk = new VirtualDisk(); VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo(); diskfileBacking.setFileName("[" + vmDatastoreName + "]"); diskfileBacking.setDiskMode("persistent"); vdDataDisk.setKey(deviceKey); vdDataDisk.setControllerKey(vdSystemDisk.getControllerKey()); vdDataDisk.setUnitNumber(new Integer(unitNumber)); vdDataDisk.setBacking(diskfileBacking); vdDataDisk.setCapacityInKB(newDiskSpace); VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec(); vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmDeviceSpec .setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE); vmDeviceSpec.setDevice(vdDataDisk); return vmDeviceSpec; }
Example #20
Source File: DiskManager.java From development with Apache License 2.0 | 5 votes |
private void configureSystemDisk(VirtualMachineConfigSpec vmConfigSpec, long systemDiskMB, VirtualDisk vdSystemDisk) throws Exception { if (systemDiskMB > 0) { long newDiskSpace = systemDiskMB * 1024; if (newDiskSpace < vdSystemDisk.getCapacityInKB()) { logger.error("Cannot reduce size of system disk \"" + vdSystemDisk.getDeviceInfo().getLabel() + "\""); logger.error("Current disk size: " + vdSystemDisk.getCapacityInKB() + " new disk space: " + newDiskSpace); throw new Exception(Messages .getAll("error_invalid_diskspacereduction").get(0) .getText()); } else if (newDiskSpace > vdSystemDisk.getCapacityInKB()) { logger.info("reconfigureDisks() extend system disk space to " + newDiskSpace + " (" + vdSystemDisk.getDeviceInfo().getLabel() + ")"); vdSystemDisk.setCapacityInKB(newDiskSpace); VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec(); vmDeviceSpec .setOperation(VirtualDeviceConfigSpecOperation.EDIT); vmDeviceSpec.setDevice(vdSystemDisk); vmConfigSpec.getDeviceChange().add(vmDeviceSpec); } else { logger.debug("System disk size has not been changed. " + newDiskSpace + " KB"); } } else { logger.error("Reconfiguration of system disk not possible because system disk size is not defined."); } }
Example #21
Source File: VmUtils.java From cs-actions with Apache License 2.0 | 5 votes |
VirtualDeviceConfigSpec getPopulatedCDSpecs(String fileName, ManagedObjectReference dataStoreRef, List<VirtualDevice> virtualDevicesList, VirtualDeviceConfigSpecOperation operation, Integer controllerKey, Integer unitNumber, Integer key, String parameter, VmInputs vmInputs) { VirtualDeviceConfigSpec cdSpecs = new VirtualDeviceConfigSpec(); if (Operation.ADD.toString().equalsIgnoreCase(parameter)) { VirtualCdromIsoBackingInfo cdIsoBacking = new VirtualCdromIsoBackingInfo(); cdIsoBacking.setDatastore(dataStoreRef); cdIsoBacking.setFileName(fileName + TEST_CD_ISO); VirtualCdrom cdRom = new VirtualCdrom(); cdRom.setBacking(cdIsoBacking); cdRom.setControllerKey(controllerKey); cdRom.setUnitNumber(unitNumber); cdRom.setKey(key); return getCDSpec(cdSpecs, operation, cdRom); } else { VirtualCdrom cdRemove = findVirtualDevice(VirtualCdrom.class, virtualDevicesList, vmInputs); if (cdRemove != null) { return getCDSpec(cdSpecs, operation, cdRemove); } } throw new RuntimeException("No optical device named: [" + vmInputs.getUpdateValue() + "] can be found."); }
Example #22
Source File: VmUtils.java From cs-actions with Apache License 2.0 | 5 votes |
private VirtualDeviceConfigSpec getDiskSpecs(VirtualDeviceConfigSpec diskSpecs, VirtualDeviceConfigSpecOperation operation, VirtualDeviceConfigSpecFileOperation fileOperation, VirtualDisk disk) { diskSpecs.setOperation(operation); diskSpecs.setFileOperation(fileOperation); diskSpecs.setDevice(disk); return diskSpecs; }
Example #23
Source File: VmUtils.java From cs-actions with Apache License 2.0 | 5 votes |
private VirtualDeviceConfigSpec getCDSpec(VirtualDeviceConfigSpec cdSpecs, VirtualDeviceConfigSpecOperation operation, VirtualCdrom cdRom) { cdSpecs.setOperation(operation); cdSpecs.setDevice(cdRom); return cdSpecs; }
Example #24
Source File: VmUtils.java From cs-actions with Apache License 2.0 | 5 votes |
private VirtualDeviceConfigSpec getNicOpSpec(VirtualDeviceConfigSpec nicSpecs, VirtualDeviceConfigSpecOperation operation, VirtualEthernetCard nic) { nicSpecs.setOperation(operation); nicSpecs.setDevice(nic); return nicSpecs; }
Example #25
Source File: HypervisorHostHelper.java From cloudstack with Apache License 2.0 | 5 votes |
private static VirtualDeviceConfigSpec getControllerSpec(String diskController, int busNum) { VirtualDeviceConfigSpec controllerSpec = new VirtualDeviceConfigSpec(); VirtualController controller = null; if (diskController.equalsIgnoreCase(DiskControllerType.ide.toString())) { controller = new VirtualIDEController(); } else if (DiskControllerType.pvscsi == DiskControllerType.getType(diskController)) { controller = new ParaVirtualSCSIController(); } else if (DiskControllerType.lsisas1068 == DiskControllerType.getType(diskController)) { controller = new VirtualLsiLogicSASController(); } else if (DiskControllerType.buslogic == DiskControllerType.getType(diskController)) { controller = new VirtualBusLogicController(); } else if (DiskControllerType.lsilogic == DiskControllerType.getType(diskController)) { controller = new VirtualLsiLogicController(); } if (!diskController.equalsIgnoreCase(DiskControllerType.ide.toString())) { ((VirtualSCSIController)controller).setSharedBus(VirtualSCSISharing.NO_SHARING); } controller.setBusNumber(busNum); controller.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT); controllerSpec.setDevice(controller); controllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); return controllerSpec; }
Example #26
Source File: HypervisorHostHelper.java From cloudstack with Apache License 2.0 | 4 votes |
public static boolean createBlankVm(VmwareHypervisorHost host, String vmName, String vmInternalCSName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB, String guestOsIdentifier, ManagedObjectReference morDs, boolean snapshotDirToParent, Pair<String, String> controllerInfo, Boolean systemVm) throws Exception { if (s_logger.isInfoEnabled()) s_logger.info("Create blank VM. cpuCount: " + cpuCount + ", cpuSpeed(MHz): " + cpuSpeedMHz + ", mem(Mb): " + memoryMB); VirtualDeviceConfigSpec controllerSpec = null; // VM config basics VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec(); vmConfig.setName(vmName); if (vmInternalCSName == null) vmInternalCSName = vmName; VmwareHelper.setBasicVmConfig(vmConfig, cpuCount, cpuSpeedMHz, cpuReservedMHz, memoryMB, memoryReserveMB, guestOsIdentifier, limitCpuUse); String recommendedController = host.getRecommendedDiskController(guestOsIdentifier); String newRootDiskController = controllerInfo.first(); String newDataDiskController = controllerInfo.second(); if (DiskControllerType.getType(controllerInfo.first()) == DiskControllerType.osdefault) { newRootDiskController = recommendedController; } if (DiskControllerType.getType(controllerInfo.second()) == DiskControllerType.osdefault) { newDataDiskController = recommendedController; } Pair<String, String> updatedControllerInfo = new Pair<String, String>(newRootDiskController, newDataDiskController); String scsiDiskController = HypervisorHostHelper.getScsiController(updatedControllerInfo, recommendedController); // If there is requirement for a SCSI controller, ensure to create those. if (scsiDiskController != null) { int busNum = 0; int maxControllerCount = VmwareHelper.MAX_SCSI_CONTROLLER_COUNT; if (systemVm) { maxControllerCount = 1; } while (busNum < maxControllerCount) { VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec(); scsiControllerSpec = getControllerSpec(DiskControllerType.getType(scsiDiskController).toString(), busNum); vmConfig.getDeviceChange().add(scsiControllerSpec); busNum++; } } if (guestOsIdentifier.startsWith("darwin")) { //Mac OS s_logger.debug("Add USB Controller device for blank Mac OS VM " + vmName); //For Mac OS X systems, the EHCI+UHCI controller is enabled by default and is required for USB mouse and keyboard access. VirtualDevice usbControllerDevice = VmwareHelper.prepareUSBControllerDevice(); VirtualDeviceConfigSpec usbControllerSpec = new VirtualDeviceConfigSpec(); usbControllerSpec.setDevice(usbControllerDevice); usbControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(usbControllerSpec); } VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo(); DatastoreMO dsMo = new DatastoreMO(host.getContext(), morDs); fileInfo.setVmPathName(String.format("[%s]", dsMo.getName())); vmConfig.setFiles(fileInfo); VirtualMachineVideoCard videoCard = new VirtualMachineVideoCard(); videoCard.setControllerKey(100); videoCard.setUseAutoDetect(true); VirtualDeviceConfigSpec videoDeviceSpec = new VirtualDeviceConfigSpec(); videoDeviceSpec.setDevice(videoCard); videoDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfig.getDeviceChange().add(videoDeviceSpec); if (host.createVm(vmConfig)) { // Here, when attempting to find the VM, we need to use the name // with which we created it. This is the only such place where // we need to do this. At all other places, we always use the // VM's internal cloudstack generated name. Here, we cannot use // the internal name because we can set the internal name into the // VM's custom field CLOUD_VM_INTERNAL_NAME only after we create // the VM. VirtualMachineMO vmMo = host.findVmOnHyperHost(vmName); assert (vmMo != null); vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME, vmInternalCSName); int ideControllerKey = -1; while (ideControllerKey < 0) { ideControllerKey = vmMo.tryGetIDEDeviceControllerKey(); if (ideControllerKey >= 0) break; s_logger.info("Waiting for IDE controller be ready in VM: " + vmInternalCSName); Thread.sleep(1000); } return true; } return false; }
Example #27
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; }
Example #28
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 4 votes |
public void attachIso(String isoDatastorePath, ManagedObjectReference morDs, boolean connect, boolean connectAtBoot, Integer key) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: " + isoDatastorePath + ", datastore: " + morDs.getValue() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot); assert (isoDatastorePath != null); assert (morDs != null); boolean newCdRom = false; VirtualCdrom cdRom; if (key == null) { cdRom = (VirtualCdrom) getIsoDevice(); } else { cdRom = (VirtualCdrom) getIsoDevice(key); } if (cdRom == null) { newCdRom = true; cdRom = new VirtualCdrom(); cdRom.setControllerKey(getIDEDeviceControllerKey()); int deviceNumber = getNextIDEDeviceNumber(); cdRom.setUnitNumber(deviceNumber); cdRom.setKey(-deviceNumber); } VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo(); cInfo.setConnected(connect); cInfo.setStartConnected(connectAtBoot); cdRom.setConnectable(cInfo); VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo(); backingInfo.setFileName(isoDatastorePath); backingInfo.setDatastore(morDs); cdRom.setBacking(backingInfo); VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec(); //VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1]; VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); deviceConfigSpec.setDevice(cdRom); if (newCdRom) { deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); } else { deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT); } //deviceConfigSpecArray[0] = deviceConfigSpec; reConfigSpec.getDeviceChange().add(deviceConfigSpec); ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec); boolean result = _context.getVimClient().waitForTask(morTask); if (!result) { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachIso() done(failed)"); throw new Exception("Failed to attach ISO due to " + TaskMO.getTaskFailureInfo(_context, morTask)); } _context.waitForTaskProgressDone(morTask); if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - attachIso() done(successfully)"); }
Example #29
Source File: HypervisorHostHelper.java From cloudstack with Apache License 2.0 | 4 votes |
public static void createOvfFile(VmwareHypervisorHost host, String diskFileName, String ovfName, String datastorePath, String templatePath, long diskCapacity, long fileSize, ManagedObjectReference morDs) throws Exception { VmwareContext context = host.getContext(); ManagedObjectReference morOvf = context.getServiceContent().getOvfManager(); VirtualMachineMO workerVmMo = HypervisorHostHelper.createWorkerVM(host, new DatastoreMO(context, morDs), ovfName); if (workerVmMo == null) throw new Exception("Unable to find just-created worker VM"); String[] disks = {datastorePath + File.separator + diskFileName}; try { VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); // Reconfigure worker VM with datadisk VirtualDevice device = VmwareHelper.prepareDiskDevice(workerVmMo, null, -1, disks, morDs, -1, 1); deviceConfigSpec.setDevice(device); deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmConfigSpec.getDeviceChange().add(deviceConfigSpec); workerVmMo.configureVm(vmConfigSpec); // Write OVF descriptor file OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams(); String deviceId = File.separator + workerVmMo.getMor().getValue() + File.separator + "VirtualIDEController0:0"; OvfFile ovfFile = new OvfFile(); ovfFile.setPath(diskFileName); ovfFile.setDeviceId(deviceId); ovfFile.setSize(fileSize); ovfFile.setCapacity(diskCapacity); ovfDescParams.getOvfFiles().add(ovfFile); OvfCreateDescriptorResult ovfCreateDescriptorResult = context.getService().createDescriptor(morOvf, workerVmMo.getMor(), ovfDescParams); String ovfPath = templatePath + File.separator + ovfName + ".ovf"; try { FileWriter out = new FileWriter(ovfPath); out.write(ovfCreateDescriptorResult.getOvfDescriptor()); out.close(); } catch (Exception e) { throw e; } } finally { workerVmMo.detachAllDisks(); workerVmMo.destroy(); } }
Example #30
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 4 votes |
public List<String> detachAllDisksExcept(String vmdkBaseName, String deviceBusName) throws Exception { List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device"); VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec(); List<String> detachedDiskFiles = new ArrayList<String>(); for (VirtualDevice device : devices) { if (device instanceof VirtualDisk) { VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)device.getBacking(); DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName()); String backingBaseName = dsBackingFile.getFileBaseName(); String deviceNumbering = getDeviceBusName(devices, device); if (backingBaseName.equalsIgnoreCase(vmdkBaseName) || (deviceBusName != null && deviceBusName.equals(deviceNumbering))) { continue; } else { s_logger.info("Detach " + diskBackingInfo.getFileName() + " from " + getName()); detachedDiskFiles.add(diskBackingInfo.getFileName()); deviceConfigSpec.setDevice(device); deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE); reConfigSpec.getDeviceChange().add(deviceConfigSpec); } } } if (detachedDiskFiles.size() > 0) { ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec); boolean result = _context.getVimClient().waitForTask(morTask); if (result) { _context.waitForTaskProgressDone(morTask); } else { s_logger.warn("Unable to reconfigure the VM to detach disks"); throw new Exception("Unable to reconfigure the VM to detach disks"); } } return detachedDiskFiles; }