mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Do not set user-configurable details for deploy-as-is VMs
This commit is contained in:
parent
9c162c6de9
commit
61e7625d49
@ -1749,38 +1749,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
VirtualMachineFileLayoutEx existingVmFileLayout = null;
|
VirtualMachineFileLayoutEx existingVmFileLayout = null;
|
||||||
List<DatastoreMO> existingDatastores = new ArrayList<DatastoreMO>();
|
List<DatastoreMO> existingDatastores = new ArrayList<DatastoreMO>();
|
||||||
|
|
||||||
|
DeployAsIsInfoTO deployAsIsInfo = vmSpec.getDeployAsIsInfo();
|
||||||
|
boolean deployAsIs = deployAsIsInfo != null;
|
||||||
|
|
||||||
Pair<String, String> names = composeVmNames(vmSpec);
|
Pair<String, String> names = composeVmNames(vmSpec);
|
||||||
String vmInternalCSName = names.first();
|
String vmInternalCSName = names.first();
|
||||||
String vmNameOnVcenter = names.second();
|
String vmNameOnVcenter = names.second();
|
||||||
String dataDiskController = vmSpec.getDetails().get(VmDetailConstants.DATA_DISK_CONTROLLER);
|
|
||||||
String rootDiskController = vmSpec.getDetails().get(VmDetailConstants.ROOT_DISK_CONTROLLER);
|
|
||||||
DiskTO rootDiskTO = null;
|
DiskTO rootDiskTO = null;
|
||||||
String bootMode = null;
|
String bootMode = getBootModeFromVmSpec(vmSpec, deployAsIs);
|
||||||
if (vmSpec.getDetails().containsKey(VmDetailConstants.BOOT_MODE)) {
|
Pair<String, String> controllerInfo = getControllerInfoFromVmSpec(vmSpec, deployAsIs);
|
||||||
bootMode = vmSpec.getDetails().get(VmDetailConstants.BOOT_MODE);
|
|
||||||
}
|
|
||||||
if (null == bootMode) {
|
|
||||||
bootMode = ApiConstants.BootType.BIOS.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If root disk controller is scsi, then data disk controller would also be scsi instead of using 'osdefault'
|
|
||||||
// This helps avoid mix of different scsi subtype controllers in instance.
|
|
||||||
if (DiskControllerType.osdefault == DiskControllerType.getType(dataDiskController) && DiskControllerType.lsilogic == DiskControllerType.getType(rootDiskController)) {
|
|
||||||
dataDiskController = DiskControllerType.scsi.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the controller types
|
|
||||||
dataDiskController = DiskControllerType.getType(dataDiskController).toString();
|
|
||||||
rootDiskController = DiskControllerType.getType(rootDiskController).toString();
|
|
||||||
|
|
||||||
if (DiskControllerType.getType(rootDiskController) == DiskControllerType.none) {
|
|
||||||
throw new CloudRuntimeException("Invalid root disk controller detected : " + rootDiskController);
|
|
||||||
}
|
|
||||||
if (DiskControllerType.getType(dataDiskController) == DiskControllerType.none) {
|
|
||||||
throw new CloudRuntimeException("Invalid data disk controller detected : " + dataDiskController);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pair<String, String> controllerInfo = new Pair<String, String>(rootDiskController, dataDiskController);
|
|
||||||
|
|
||||||
Boolean systemVm = vmSpec.getType().isUsedBySystem();
|
Boolean systemVm = vmSpec.getType().isUsedBySystem();
|
||||||
// Thus, vmInternalCSName always holds i-x-y, the cloudstack generated internal VM name.
|
// Thus, vmInternalCSName always holds i-x-y, the cloudstack generated internal VM name.
|
||||||
@ -1802,19 +1779,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
}
|
}
|
||||||
|
|
||||||
DiskTO[] specDisks = vmSpec.getDisks();
|
DiskTO[] specDisks = vmSpec.getDisks();
|
||||||
DeployAsIsInfoTO deployAsIsInfo = vmSpec.getDeployAsIsInfo();
|
String guestOsId = getGuestOsIdFromVmSpec(vmSpec, deployAsIs);
|
||||||
boolean installAsIs = deployAsIsInfo != null;
|
|
||||||
if (installAsIs && dcMo.findVm(vmInternalCSName) == null) {
|
|
||||||
if (s_logger.isTraceEnabled()) {
|
|
||||||
s_logger.trace("Deploying OVA from as is");
|
|
||||||
}
|
|
||||||
String deployAsIsTemplate = deployAsIsInfo.getTemplatePath();
|
|
||||||
String destDatastore = deployAsIsInfo.getDestStoragePool();
|
|
||||||
vmInVcenter = _storageProcessor.cloneVMFromTemplate(deployAsIsTemplate, vmInternalCSName, destDatastore);
|
|
||||||
mapSpecDisksToClonedDisks(vmInVcenter, vmInternalCSName, specDisks);
|
|
||||||
}
|
|
||||||
|
|
||||||
String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs(), vmSpec.getPlatformEmulator()).value();
|
|
||||||
DiskTO[] disks = validateDisks(vmSpec.getDisks());
|
DiskTO[] disks = validateDisks(vmSpec.getDisks());
|
||||||
assert (disks.length > 0);
|
assert (disks.length > 0);
|
||||||
NicTO[] nics = vmSpec.getNics();
|
NicTO[] nics = vmSpec.getNics();
|
||||||
@ -1840,6 +1805,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
int firstScsiControllerBusNum = 0;
|
int firstScsiControllerBusNum = 0;
|
||||||
int numScsiControllerForSystemVm = 1;
|
int numScsiControllerForSystemVm = 1;
|
||||||
boolean hasSnapshot = false;
|
boolean hasSnapshot = false;
|
||||||
|
|
||||||
if (vmMo != null) {
|
if (vmMo != null) {
|
||||||
s_logger.info("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration");
|
s_logger.info("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration");
|
||||||
if (getVmPowerState(vmMo) != PowerState.PowerOff)
|
if (getVmPowerState(vmMo) != PowerState.PowerOff)
|
||||||
@ -1849,15 +1815,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
diskInfoBuilder = vmMo.getDiskInfoBuilder();
|
diskInfoBuilder = vmMo.getDiskInfoBuilder();
|
||||||
hasSnapshot = vmMo.hasSnapshot();
|
hasSnapshot = vmMo.hasSnapshot();
|
||||||
nicDevices = vmMo.getNicDevices();
|
nicDevices = vmMo.getNicDevices();
|
||||||
if (!hasSnapshot)
|
|
||||||
vmMo.tearDownDevices(new Class<?>[]{VirtualDisk.class, VirtualEthernetCard.class});
|
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
|
||||||
else
|
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
|
||||||
vmMo.tearDownDevices(new Class<?>[]{VirtualEthernetCard.class});
|
numScsiControllerForSystemVm, firstScsiControllerBusNum, deployAsIs);
|
||||||
if (systemVm) {
|
|
||||||
ensureScsiDiskControllers(vmMo, systemVmScsiControllerType.toString(), numScsiControllerForSystemVm, firstScsiControllerBusNum);
|
|
||||||
} else {
|
|
||||||
ensureDiskControllers(vmMo, controllerInfo);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
|
ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
|
||||||
assert (morDc != null);
|
assert (morDc != null);
|
||||||
@ -1875,17 +1836,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
|
|
||||||
diskInfoBuilder = vmMo.getDiskInfoBuilder();
|
diskInfoBuilder = vmMo.getDiskInfoBuilder();
|
||||||
hasSnapshot = vmMo.hasSnapshot();
|
hasSnapshot = vmMo.hasSnapshot();
|
||||||
if (!hasSnapshot)
|
|
||||||
vmMo.tearDownDevices(new Class<?>[]{VirtualDisk.class, VirtualEthernetCard.class});
|
|
||||||
else
|
|
||||||
vmMo.tearDownDevices(new Class<?>[]{VirtualEthernetCard.class});
|
|
||||||
|
|
||||||
if (systemVm) {
|
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
|
||||||
// System volumes doesn't require more than 1 SCSI controller as there is no requirement for data volumes.
|
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
|
||||||
ensureScsiDiskControllers(vmMo, systemVmScsiControllerType.toString(), numScsiControllerForSystemVm, firstScsiControllerBusNum);
|
numScsiControllerForSystemVm, firstScsiControllerBusNum, deployAsIs);
|
||||||
} else {
|
|
||||||
ensureDiskControllers(vmMo, controllerInfo);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// If a VM with the same name is found in a different cluster in the DC, unregister the old VM and configure a new VM (cold-migration).
|
// If a VM with the same name is found in a different cluster in the DC, unregister the old VM and configure a new VM (cold-migration).
|
||||||
VirtualMachineMO existingVmInDc = dcMo.findVm(vmInternalCSName);
|
VirtualMachineMO existingVmInDc = dcMo.findVm(vmInternalCSName);
|
||||||
@ -1897,6 +1851,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
existingDatastores = existingVmInDc.getAllDatastores();
|
existingDatastores = existingVmInDc.getAllDatastores();
|
||||||
existingVmInDc.unregisterVm();
|
existingVmInDc.unregisterVm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deployAsIs) {
|
||||||
|
if (s_logger.isTraceEnabled()) {
|
||||||
|
s_logger.trace("Deploying OVA from template as-is");
|
||||||
|
}
|
||||||
|
String deployAsIsTemplate = deployAsIsInfo.getTemplatePath();
|
||||||
|
String destDatastore = deployAsIsInfo.getDestStoragePool();
|
||||||
|
vmMo = _storageProcessor.cloneVMFromTemplate(deployAsIsTemplate, vmInternalCSName, destDatastore);
|
||||||
|
mapSpecDisksToClonedDisks(vmMo, vmInternalCSName, specDisks);
|
||||||
|
} else {
|
||||||
Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null;
|
Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null;
|
||||||
for (DiskTO vol : disks) {
|
for (DiskTO vol : disks) {
|
||||||
if (vol.getType() == Volume.Type.ROOT) {
|
if (vol.getType() == Volume.Type.ROOT) {
|
||||||
@ -1938,6 +1902,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
throw new Exception("Failed to create VM. vmName: " + vmInternalCSName);
|
throw new Exception("Failed to create VM. vmName: " + vmInternalCSName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
|
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
@ -1945,9 +1910,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The number of disks changed must be 0 for install as is, as the VM is a clone
|
// The number of disks changed must be 0 for install as is, as the VM is a clone from the template as-is
|
||||||
//int disksChanges = !installAsIs ? disks.length : 0;
|
int disksChanges = !deployAsIs ? disks.length : 0;
|
||||||
int totalChangeDevices = disks.length + nics.length;
|
int totalChangeDevices = disksChanges + nics.length;
|
||||||
int hackDeviceCount = 0;
|
int hackDeviceCount = 0;
|
||||||
if (diskInfoBuilder != null) {
|
if (diskInfoBuilder != null) {
|
||||||
hackDeviceCount += diskInfoBuilder.getDiskCount();
|
hackDeviceCount += diskInfoBuilder.getDiskCount();
|
||||||
@ -1964,7 +1929,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
if (vmSpec.getType() != VirtualMachine.Type.User) {
|
if (vmSpec.getType() != VirtualMachine.Type.User) {
|
||||||
// system VM needs a patch ISO
|
// system VM needs a patch ISO
|
||||||
totalChangeDevices++;
|
totalChangeDevices++;
|
||||||
} else {
|
} else if (!deployAsIs) {
|
||||||
volIso = getIsoDiskTO(disks);
|
volIso = getIsoDiskTO(disks);
|
||||||
if (volIso == null)
|
if (volIso == null)
|
||||||
totalChangeDevices++;
|
totalChangeDevices++;
|
||||||
@ -1972,9 +1937,18 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
|
|
||||||
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
|
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
|
||||||
|
|
||||||
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), getReservedCpuMHZ(vmSpec), (int) (vmSpec.getMaxRam() / (1024 * 1024)),
|
int i = 0;
|
||||||
getReservedMemoryMb(vmSpec), guestOsId, vmSpec.getLimitCpuUse());
|
int ideUnitNumber = 0;
|
||||||
|
int scsiUnitNumber = 0;
|
||||||
|
int ideControllerKey = vmMo.getIDEDeviceControllerKey();
|
||||||
|
int scsiControllerKey = vmMo.getScsiDeviceControllerKeyNoException();
|
||||||
|
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
|
||||||
|
DiskTO[] sortedDisks = sortVolumesByDeviceId(disks);
|
||||||
|
|
||||||
|
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), getReservedCpuMHZ(vmSpec), (int) (vmSpec.getMaxRam() / (1024 * 1024)),
|
||||||
|
getReservedMemoryMb(vmSpec), guestOsId, vmSpec.getLimitCpuUse(), deployAsIs);
|
||||||
|
|
||||||
|
if (!deployAsIs) {
|
||||||
// Check for multi-cores per socket settings
|
// Check for multi-cores per socket settings
|
||||||
int numCoresPerSocket = 1;
|
int numCoresPerSocket = 1;
|
||||||
String coresPerSocket = vmSpec.getDetails().get(VmDetailConstants.CPU_CORE_PER_SOCKET);
|
String coresPerSocket = vmSpec.getDetails().get(VmDetailConstants.CPU_CORE_PER_SOCKET);
|
||||||
@ -2001,12 +1975,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
|
|
||||||
configNestedHVSupport(vmMo, vmSpec, vmConfigSpec);
|
configNestedHVSupport(vmMo, vmSpec, vmConfigSpec);
|
||||||
|
|
||||||
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
|
|
||||||
int i = 0;
|
|
||||||
int ideUnitNumber = 0;
|
|
||||||
int scsiUnitNumber = 0;
|
|
||||||
int ideControllerKey = vmMo.getIDEDeviceControllerKey();
|
|
||||||
int scsiControllerKey = vmMo.getScsiDeviceControllerKeyNoException();
|
|
||||||
int controllerKey;
|
int controllerKey;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -2106,14 +2074,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
//
|
//
|
||||||
// Setup ROOT/DATA disk devices
|
// Setup ROOT/DATA disk devices
|
||||||
//
|
//
|
||||||
DiskTO[] sortedDisks = sortVolumesByDeviceId(disks);
|
|
||||||
for (DiskTO vol : sortedDisks) {
|
for (DiskTO vol : sortedDisks) {
|
||||||
if (vol.getType() == Volume.Type.ISO)
|
if (vol.getType() == Volume.Type.ISO)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
|
VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
|
||||||
controllerKey = getDiskController(matchingExistingDisk, vol, vmSpec, ideControllerKey, scsiControllerKey);
|
controllerKey = getDiskController(matchingExistingDisk, vol, vmSpec, ideControllerKey, scsiControllerKey);
|
||||||
String diskController = getDiskController(vmMo, matchingExistingDisk, vol, new Pair<String, String>(rootDiskController, dataDiskController));
|
String diskController = getDiskController(vmMo, matchingExistingDisk, vol, controllerInfo);
|
||||||
|
|
||||||
if (DiskControllerType.getType(diskController) == DiskControllerType.osdefault) {
|
if (DiskControllerType.getType(diskController) == DiskControllerType.osdefault) {
|
||||||
diskController = vmMo.getRecommendedDiskController(null);
|
diskController = vmMo.getRecommendedDiskController(null);
|
||||||
@ -2214,6 +2181,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
s_logger.debug("USB Controller device exists on VM Start for Mac OS VM " + vmInternalCSName);
|
s_logger.debug("USB Controller device exists on VM Start for Mac OS VM " + vmInternalCSName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setup NIC devices
|
// Setup NIC devices
|
||||||
@ -2318,6 +2286,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
// pass boot arguments through machine.id & perform customized options to VMX
|
// pass boot arguments through machine.id & perform customized options to VMX
|
||||||
ArrayList<OptionValue> extraOptions = new ArrayList<OptionValue>();
|
ArrayList<OptionValue> extraOptions = new ArrayList<OptionValue>();
|
||||||
configBasicExtraOption(extraOptions, vmSpec);
|
configBasicExtraOption(extraOptions, vmSpec);
|
||||||
|
|
||||||
|
if (deployAsIs) {
|
||||||
|
setDeployAsIsProperties(vmMo, deployAsIsInfo, vmConfigSpec);
|
||||||
|
configureVNC(vmSpec, extraOptions, vmConfigSpec, hyperHost, vmInternalCSName);
|
||||||
|
} else {
|
||||||
configNvpExtraOption(extraOptions, vmSpec, nicUuidToDvSwitchUuid);
|
configNvpExtraOption(extraOptions, vmSpec, nicUuidToDvSwitchUuid);
|
||||||
configCustomExtraOption(extraOptions, vmSpec);
|
configCustomExtraOption(extraOptions, vmSpec);
|
||||||
|
|
||||||
@ -2331,19 +2304,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
extraOptions.add(option);
|
extraOptions.add(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
// config VNC
|
configureVNC(vmSpec, extraOptions, vmConfigSpec, hyperHost, vmInternalCSName);
|
||||||
String keyboardLayout = null;
|
|
||||||
if (vmSpec.getDetails() != null)
|
|
||||||
keyboardLayout = vmSpec.getDetails().get(VmDetailConstants.KEYBOARD);
|
|
||||||
vmConfigSpec.getExtraConfig()
|
|
||||||
.addAll(Arrays.asList(configureVnc(extraOptions.toArray(new OptionValue[0]), hyperHost, vmInternalCSName, vmSpec.getVncPassword(), keyboardLayout)));
|
|
||||||
|
|
||||||
// config video card
|
// config video card
|
||||||
configureVideoCard(vmMo, vmSpec, vmConfigSpec);
|
configureVideoCard(vmMo, vmSpec, vmConfigSpec);
|
||||||
|
|
||||||
setDeployAsIsProperties(vmMo, deployAsIsInfo, vmConfigSpec);
|
|
||||||
|
|
||||||
setBootOptions(vmSpec, bootMode, vmConfigSpec);
|
setBootOptions(vmSpec, bootMode, vmConfigSpec);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Configure VM
|
// Configure VM
|
||||||
@ -2358,7 +2325,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
|
|
||||||
// Resizing root disk only when explicit requested by user
|
// Resizing root disk only when explicit requested by user
|
||||||
final Map<String, String> vmDetails = cmd.getVirtualMachine().getDetails();
|
final Map<String, String> vmDetails = cmd.getVirtualMachine().getDetails();
|
||||||
if (rootDiskTO != null && !hasSnapshot && (vmDetails != null && vmDetails.containsKey(ApiConstants.ROOT_DISK_SIZE))) {
|
if (!deployAsIs && rootDiskTO != null && !hasSnapshot && (vmDetails != null && vmDetails.containsKey(ApiConstants.ROOT_DISK_SIZE))) {
|
||||||
resizeRootDiskOnVMStart(vmMo, rootDiskTO, hyperHost, context);
|
resizeRootDiskOnVMStart(vmMo, rootDiskTO, hyperHost, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2432,6 +2399,85 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure VNC
|
||||||
|
*/
|
||||||
|
private void configureVNC(VirtualMachineTO vmSpec, ArrayList<OptionValue> extraOptions, VirtualMachineConfigSpec vmConfigSpec, VmwareHypervisorHost hyperHost, String vmInternalCSName) throws Exception {
|
||||||
|
String keyboardLayout = null;
|
||||||
|
if (vmSpec.getDetails() != null)
|
||||||
|
keyboardLayout = vmSpec.getDetails().get(VmDetailConstants.KEYBOARD);
|
||||||
|
vmConfigSpec.getExtraConfig()
|
||||||
|
.addAll(Arrays.asList(configureVnc(extraOptions.toArray(new OptionValue[0]), hyperHost, vmInternalCSName, vmSpec.getVncPassword(), keyboardLayout)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureDiskControllersInternal(VirtualMachineMO vmMo, Boolean systemVm,
|
||||||
|
Pair<String, String> controllerInfo,
|
||||||
|
DiskControllerType systemVmScsiControllerType,
|
||||||
|
int numScsiControllerForSystemVm,
|
||||||
|
int firstScsiControllerBusNum, boolean deployAsIs) throws Exception {
|
||||||
|
if (systemVm) {
|
||||||
|
ensureScsiDiskControllers(vmMo, systemVmScsiControllerType.toString(), numScsiControllerForSystemVm, firstScsiControllerBusNum);
|
||||||
|
} else if (!deployAsIs) {
|
||||||
|
ensureDiskControllers(vmMo, controllerInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tearDownVmDevices(VirtualMachineMO vmMo, boolean hasSnapshot, boolean deployAsIs) throws Exception {
|
||||||
|
if (deployAsIs) {
|
||||||
|
vmMo.tearDownDevices(new Class<?>[]{VirtualEthernetCard.class});
|
||||||
|
} else if (!hasSnapshot) {
|
||||||
|
vmMo.tearDownDevices(new Class<?>[]{VirtualDisk.class, VirtualEthernetCard.class});
|
||||||
|
} else {
|
||||||
|
vmMo.tearDownDevices(new Class<?>[]{VirtualEthernetCard.class});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getGuestOsIdFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs) {
|
||||||
|
String guestOsId = null;
|
||||||
|
if (!deployAsIs) {
|
||||||
|
guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs(), vmSpec.getPlatformEmulator()).value();
|
||||||
|
}
|
||||||
|
return guestOsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pair<String, String> getControllerInfoFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs) throws CloudRuntimeException {
|
||||||
|
String dataDiskController = vmSpec.getDetails().get(VmDetailConstants.DATA_DISK_CONTROLLER);
|
||||||
|
String rootDiskController = vmSpec.getDetails().get(VmDetailConstants.ROOT_DISK_CONTROLLER);
|
||||||
|
|
||||||
|
// If root disk controller is scsi, then data disk controller would also be scsi instead of using 'osdefault'
|
||||||
|
// This helps avoid mix of different scsi subtype controllers in instance.
|
||||||
|
if (DiskControllerType.osdefault == DiskControllerType.getType(dataDiskController) && DiskControllerType.lsilogic == DiskControllerType.getType(rootDiskController)) {
|
||||||
|
dataDiskController = DiskControllerType.scsi.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the controller types
|
||||||
|
dataDiskController = DiskControllerType.getType(dataDiskController).toString();
|
||||||
|
rootDiskController = DiskControllerType.getType(rootDiskController).toString();
|
||||||
|
|
||||||
|
if (DiskControllerType.getType(rootDiskController) == DiskControllerType.none) {
|
||||||
|
throw new CloudRuntimeException("Invalid root disk controller detected : " + rootDiskController);
|
||||||
|
}
|
||||||
|
if (DiskControllerType.getType(dataDiskController) == DiskControllerType.none) {
|
||||||
|
throw new CloudRuntimeException("Invalid data disk controller detected : " + dataDiskController);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Pair<String, String>(rootDiskController, dataDiskController);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBootModeFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs) {
|
||||||
|
String bootMode = null;
|
||||||
|
if (!deployAsIs) {
|
||||||
|
if (vmSpec.getDetails().containsKey(VmDetailConstants.BOOT_MODE)) {
|
||||||
|
bootMode = vmSpec.getDetails().get(VmDetailConstants.BOOT_MODE);
|
||||||
|
}
|
||||||
|
if (null == bootMode) {
|
||||||
|
bootMode = ApiConstants.BootType.BIOS.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bootMode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set OVF properties (if available)
|
* Set OVF properties (if available)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1479,7 +1479,7 @@ public class HypervisorHostHelper {
|
|||||||
if (vmInternalCSName == null)
|
if (vmInternalCSName == null)
|
||||||
vmInternalCSName = vmName;
|
vmInternalCSName = vmName;
|
||||||
|
|
||||||
VmwareHelper.setBasicVmConfig(vmConfig, cpuCount, cpuSpeedMHz, cpuReservedMHz, memoryMB, memoryReserveMB, guestOsIdentifier, limitCpuUse);
|
VmwareHelper.setBasicVmConfig(vmConfig, cpuCount, cpuSpeedMHz, cpuReservedMHz, memoryMB, memoryReserveMB, guestOsIdentifier, limitCpuUse, false);
|
||||||
|
|
||||||
String recommendedController = host.getRecommendedDiskController(guestOsIdentifier);
|
String recommendedController = host.getRecommendedDiskController(guestOsIdentifier);
|
||||||
String newRootDiskController = controllerInfo.first();
|
String newRootDiskController = controllerInfo.first();
|
||||||
|
|||||||
@ -534,7 +534,7 @@ public class VmwareHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB,
|
public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz, int memoryMB, int memoryReserveMB,
|
||||||
String guestOsIdentifier, boolean limitCpuUse) {
|
String guestOsIdentifier, boolean limitCpuUse, boolean deployAsIs) {
|
||||||
|
|
||||||
// VM config basics
|
// VM config basics
|
||||||
vmConfig.setMemoryMB((long)memoryMB);
|
vmConfig.setMemoryMB((long)memoryMB);
|
||||||
@ -560,9 +560,13 @@ public class VmwareHelper {
|
|||||||
memInfo.setReservation((long)memoryReserveMB);
|
memInfo.setReservation((long)memoryReserveMB);
|
||||||
vmConfig.setMemoryAllocation(memInfo);
|
vmConfig.setMemoryAllocation(memInfo);
|
||||||
|
|
||||||
|
if (!deployAsIs) {
|
||||||
|
// Deploy as-is uses the cloned VM guest OS
|
||||||
vmConfig.setGuestId(guestOsIdentifier);
|
vmConfig.setGuestId(guestOsIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static VirtualDevice prepareUSBControllerDevice() {
|
public static VirtualDevice prepareUSBControllerDevice() {
|
||||||
s_logger.debug("Preparing USB controller(EHCI+UHCI) device");
|
s_logger.debug("Preparing USB controller(EHCI+UHCI) device");
|
||||||
VirtualUSBController usbController = new VirtualUSBController(); //EHCI+UHCI
|
VirtualUSBController usbController = new VirtualUSBController(); //EHCI+UHCI
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user