BUG-ID: CLOUDSTACK-7102. Volume migration fails with 'VM i-2-3-VM does not exist in VMware datacenter' expection.

Look for a VM in vCenter based on both the vCenter name and CS internal name (required in case 'vm.instancename.flag' is enabled).
During Attach Volume and Volume Migration, for lookup and other operations use VM's name as obtained from vCenter instead of using the name set in the agent command.
This commit is contained in:
Likitha Shetty 2014-10-28 16:38:18 +05:30
parent 5d094e5cab
commit b8fdda0a34
3 changed files with 11 additions and 14 deletions

View File

@ -2904,7 +2904,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
VirtualMachineTO vmTo = cmd.getVirtualMachine();
final String vmName = vmTo.getName();
String vmName = vmTo.getName();
VmwareHypervisorHost srcHyperHost = null;
VmwareHypervisorHost tgtHyperHost = null;
@ -2954,6 +2954,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.error(msg);
throw new Exception(msg);
}
vmName = vmMo.getName();
// Get details of each target datastore & attach to source host.
for (Entry<VolumeTO, StorageFilerTO> entry : volToFiler.entrySet()) {
@ -3083,7 +3084,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.info("Executing resource MigrateVolumeCommand: " + _gson.toJson(cmd));
}
final String vmName = cmd.getAttachedVmName();
String vmName = cmd.getAttachedVmName();
VirtualMachineMO vmMo = null;
VmwareHypervisorHost srcHyperHost = null;
@ -3110,6 +3111,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.error(msg);
throw new Exception(msg);
}
vmName = vmMo.getName();
morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(srcHyperHost, tgtDsName);
if (morDs == null) {
String msg = "Unable to find the mounted datastore with name " + tgtDsName + " to execute MigrateVolumeCommand";

View File

@ -1299,6 +1299,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
s_logger.error(msg);
throw new Exception(msg);
}
vmName = vmMo.getName();
ManagedObjectReference morDs = null;

View File

@ -82,19 +82,13 @@ public class DatacenterMO extends BaseMO {
}
public VirtualMachineMO findVm(String vmName) throws Exception {
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name"});
if (ocs != null && ocs.size() > 0) {
for (ObjectContent oc : ocs) {
List<DynamicProperty> props = oc.getPropSet();
if (props != null) {
for (DynamicProperty prop : props) {
if (prop.getVal().toString().equals(vmName))
return new VirtualMachineMO(_context, oc.getObj());
}
}
}
int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
if (key == 0) {
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
}
return null;
String instanceNameCustomField = "value[" + key + "]";
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name", instanceNameCustomField});
return HypervisorHostHelper.findVmFromObjectContent(_context, ocs.toArray(new ObjectContent[0]), vmName, instanceNameCustomField);
}
public List<VirtualMachineMO> findVmByNameAndLabel(String vmLabel) throws Exception {