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 @@ -344,7 +344,7 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);

workerVMName = hostService.getWorkerName(context, cmd, 0);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);

if (vmMo == null) {
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
Expand Down Expand Up @@ -647,7 +647,7 @@ 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()));
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
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 +965,7 @@ 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()));
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), null);
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 @@ -1008,7 +1008,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
if (vmMo == null) {
// create a dummy worker vm for attaching the volume
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName);
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);

if (workerVm == null) {
String msg = "Unable to create worker VM to execute CopyVolumeCommand";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private Answer execute(ResizeVolumeCommand cmd) {
s_logger.info("Create worker VM " + vmName);

// 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) {
// OfflineVmwareMigration: don't throw a general Exception but think of a specific one
Expand Down Expand Up @@ -4595,7 +4595,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
dsMo = new DatastoreMO(hyperHost.getContext(), morSourceDS);
s_logger.info("Create worker VM " + vmName);
// 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) {
// 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private String cleanUpDatastore(Command cmd, HostDatastoreSystemMO hostDatastore
if (vmName != null) {
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) {
throw new Exception("Unable to create a worker VM for volume creation");
Expand Down Expand Up @@ -794,7 +794,7 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
String dummyVmName = hostService.getWorkerName(context, cmd, 0);

try {
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
if (vmMo == null) {
throw new Exception("Unable to create a dummy VM for volume creation");
}
Expand Down Expand Up @@ -995,7 +995,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
if (vmMo == null || VmwareResource.getVmState(vmMo) == PowerState.PowerOff) {
// create a dummy worker vm for attaching the volume
DatastoreMO dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName);
workerVm = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);

if (workerVm == null) {
String msg = "Unable to create worker VM to execute CopyVolumeCommand";
Expand Down Expand Up @@ -1130,9 +1130,11 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
throw new Exception(msg);
}

String hardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());

// 4 MB is the minimum requirement for VM memory in VMware
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.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
Expand Down Expand Up @@ -1194,7 +1196,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
if (volume.getVmName() == null) {
ManagedObjectReference secMorDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, volume.getDataStore().getUuid());
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) {
throw new Exception("Unable to find created worker VM");
}
Expand Down Expand Up @@ -1551,7 +1553,7 @@ private void exportManagedStorageSnapshotToTemplate(CopyCommand cmd, String inst
ManagedObjectReference dsMor = hyperHost.findDatastoreByName(dsFile.getDatastoreName());
DatastoreMO dsMo = new DatastoreMO(context, dsMor);

VirtualMachineMO workerVM = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
VirtualMachineMO workerVM = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);

if (workerVM == null) {
throw new CloudRuntimeException("Failed to find the newly created worker VM: " + workerVMName);
Expand Down Expand Up @@ -1716,12 +1718,14 @@ private Pair<String, String[]> exportVolumeToSecondaryStorage(VirtualMachineMO v
throw new Exception(msg);
}

String virtualHardwareVersion = String.valueOf(vmMo.getVirtualHardwareVersion());

String diskDevice = volumeDeviceInfo.second();
String disks[] = vmMo.getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
if (clonedWorkerVMNeeded) {
// 4 MB is the minimum requirement for VM memory in VMware
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.exportVm(exportPath, exportName, false, false);
} else {
Expand Down Expand Up @@ -1798,7 +1802,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
if(vmMo == null) {
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
workerVMName = hostService.getWorkerName(context, cmd, 0);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName, null);
if (vmMo == null) {
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
}
Expand Down Expand Up @@ -2251,7 +2255,7 @@ public Answer createVolume(CreateObjectCommand cmd) {
String dummyVmName = hostService.getWorkerName(context, cmd, 0);
try {
s_logger.info("Create worker VM " + dummyVmName);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName);
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null);
if (vmMo == null) {
throw new Exception("Unable to create a dummy VM for volume creation");
}
Expand Down Expand Up @@ -2934,7 +2938,7 @@ private void createVmdk(Command cmd, DatastoreMO dsMo, String vmdkDatastorePath,

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) {
throw new Exception("Unable to create a dummy VM for volume creation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ private static VirtualDeviceConfigSpec getControllerSpec(String diskController,

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
// create it successfully
Expand All @@ -1615,6 +1615,13 @@ public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, Da
VirtualMachineMO workingVM = null;
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
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.setNumCPUs(1);
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
Expand Down Expand Up @@ -1933,7 +1940,7 @@ public static void createOvfFile(VmwareHypervisorHost host, String diskFileName,
ManagedObjectReference morDs) throws Exception {
VmwareContext context = host.getContext();
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)
throw new Exception("Unable to find just-created worker VM");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1959,21 +1959,21 @@ public String[] getCurrentSnapshotDiskChainDatastorePaths(String diskDevice) thr
}

// 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 {
assert (morDs != null);
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);
}

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.length >= 1);

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)
throw new Exception("Unable to find just-created blank VM");

Expand Down