Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
}

// 4 MB is the minimum requirement for VM memory in VMware
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
String vmxFormattedVirtualHardwareVersion = VirtualMachineMO.getVmxFormattedVirtualHardwareVersion(vmMo.getVirtualHardwareVersion());
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), vmxFormattedVirtualHardwareVersion);
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
if (clonedVm == null) {
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
Expand Down Expand Up @@ -965,7 +966,8 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume

if (clonedWorkerVMNeeded) {
// 4 MB is the minimum requirement for VM memory in VMware
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
String vmxFormattedVirtualHardwareVersion = VirtualMachineMO.getVmxFormattedVirtualHardwareVersion(vmMo.getVirtualHardwareVersion());
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), vmxFormattedVirtualHardwareVersion);
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
if (clonedVm == null) {
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ private static VirtualDeviceConfigSpec getControllerSpec(String diskController,

return controllerSpec;
}
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName, String hardwareVersion) throws Exception {
public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO dsMo, String vmName, String vmxFormattedHardwareVersion) throws Exception {

// Allow worker VM to float within cluster so that we will have better chance to
// create it successfully
Expand All @@ -1651,8 +1651,8 @@ public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, Da
VirtualMachineMO workingVM = null;
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
vmConfig.setName(vmName);
if (hardwareVersion != null){
vmConfig.setVersion(("vmx-" + hardwareVersion));
if (StringUtils.isNotBlank(vmxFormattedHardwareVersion)){
vmConfig.setVersion(vmxFormattedHardwareVersion);
} else {
ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), hyperHost.getHyperHostCluster());
DatacenterMO dataCenterMo = new DatacenterMO(hyperHost.getContext(), hyperHost.getHyperHostDatacenter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -3292,6 +3293,18 @@ public int getVirtualHardwareVersion() throws Exception {
return vhOption.getHwVersion();
}

/**
* Return a hardware version string in the format expected by Vmware
* Format: "vmx-DD" where DD represents the hardware version number
* @param virtualHardwareVersion numeric virtual hardware version
*/
public static String getVmxFormattedVirtualHardwareVersion(int virtualHardwareVersion) {
if (virtualHardwareVersion < 1) {
throw new CloudRuntimeException("Invalid hardware version: " + virtualHardwareVersion);
}
return String.format("vmx-%02d", virtualHardwareVersion);
}

public VirtualHardwareOption getVirtualHardwareOption() throws Exception {
VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(getEnvironmentBrowser(), null, null);
return vmConfigOption.getHardwareOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.cloud.hypervisor.vmware.util.VmwareClient;
import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.cloud.utils.exception.CloudRuntimeException;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.VirtualDevice;
import com.vmware.vim25.VirtualLsiLogicController;
Expand All @@ -27,6 +28,7 @@
import com.vmware.vim25.VirtualSCSISharing;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -117,4 +119,21 @@ public void TestEnsureLsiLogicDeviceControllers() {
}

}

@Test
public void testGetVmxFormattedVirtualHardwareVersionOneDigit() {
String vmxHwVersion = VirtualMachineMO.getVmxFormattedVirtualHardwareVersion(8);
Assert.assertEquals("vmx-08", vmxHwVersion);
}

@Test
public void testGetVmxFormattedVirtualHardwareVersionTwoDigits() {
String vmxHwVersion = VirtualMachineMO.getVmxFormattedVirtualHardwareVersion(11);
Assert.assertEquals("vmx-11", vmxHwVersion);
}

@Test(expected = CloudRuntimeException.class)
public void testGetVmxFormattedVirtualHardwareVersionInvalid() {
VirtualMachineMO.getVmxFormattedVirtualHardwareVersion(-1);
}
}