Skip to content

Commit c8a437b

Browse files
Likitha Shettyyadvr
authored andcommitted
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. (cherry picked from commit b8fdda0) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 8f4aa23 commit c8a437b

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
29212921
}
29222922

29232923
VirtualMachineTO vmTo = cmd.getVirtualMachine();
2924-
final String vmName = vmTo.getName();
2924+
String vmName = vmTo.getName();
29252925

29262926
VmwareHypervisorHost srcHyperHost = null;
29272927
VmwareHypervisorHost tgtHyperHost = null;
@@ -2971,6 +2971,7 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
29712971
s_logger.error(msg);
29722972
throw new Exception(msg);
29732973
}
2974+
vmName = vmMo.getName();
29742975

29752976
// Get details of each target datastore & attach to source host.
29762977
for (Entry<VolumeTO, StorageFilerTO> entry : volToFiler.entrySet()) {
@@ -3100,7 +3101,7 @@ private Answer execute(MigrateVolumeCommand cmd) {
31003101
s_logger.info("Executing resource MigrateVolumeCommand: " + _gson.toJson(cmd));
31013102
}
31023103

3103-
final String vmName = cmd.getAttachedVmName();
3104+
String vmName = cmd.getAttachedVmName();
31043105

31053106
VirtualMachineMO vmMo = null;
31063107
VmwareHypervisorHost srcHyperHost = null;
@@ -3127,6 +3128,7 @@ private Answer execute(MigrateVolumeCommand cmd) {
31273128
s_logger.error(msg);
31283129
throw new Exception(msg);
31293130
}
3131+
vmName = vmMo.getName();
31303132
morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(srcHyperHost, tgtDsName);
31313133
if (morDs == null) {
31323134
String msg = "Unable to find the mounted datastore with name " + tgtDsName + " to execute MigrateVolumeCommand";

‎plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean
12901290
s_logger.error(msg);
12911291
throw new Exception(msg);
12921292
}
1293+
vmName = vmMo.getName();
12931294

12941295
ManagedObjectReference morDs = null;
12951296

‎vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,13 @@ public void registerTemplate(ManagedObjectReference morHost, String datastoreNam
8282
}
8383

8484
public VirtualMachineMO findVm(String vmName) throws Exception {
85-
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name"});
86-
if (ocs != null && ocs.size() > 0) {
87-
for (ObjectContent oc : ocs) {
88-
List<DynamicProperty> props = oc.getPropSet();
89-
if (props != null) {
90-
for (DynamicProperty prop : props) {
91-
if (prop.getVal().toString().equals(vmName))
92-
return new VirtualMachineMO(_context, oc.getObj());
93-
}
94-
}
95-
}
85+
int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
86+
if (key == 0) {
87+
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
9688
}
97-
return null;
89+
String instanceNameCustomField = "value[" + key + "]";
90+
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name", instanceNameCustomField});
91+
return HypervisorHostHelper.findVmFromObjectContent(_context, ocs.toArray(new ObjectContent[0]), vmName, instanceNameCustomField);
9892
}
9993

10094
public List<VirtualMachineMO> findVmByNameAndLabel(String vmLabel) throws Exception {

0 commit comments

Comments
 (0)