mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
VMware: match hardware version for worker VM when taking a snapshot (#4321)
* Add hardware version to worker VM * Added worker VM hardware version when creating a template from a volume and migrating a detached volume * Add null parameter back that was removed by merge
This commit is contained in:
parent
cde7fbff05
commit
479ef8aafa
@ -344,7 +344,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||||||
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
||||||
|
|
||||||
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
||||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
|
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);
|
||||||
|
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
||||||
@ -647,7 +647,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 4 MB is the minimum requirement for VM memory in VMware
|
// 4 MB is the minimum requirement for VM memory in VMware
|
||||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
|
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
|
||||||
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
|
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
|
||||||
if (clonedVm == null) {
|
if (clonedVm == null) {
|
||||||
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
|
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
|
||||||
@ -965,7 +965,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||||||
|
|
||||||
if (clonedWorkerVMNeeded) {
|
if (clonedWorkerVMNeeded) {
|
||||||
// 4 MB is the minimum requirement for VM memory in VMware
|
// 4 MB is the minimum requirement for VM memory in VMware
|
||||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
|
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
|
||||||
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
|
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
|
||||||
if (clonedVm == null) {
|
if (clonedVm == null) {
|
||||||
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
|
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
|
||||||
@ -1008,7 +1008,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
// create a dummy worker vm for attaching the volume
|
// create a dummy worker vm for attaching the volume
|
||||||
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
||||||
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName);
|
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);
|
||||||
|
|
||||||
if (workerVm == null) {
|
if (workerVm == null) {
|
||||||
String msg = "Unable to create worker VM to execute CopyVolumeCommand";
|
String msg = "Unable to create worker VM to execute CopyVolumeCommand";
|
||||||
|
|||||||
@ -763,7 +763,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
s_logger.info("Create worker VM " + vmName);
|
s_logger.info("Create worker VM " + vmName);
|
||||||
|
|
||||||
// OfflineVmwareMigration: 2. create the worker with access to the data(store)
|
// OfflineVmwareMigration: 2. create the worker with access to the data(store)
|
||||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName);
|
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName, null);
|
||||||
|
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
// OfflineVmwareMigration: don't throw a general Exception but think of a specific one
|
// OfflineVmwareMigration: don't throw a general Exception but think of a specific one
|
||||||
@ -4595,7 +4595,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
dsMo = new DatastoreMO(hyperHost.getContext(), morSourceDS);
|
dsMo = new DatastoreMO(hyperHost.getContext(), morSourceDS);
|
||||||
s_logger.info("Create worker VM " + vmName);
|
s_logger.info("Create worker VM " + vmName);
|
||||||
// OfflineVmwareMigration: 2. create the worker with access to the data(store)
|
// OfflineVmwareMigration: 2. create the worker with access to the data(store)
|
||||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName);
|
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName, null);
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
// OfflineVmwareMigration: don't throw a general Exception but think of a specific one
|
// OfflineVmwareMigration: don't throw a general Exception but think of a specific one
|
||||||
throw new CloudRuntimeException("Unable to create a worker VM for volume operation");
|
throw new CloudRuntimeException("Unable to create a worker VM for volume operation");
|
||||||
|
|||||||
@ -396,7 +396,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
if (vmName != null) {
|
if (vmName != null) {
|
||||||
String workerVmName = hostService.getWorkerName(context, cmd, 0);
|
String workerVmName = hostService.getWorkerName(context, cmd, 0);
|
||||||
|
|
||||||
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName);
|
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);
|
||||||
|
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
throw new Exception("Unable to create a worker VM for volume creation");
|
throw new Exception("Unable to create a worker VM for volume creation");
|
||||||
@ -794,7 +794,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
|
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
|
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
throw new Exception("Unable to create a dummy VM for volume creation");
|
throw new Exception("Unable to create a dummy VM for volume creation");
|
||||||
}
|
}
|
||||||
@ -995,7 +995,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
if (vmMo == null || VmwareResource.getVmState(vmMo) == PowerState.PowerOff) {
|
if (vmMo == null || VmwareResource.getVmState(vmMo) == PowerState.PowerOff) {
|
||||||
// create a dummy worker vm for attaching the volume
|
// create a dummy worker vm for attaching the volume
|
||||||
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
||||||
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName);
|
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);
|
||||||
|
|
||||||
if (workerVm == null) {
|
if (workerVm == null) {
|
||||||
String msg = "Unable to create worker VM to execute CopyVolumeCommand";
|
String msg = "Unable to create worker VM to execute CopyVolumeCommand";
|
||||||
@ -1130,9 +1130,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
throw new Exception(msg);
|
throw new Exception(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String hardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());
|
||||||
|
|
||||||
// 4 MB is the minimum requirement for VM memory in VMware
|
// 4 MB is the minimum requirement for VM memory in VMware
|
||||||
Pair<VirtualMachineMO, String[]> cloneResult =
|
Pair<VirtualMachineMO, String[]> cloneResult =
|
||||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
|
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), hardwareVersion);
|
||||||
clonedVm = cloneResult.first();
|
clonedVm = cloneResult.first();
|
||||||
|
|
||||||
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
|
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
|
||||||
@ -1194,7 +1196,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
if (volume.getVmName() == null) {
|
if (volume.getVmName() == null) {
|
||||||
ManagedObjectReference secMorDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, volume.getDataStore().getUuid());
|
ManagedObjectReference secMorDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, volume.getDataStore().getUuid());
|
||||||
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), secMorDs);
|
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), secMorDs);
|
||||||
workerVmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, "workervm"+volume.getUuid());
|
workerVmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, "workervm"+volume.getUuid(), null);
|
||||||
if (workerVmMo == null) {
|
if (workerVmMo == null) {
|
||||||
throw new Exception("Unable to find created worker VM");
|
throw new Exception("Unable to find created worker VM");
|
||||||
}
|
}
|
||||||
@ -1551,7 +1553,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
ManagedObjectReference dsMor = hyperHost.findDatastoreByName(dsFile.getDatastoreName());
|
ManagedObjectReference dsMor = hyperHost.findDatastoreByName(dsFile.getDatastoreName());
|
||||||
DatastoreMO dsMo = new DatastoreMO(context, dsMor);
|
DatastoreMO dsMo = new DatastoreMO(context, dsMor);
|
||||||
|
|
||||||
VirtualMachineMO workerVM = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
|
VirtualMachineMO workerVM = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);
|
||||||
|
|
||||||
if (workerVM == null) {
|
if (workerVM == null) {
|
||||||
throw new CloudRuntimeException("Failed to find the newly created worker VM: " + workerVMName);
|
throw new CloudRuntimeException("Failed to find the newly created worker VM: " + workerVMName);
|
||||||
@ -1716,12 +1718,14 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
throw new Exception(msg);
|
throw new Exception(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String virtualHardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());
|
||||||
|
|
||||||
String diskDevice = volumeDeviceInfo.second();
|
String diskDevice = volumeDeviceInfo.second();
|
||||||
String disks[] = vmMo.getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
|
String disks[] = vmMo.getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
|
||||||
if (clonedWorkerVMNeeded) {
|
if (clonedWorkerVMNeeded) {
|
||||||
// 4 MB is the minimum requirement for VM memory in VMware
|
// 4 MB is the minimum requirement for VM memory in VMware
|
||||||
Pair<VirtualMachineMO, String[]> cloneResult =
|
Pair<VirtualMachineMO, String[]> cloneResult =
|
||||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, diskDevice, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
|
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, diskDevice, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), virtualHardwareVersion);
|
||||||
clonedVm = cloneResult.first();
|
clonedVm = cloneResult.first();
|
||||||
clonedVm.exportVm(exportPath, exportName, false, false);
|
clonedVm.exportVm(exportPath, exportName, false, false);
|
||||||
} else {
|
} else {
|
||||||
@ -1798,7 +1802,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
if(vmMo == null) {
|
if(vmMo == null) {
|
||||||
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
||||||
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
||||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
|
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
||||||
}
|
}
|
||||||
@ -2251,7 +2255,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
|
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
|
||||||
try {
|
try {
|
||||||
s_logger.info("Create worker VM " + dummyVmName);
|
s_logger.info("Create worker VM " + dummyVmName);
|
||||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
|
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
throw new Exception("Unable to create a dummy VM for volume creation");
|
throw new Exception("Unable to create a dummy VM for volume creation");
|
||||||
}
|
}
|
||||||
@ -2934,7 +2938,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
|
|
||||||
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
|
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
|
||||||
|
|
||||||
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
|
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
|
||||||
|
|
||||||
if (vmMo == null) {
|
if (vmMo == null) {
|
||||||
throw new Exception("Unable to create a dummy VM for volume creation");
|
throw new Exception("Unable to create a dummy VM for volume creation");
|
||||||
|
|||||||
@ -1604,7 +1604,7 @@ public class HypervisorHostHelper {
|
|||||||
|
|
||||||
return controllerSpec;
|
return controllerSpec;
|
||||||
}
|
}
|
||||||
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName) throws Exception {
|
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName, String hardwareVersion) throws Exception {
|
||||||
|
|
||||||
// Allow worker VM to float within cluster so that we will have better chance to
|
// Allow worker VM to float within cluster so that we will have better chance to
|
||||||
// create it successfully
|
// create it successfully
|
||||||
@ -1615,6 +1615,13 @@ public class HypervisorHostHelper {
|
|||||||
VirtualMachineMO workingVM = null;
|
VirtualMachineMO workingVM = null;
|
||||||
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
|
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
|
||||||
vmConfig.setName(vmName);
|
vmConfig.setName(vmName);
|
||||||
|
if (hardwareVersion != null){
|
||||||
|
vmConfig.setVersion(("vmx-" + hardwareVersion));
|
||||||
|
} else {
|
||||||
|
ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), hyperHost.getHyperHostCluster());
|
||||||
|
DatacenterMO dataCenterMo = new DatacenterMO(hyperHost.getContext(), hyperHost.getHyperHostDatacenter());
|
||||||
|
setVMHardwareVersion(vmConfig, clusterMo, dataCenterMo);
|
||||||
|
}
|
||||||
vmConfig.setMemoryMB((long)4);
|
vmConfig.setMemoryMB((long)4);
|
||||||
vmConfig.setNumCPUs(1);
|
vmConfig.setNumCPUs(1);
|
||||||
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
|
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
|
||||||
@ -1933,7 +1940,7 @@ public class HypervisorHostHelper {
|
|||||||
ManagedObjectReference morDs) throws Exception {
|
ManagedObjectReference morDs) throws Exception {
|
||||||
VmwareContext context = host.getContext();
|
VmwareContext context = host.getContext();
|
||||||
ManagedObjectReference morOvf = context.getServiceContent().getOvfManager();
|
ManagedObjectReference morOvf = context.getServiceContent().getOvfManager();
|
||||||
VirtualMachineMO workerVmMo = HypervisorHostHelper.createWorkerVM(host, new DatastoreMO(context, morDs), ovfName);
|
VirtualMachineMO workerVmMo = HypervisorHostHelper.createWorkerVM(host, new DatastoreMO(context, morDs), ovfName, null);
|
||||||
if (workerVmMo == null)
|
if (workerVmMo == null)
|
||||||
throw new Exception("Unable to find just-created worker VM");
|
throw new Exception("Unable to find just-created worker VM");
|
||||||
|
|
||||||
|
|||||||
@ -1959,21 +1959,21 @@ public class VirtualMachineMO extends BaseMO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return the disk chain (VMDK datastore paths) for cloned snapshot
|
// return the disk chain (VMDK datastore paths) for cloned snapshot
|
||||||
public Pair<VirtualMachineMO, String[]> cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice, ManagedObjectReference morDs)
|
public Pair<VirtualMachineMO, String[]> cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice, ManagedObjectReference morDs, String virtualHardwareVersion)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
assert (morDs != null);
|
assert (morDs != null);
|
||||||
String[] disks = getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
|
String[] disks = getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
|
||||||
VirtualMachineMO clonedVm = cloneFromDiskChain(clonedVmName, cpuSpeedMHz, memoryMb, disks, morDs);
|
VirtualMachineMO clonedVm = cloneFromDiskChain(clonedVmName, cpuSpeedMHz, memoryMb, disks, morDs, virtualHardwareVersion);
|
||||||
return new Pair<VirtualMachineMO, String[]>(clonedVm, disks);
|
return new Pair<VirtualMachineMO, String[]>(clonedVm, disks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualMachineMO cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception {
|
public VirtualMachineMO cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs, String cloneHardwareVersion) throws Exception {
|
||||||
assert (disks != null);
|
assert (disks != null);
|
||||||
assert (disks.length >= 1);
|
assert (disks.length >= 1);
|
||||||
|
|
||||||
HostMO hostMo = getRunningHost();
|
HostMO hostMo = getRunningHost();
|
||||||
|
|
||||||
VirtualMachineMO clonedVmMo = HypervisorHostHelper.createWorkerVM(hostMo, new DatastoreMO(hostMo.getContext(), morDs), clonedVmName);
|
VirtualMachineMO clonedVmMo = HypervisorHostHelper.createWorkerVM(hostMo, new DatastoreMO(hostMo.getContext(), morDs), clonedVmName, cloneHardwareVersion);
|
||||||
if (clonedVmMo == null)
|
if (clonedVmMo == null)
|
||||||
throw new Exception("Unable to find just-created blank VM");
|
throw new Exception("Unable to find just-created blank VM");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user