Fixed volume migrations to and fro vVols datastorewq

This commit is contained in:
Harikrishna Patnala 2020-09-10 15:00:42 +05:30
parent 700ab1a5ef
commit f825a94dc4
4 changed files with 24 additions and 8 deletions

View File

@ -4760,7 +4760,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
VirtualMachineMO vmMo = null; VirtualMachineMO vmMo = null;
DatastoreMO dsMo = null; DatastoreMO dsMo = null;
DatastoreMO destinationDsMo = null;
ManagedObjectReference morSourceDS = null; ManagedObjectReference morSourceDS = null;
ManagedObjectReference morDestintionDS = null;
String vmdkDataStorePath = null; String vmdkDataStorePath = null;
String vmName = null; String vmName = null;
@ -4768,15 +4770,21 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
// OfflineVmwareMigration: we need to refactor the worker vm creation out for use in migration methods as well as here // OfflineVmwareMigration: we need to refactor the worker vm creation out for use in migration methods as well as here
// OfflineVmwareMigration: this method is 100 lines and needs refactorring anyway // OfflineVmwareMigration: this method is 100 lines and needs refactorring anyway
// we need to spawn a worker VM to attach the volume to and move it // we need to spawn a worker VM to attach the volume to and move it
vmName = getWorkerName(getServiceContext(), cmd, 0, dsMo); morSourceDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getSourcePool().getUuid());
dsMo = new DatastoreMO(hyperHost.getContext(), morSourceDS);
morDestintionDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getTargetPool().getUuid());
destinationDsMo = new DatastoreMO(hyperHost.getContext(), morDestintionDS);
if (dsMo.getDatastoreType().equalsIgnoreCase("VVOL"))
vmName = getWorkerName(getServiceContext(), cmd, 0, dsMo);
if (destinationDsMo.getDatastoreType().equalsIgnoreCase("VVOL"))
vmName = getWorkerName(getServiceContext(), cmd, 0, destinationDsMo);
// OfflineVmwareMigration: refactor for re-use // OfflineVmwareMigration: refactor for re-use
// OfflineVmwareMigration: 1. find data(store) // OfflineVmwareMigration: 1. find data(store)
// OfflineVmwareMigration: more robust would be to find the store given the volume as it might have been moved out of band or due to error // OfflineVmwareMigration: more robust would be to find the store given the volume as it might have been moved out of band or due to error
// example: DatastoreMO existingVmDsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(fileInDatastore.getDatastoreName())); // example: DatastoreMO existingVmDsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(fileInDatastore.getDatastoreName()));
morSourceDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getSourcePool().getUuid());
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, null); vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName, null);

View File

@ -989,7 +989,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
volumeName = srcVolumePath.substring(index + 1); volumeName = srcVolumePath.substring(index + 1);
} }
String newVolume = VmwareHelper.getVCenterSafeUuid(); String newVolume = VmwareHelper.getVCenterSafeUuid(dsMo);
restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, volumeFolder, volumeName, wait, nfsVersion); restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, volumeFolder, volumeName, wait, nfsVersion);
return new Pair<>(volumeFolder, newVolume); return new Pair<>(volumeFolder, newVolume);
@ -3590,7 +3590,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
String backupPath = backedUpSnapshotUuid.substring(0, index); String backupPath = backedUpSnapshotUuid.substring(0, index);
backedUpSnapshotUuid = backedUpSnapshotUuid.substring(index + 1); backedUpSnapshotUuid = backedUpSnapshotUuid.substring(index + 1);
String details; String details;
String newVolumeName = VmwareHelper.getVCenterSafeUuid();
VmwareContext context = hostService.getServiceContext(cmd); VmwareContext context = hostService.getServiceContext(cmd);
try { try {
@ -3602,13 +3601,14 @@ public class VmwareStorageProcessor implements StorageProcessor {
throw new Exception(msg); throw new Exception(msg);
} }
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
String newVolumeName = VmwareHelper.getVCenterSafeUuid(primaryDsMo);
// strip off the extension since restoreVolumeFromSecStorage internally will append suffix there. // strip off the extension since restoreVolumeFromSecStorage internally will append suffix there.
if (backedUpSnapshotUuid.endsWith(".ova")){ if (backedUpSnapshotUuid.endsWith(".ova")){
backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ova", ""); backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ova", "");
} else if (backedUpSnapshotUuid.endsWith(".ovf")){ } else if (backedUpSnapshotUuid.endsWith(".ovf")){
backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ovf", ""); backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ovf", "");
} }
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, _nfsVersion); restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, _nfsVersion);
VolumeObjectTO newVol = new VolumeObjectTO(); VolumeObjectTO newVol = new VolumeObjectTO();

View File

@ -406,6 +406,8 @@ public class DatastoreMO extends BaseMO {
s_logger.info("Found file " + fileName + " in datastore at " + absoluteFileName); s_logger.info("Found file " + fileName + " in datastore at " + absoluteFileName);
if (parentFolderPath.endsWith("]")) if (parentFolderPath.endsWith("]"))
absoluteFileName += " "; absoluteFileName += " ";
else if (!parentFolderPath.endsWith("/"))
absoluteFileName +="/";
absoluteFileName += fi.getPath(); absoluteFileName += fi.getPath();
if(isValidCloudStackFolderPath(parentFolderPath, searchExcludedFolders)) { if(isValidCloudStackFolderPath(parentFolderPath, searchExcludedFolders)) {
return absoluteFileName; return absoluteFileName;

View File

@ -76,7 +76,9 @@ import com.vmware.vim25.VirtualVmxnet2;
import com.vmware.vim25.VirtualVmxnet3; import com.vmware.vim25.VirtualVmxnet3;
import com.cloud.hypervisor.vmware.mo.DiskControllerType; import com.cloud.hypervisor.vmware.mo.DiskControllerType;
import com.cloud.hypervisor.vmware.mo.DatastoreMO;
import com.cloud.hypervisor.vmware.mo.HostMO; import com.cloud.hypervisor.vmware.mo.HostMO;
import com.cloud.hypervisor.vmware.mo.CustomFieldConstants;
import com.cloud.hypervisor.vmware.mo.LicenseAssignmentManagerMO; import com.cloud.hypervisor.vmware.mo.LicenseAssignmentManagerMO;
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType; import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO; import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
@ -692,9 +694,13 @@ public class VmwareHelper {
return hotplugSupportedByLicense; return hotplugSupportedByLicense;
} }
public static String getVCenterSafeUuid() { public static String getVCenterSafeUuid(DatastoreMO dsMo) throws Exception{
// Object name that is greater than 32 is not safe in vCenter // Object name that is greater than 32 is not safe in vCenter
return UUID.randomUUID().toString().replaceAll("-", ""); String uuid = UUID.randomUUID().toString().replaceAll("-", "");
if (dsMo.getDatastoreType().equalsIgnoreCase("VVOL")) {
return CustomFieldConstants.CLOUD_UUID + "-" + uuid;
}
return uuid;
} }
public static String getRecommendedDiskControllerFromDescriptor(GuestOsDescriptor guestOsDescriptor) throws Exception { public static String getRecommendedDiskControllerFromDescriptor(GuestOsDescriptor guestOsDescriptor) throws Exception {