@@ -3387,7 +3387,6 @@ protected Answer execute(MigrateVmToPoolCommand cmd) {
33873387
33883388 private Answer migrateAndAnswer (VirtualMachineMO vmMo , String poolUuid , VmwareHypervisorHost hyperHost , Command cmd ) throws Exception {
33893389 String hostNameInTargetCluster = null ;
3390- VmwareHypervisorHost hostInTargetCluster = null ;
33913390 List <Pair <VolumeTO , StorageFilerTO >> volToFiler = new ArrayList <>();
33923391 if (cmd instanceof MigrateVmToPoolCommand ) {
33933392 MigrateVmToPoolCommand mcmd = (MigrateVmToPoolCommand )cmd ;
@@ -3396,13 +3395,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
33963395 } else if (cmd instanceof MigrateVolumeCommand ) {
33973396 hostNameInTargetCluster = ((MigrateVolumeCommand )cmd ).getHostGuidInTargetCluster ();
33983397 }
3399- if (StringUtils .isNotBlank (hostNameInTargetCluster )) {
3400- String hostInTargetClusterMorInfo = hostNameInTargetCluster .split ("@" )[0 ];
3401- ManagedObjectReference morHostInTargetCluster = new ManagedObjectReference ();
3402- morHostInTargetCluster .setType (hostInTargetClusterMorInfo .split (":" )[0 ]);
3403- morHostInTargetCluster .setValue (hostInTargetClusterMorInfo .split (":" )[1 ]);
3404- hostInTargetCluster = new HostMO (getServiceContext (), morHostInTargetCluster );
3405- }
3398+ VmwareHypervisorHost hostInTargetCluster = VmwareHelper .getHostMOFromHostName (getServiceContext (), hostNameInTargetCluster );
34063399 try {
34073400 // OfflineVmwareMigration: getVolumesFromCommand(cmd);
34083401 Map <Integer , Long > volumeDeviceKey = new HashMap <>();
@@ -3581,19 +3574,11 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
35813574
35823575 ManagedObjectReference morSourceDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , cmd .getSourcePool ().getUuid ());
35833576 DatastoreMO sourceDsMo = new DatastoreMO (hyperHost .getContext (), morSourceDs );
3584- DatacenterMO dcMo = new DatacenterMO (hyperHost .getContext (), hyperHost .getHyperHostDatacenter ());
35853577 String targetDsName = cmd .getTargetPool ().getUuid ();
3586- String hostNameInTargetCluster = cmd .getHostGuidInTargetCluster ();
3587- VmwareHypervisorHost hostInTargetCluster = null ;
3588- if (StringUtils .isNotBlank (hostNameInTargetCluster )) {
3589- String hostInTargetClusterMorInfo = hostNameInTargetCluster .split ("@" )[0 ];
3590- ManagedObjectReference morHostInTargetCluster = new ManagedObjectReference ();
3591- morHostInTargetCluster .setType (hostInTargetClusterMorInfo .split (":" )[0 ]);
3592- morHostInTargetCluster .setValue (hostInTargetClusterMorInfo .split (":" )[1 ]);
3593- hostInTargetCluster = new HostMO (getServiceContext (), morHostInTargetCluster );
3594- }
3578+ VmwareHypervisorHost hostInTargetCluster = VmwareHelper .getHostMOFromHostName (getServiceContext (),
3579+ cmd .getHostGuidInTargetCluster ());
35953580 VmwareHypervisorHost dsHost = hostInTargetCluster == null ? hyperHost : hostInTargetCluster ;
3596- ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , hyperHost );
3581+ ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , dsHost );
35973582 if (morTargetDS == null ) {
35983583 String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
35993584 s_logger .error (msg );
@@ -5731,30 +5716,23 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
57315716 VmwareHypervisorHost targetHyperHost = hostInTargetCluster ;
57325717 VirtualMachineMO vmMo = null ;
57335718 ManagedObjectReference morSourceHostDc = null ;
5734- ManagedObjectReference morTargetHostDc = null ;
5735- ManagedObjectReference morTargetHost = new ManagedObjectReference ();
57365719 VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec ();
57375720 List <VirtualMachineRelocateSpecDiskLocator > diskLocators = new ArrayList <VirtualMachineRelocateSpecDiskLocator >();
57385721 Set <String > mountedDatastoresAtSource = new HashSet <String >();
57395722 List <VolumeObjectTO > volumeToList = new ArrayList <>();
57405723 Map <Long , Integer > volumeDeviceKey = new HashMap <Long , Integer >();
5741- if (StringUtils .isNotBlank (targetHost )) {
5742- String targetHostMorInfo = targetHost .split ("@" )[0 ];
5743- morTargetHost .setType (targetHostMorInfo .split (":" )[0 ]);
5744- morTargetHost .setValue (targetHostMorInfo .split (":" )[1 ]);
5745- }
57465724
57475725 try {
57485726 if (sourceHyperHost == null ) {
57495727 sourceHyperHost = getHyperHost (getServiceContext ());
57505728 }
57515729 if (targetHyperHost == null && StringUtils .isNotBlank (targetHost )) {
5752- targetHyperHost = new HostMO (getServiceContext (), morTargetHost );
5730+ targetHyperHost = VmwareHelper . getHostMOFromHostName (getServiceContext (), targetHost );
57535731 }
57545732 morSourceHostDc = sourceHyperHost .getHyperHostDatacenter ();
57555733 DatacenterMO dcMo = new DatacenterMO (sourceHyperHost .getContext (), morSourceHostDc );
57565734 if (targetHyperHost != null ) {
5757- morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
5735+ ManagedObjectReference morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
57585736 if (!morSourceHostDc .getValue ().equalsIgnoreCase (morTargetHostDc .getValue ())) {
57595737 String msg = "VM " + vmName + " cannot be migrated between different datacenter" ;
57605738 throw new CloudRuntimeException (msg );
@@ -5845,12 +5823,12 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
58455823 }
58465824
58475825 // Specific section for MigrateVmWithStorageCommand
5848- if (vmTo != null ) {
5826+ if (vmTo != null && targetHyperHost != null ) {
58495827 // Prepare network at target before migration
58505828 NicTO [] nics = vmTo .getNics ();
58515829 for (NicTO nic : nics ) {
58525830 // prepare network on the host
5853- prepareNetworkFromNicInfo (new HostMO ( getServiceContext (), morTargetHost ) , nic , false , vmTo .getType ());
5831+ prepareNetworkFromNicInfo (( HostMO ) targetHyperHost , nic , false , vmTo .getType ());
58545832 }
58555833 // Ensure secondary storage mounted on target host
58565834 VmwareManager mgr = targetHyperHost .getContext ().getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
0 commit comments