Skip to content

Commit 2a84ae4

Browse files
authored
vmware: Snapshot hardware version fix (#24)
https://shapeblue.atlassian.net/browse/FRO-932
1 parent 468c92e commit 2a84ae4

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
336336
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
337337

338338
workerVMName = hostService.getWorkerName(context, cmd, 0);
339-
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
339+
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);
340340

341341
if (vmMo == null) {
342342
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
@@ -645,7 +645,7 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
645645
}
646646

647647
// 4 MB is the minimum requirement for VM memory in VMware
648-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
648+
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
649649
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
650650
if (clonedVm == null) {
651651
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
@@ -962,7 +962,7 @@ private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volume
962962
}
963963

964964
// 4 MB is the minimum requirement for VM memory in VMware
965-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
965+
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
966966
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
967967
if (clonedVm == null) {
968968
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
@@ -1000,7 +1000,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
10001000
if (vmMo == null) {
10011001
// create a dummy worker vm for attaching the volume
10021002
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
1003-
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName);
1003+
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);
10041004

10051005
if (workerVm == null) {
10061006
String msg = "Unable to create worker VM to execute CopyVolumeCommand";

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ private Answer execute(ResizeVolumeCommand cmd) {
657657
dsMo = new DatastoreMO(hyperHost.getContext(), morDS);
658658
s_logger.info("Create worker VM " + vmName);
659659
// OfflineVmwareMigration: 2. create the worker with access to the data(store)
660-
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName);
660+
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName, null);
661661
if (vmMo == null) {
662662
// OfflineVmwareMigration: don't throw a general Exception but think of a specific one
663663
throw new Exception("Unable to create a worker VM for volume resize");
@@ -3822,7 +3822,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
38223822
dsMo = new DatastoreMO(hyperHost.getContext(), morSourceDS);
38233823
s_logger.info("Create worker VM " + vmName);
38243824
// OfflineVmwareMigration: 2. create the worker with access to the data(store)
3825-
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName);
3825+
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName, null);
38263826
if (vmMo == null) {
38273827
// OfflineVmwareMigration: don't throw a general Exception but think of a specific one
38283828
throw new CloudRuntimeException("Unable to create a worker VM for volume operation");

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
454454
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
455455

456456
try {
457-
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
457+
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
458458
if (vmMo == null) {
459459
throw new Exception("Unable to create a dummy VM for volume creation");
460460
}
@@ -640,7 +640,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
640640
if (vmMo == null || VmwareResource.getVmState(vmMo) == PowerState.PowerOff) {
641641
// create a dummy worker vm for attaching the volume
642642
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
643-
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName);
643+
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);
644644

645645
if (workerVm == null) {
646646
String msg = "Unable to create worker VM to execute CopyVolumeCommand";
@@ -774,7 +774,7 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
774774

775775
// 4 MB is the minimum requirement for VM memory in VMware
776776
Pair<VirtualMachineMO, String[]> cloneResult =
777-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
777+
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
778778
clonedVm = cloneResult.first();
779779

780780
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
@@ -1098,9 +1098,11 @@ private Pair<String, String[]> exportVolumeToSecondaryStroage(VirtualMachineMO v
10981098
throw new Exception(msg);
10991099
}
11001100

1101+
String virtualHardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());
1102+
11011103
// 4 MB is the minimum requirement for VM memory in VMware
11021104
Pair<VirtualMachineMO, String[]> cloneResult =
1103-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
1105+
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), virtualHardwareVersion);
11041106
clonedVm = cloneResult.first();
11051107
String disks[] = cloneResult.second();
11061108

@@ -1175,7 +1177,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
11751177
if(vmMo == null) {
11761178
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
11771179
workerVMName = hostService.getWorkerName(context, cmd, 0);
1178-
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
1180+
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);
11791181
if (vmMo == null) {
11801182
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
11811183
}
@@ -1563,7 +1565,7 @@ public Answer createVolume(CreateObjectCommand cmd) {
15631565
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
15641566
try {
15651567
s_logger.info("Create worker VM " + dummyVmName);
1566-
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
1568+
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
15671569
if (vmMo == null) {
15681570
throw new Exception("Unable to create a dummy VM for volume creation");
15691571
}
@@ -1910,7 +1912,7 @@ private void createVmdk(Command cmd, DatastoreMO dsMo, String vmdkDatastorePath,
19101912

19111913
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
19121914

1913-
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
1915+
VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
19141916

19151917
if (vmMo == null) {
19161918
throw new Exception("Unable to create a dummy VM for volume creation");

vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ private static VirtualDeviceConfigSpec getControllerSpec(String diskController,
14071407

14081408
return controllerSpec;
14091409
}
1410-
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName) throws Exception {
1410+
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName, String hardwareVersion) throws Exception {
14111411

14121412
// Allow worker VM to float within cluster so that we will have better chance to
14131413
// create it successfully
@@ -1418,6 +1418,9 @@ public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, Da
14181418
VirtualMachineMO workingVM = null;
14191419
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
14201420
vmConfig.setName(vmName);
1421+
if (hardwareVersion != null){
1422+
vmConfig.setVersion(("vmx-" + hardwareVersion));
1423+
}
14211424
vmConfig.setMemoryMB((long)4);
14221425
vmConfig.setNumCPUs(1);
14231426
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());

vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,21 +1872,21 @@ public String[] getCurrentSnapshotDiskChainDatastorePaths(String diskDevice) thr
18721872
}
18731873

18741874
// return the disk chain (VMDK datastore paths) for cloned snapshot
1875-
public Pair<VirtualMachineMO, String[]> cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice, ManagedObjectReference morDs)
1875+
public Pair<VirtualMachineMO, String[]> cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice, ManagedObjectReference morDs, String virtualHardwareVersion)
18761876
throws Exception {
18771877
assert (morDs != null);
18781878
String[] disks = getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
1879-
VirtualMachineMO clonedVm = cloneFromDiskChain(clonedVmName, cpuSpeedMHz, memoryMb, disks, morDs);
1879+
VirtualMachineMO clonedVm = cloneFromDiskChain(clonedVmName, cpuSpeedMHz, memoryMb, disks, morDs, virtualHardwareVersion);
18801880
return new Pair<VirtualMachineMO, String[]>(clonedVm, disks);
18811881
}
18821882

1883-
public VirtualMachineMO cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception {
1883+
public VirtualMachineMO cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs, String cloneHardwareVersion) throws Exception {
18841884
assert (disks != null);
18851885
assert (disks.length >= 1);
18861886

18871887
HostMO hostMo = getRunningHost();
18881888

1889-
VirtualMachineMO clonedVmMo = HypervisorHostHelper.createWorkerVM(hostMo, new DatastoreMO(hostMo.getContext(), morDs), clonedVmName);
1889+
VirtualMachineMO clonedVmMo = HypervisorHostHelper.createWorkerVM(hostMo, new DatastoreMO(hostMo.getContext(), morDs), clonedVmName, cloneHardwareVersion);
18901890
if (clonedVmMo == null)
18911891
throw new Exception("Unable to find just-created blank VM");
18921892

0 commit comments

Comments
 (0)