mirror of https://github.com/apache/cloudstack.git
Move clone operation into virtual machine mo
This commit is contained in:
parent
e4727f7fa0
commit
874b5a36e0
|
|
@ -1244,9 +1244,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||
VirtualDisk requiredDisk = volumeDeviceInfo.first();
|
||||
vmMo.createFullCloneWithSpecificDisk(templateUniqueName, dcMo.getVmFolder(), morPool, requiredDisk);
|
||||
clonedVm = dcMo.findVm(templateUniqueName);
|
||||
|
||||
checkIfVMHasOnlyRequiredDisk(clonedVm, requiredDisk);
|
||||
|
||||
clonedVm.tagAsWorkerVM();
|
||||
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, false, false);
|
||||
|
||||
|
|
@ -1839,7 +1836,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
checkIfVMHasOnlyRequiredDisk(clonedVm, requiredDisk);
|
||||
clonedVm.tagAsWorkerVM();
|
||||
vmMo = clonedVm;
|
||||
}
|
||||
|
|
@ -1854,19 +1850,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkIfVMHasOnlyRequiredDisk(VirtualMachineMO clonedVm, VirtualDisk requiredDisk) throws Exception {
|
||||
|
||||
s_logger.info(String.format("Checking if Cloned VM %s is created only with required Disk, if not detach the remaining disks", clonedVm.getName()));
|
||||
VirtualDisk[] vmDisks = clonedVm.getAllDiskDevice();
|
||||
if (vmDisks.length != 1) {
|
||||
String baseName = VmwareHelper.getDiskDeviceFileName(requiredDisk);
|
||||
s_logger.info(String.format("Detaching all disks for the cloned VM: %s except disk with base name: %s, key=%d", clonedVm.getName(), baseName, requiredDisk.getKey()));
|
||||
clonedVm.detachAllDisksExcept(VmwareHelper.getDiskDeviceFileName(requiredDisk), null);
|
||||
} else {
|
||||
s_logger.info(String.format("Cloned VM %s is created only with required Disk", clonedVm.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
// Ternary<String(backup uuid in secondary storage), String(device bus name), String[](original disk chain in the snapshot)>
|
||||
private Ternary<String, String, String[]> backupSnapshotToSecondaryStorage(VmwareContext context, VirtualMachineMO vmMo, VmwareHypervisorHost hypervisorHost, String installPath, String volumePath, String snapshotUuid,
|
||||
String secStorageUrl, String prevSnapshotUuid, String prevBackupUuid, String workerVmName,
|
||||
|
|
|
|||
|
|
@ -784,12 +784,41 @@ public class VirtualMachineMO extends BaseMO {
|
|||
if (result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
s_logger.debug(String.format("Cloned VM: %s as %s", getName(), cloneName));
|
||||
makeSureVMHasOnlyRequiredDisk(cloneName, requiredDisk);
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
makeSureVMHasOnlyRequiredDisk(cloneName, requiredDisk);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
private void makeSureVMHasOnlyRequiredDisk(String vmName, VirtualDisk requiredDisk) throws Exception {
|
||||
VirtualMachineRuntimeInfo runtimeInfo = getRuntimeInfo();
|
||||
HostMO hostMo = new HostMO(_context, runtimeInfo.getHost());
|
||||
DatacenterMO dcMo = new DatacenterMO(_context, hostMo.getHyperHostDatacenter());
|
||||
|
||||
VirtualMachineMO clonedVm = dcMo.findVm(vmName);
|
||||
VirtualDisk[] vmDisks = clonedVm.getAllDiskDevice();
|
||||
s_logger.debug(String.format("Checking if VM %s is created only with required Disk, if not detach the remaining disks", vmName));
|
||||
if (vmDisks.length != 1) {
|
||||
VirtualDisk requiredCloneDisk = null;
|
||||
for (VirtualDisk vmDisk: vmDisks) {
|
||||
if (vmDisk.getKey() == requiredDisk.getKey()) {
|
||||
requiredCloneDisk = vmDisk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (requiredCloneDisk != null) {
|
||||
String baseName = VmwareHelper.getDiskDeviceFileName(requiredCloneDisk);
|
||||
s_logger.debug(String.format("Detaching all disks for the VM: %s except disk with base name: %s, key=%d", vmName, baseName, requiredCloneDisk.getKey()));
|
||||
clonedVm.detachAllDisksExcept(baseName, null);
|
||||
} else {
|
||||
s_logger.error(String.format("Failed to identify required disk in VM %s", vmName));
|
||||
}
|
||||
} else {
|
||||
s_logger.debug(String.format("VM %s is created only with required Disk", vmName));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs, Storage.ProvisioningType diskProvisioningType)
|
||||
|
|
|
|||
Loading…
Reference in New Issue