@@ -3826,7 +3826,6 @@ protected Answer execute(MigrateVmToPoolCommand cmd) {
38263826
38273827 private Answer migrateAndAnswer (VirtualMachineMO vmMo , String poolUuid , VmwareHypervisorHost hyperHost , Command cmd ) throws Exception {
38283828 String hostNameInTargetCluster = null ;
3829- VmwareHypervisorHost hostInTargetCluster = null ;
38303829 List <Pair <VolumeTO , StorageFilerTO >> volToFiler = new ArrayList <>();
38313830 if (cmd instanceof MigrateVmToPoolCommand ) {
38323831 MigrateVmToPoolCommand mcmd = (MigrateVmToPoolCommand )cmd ;
@@ -3835,13 +3834,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
38353834 } else if (cmd instanceof MigrateVolumeCommand ) {
38363835 hostNameInTargetCluster = ((MigrateVolumeCommand )cmd ).getHostGuidInTargetCluster ();
38373836 }
3838- if (StringUtils .isNotBlank (hostNameInTargetCluster )) {
3839- String hostInTargetClusterMorInfo = hostNameInTargetCluster .split ("@" )[0 ];
3840- ManagedObjectReference morHostInTargetCluster = new ManagedObjectReference ();
3841- morHostInTargetCluster .setType (hostInTargetClusterMorInfo .split (":" )[0 ]);
3842- morHostInTargetCluster .setValue (hostInTargetClusterMorInfo .split (":" )[1 ]);
3843- hostInTargetCluster = new HostMO (getServiceContext (), morHostInTargetCluster );
3844- }
3837+ VmwareHypervisorHost hostInTargetCluster = VmwareHelper .getHostMOFromHostName (getServiceContext (), hostNameInTargetCluster );
38453838 try {
38463839 // OfflineVmwareMigration: getVolumesFromCommand(cmd);
38473840 Map <Integer , Long > volumeDeviceKey = new HashMap <>();
@@ -4020,19 +4013,11 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
40204013
40214014 ManagedObjectReference morSourceDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , cmd .getSourcePool ().getUuid ());
40224015 DatastoreMO sourceDsMo = new DatastoreMO (hyperHost .getContext (), morSourceDs );
4023- DatacenterMO dcMo = new DatacenterMO (hyperHost .getContext (), hyperHost .getHyperHostDatacenter ());
40244016 String targetDsName = cmd .getTargetPool ().getUuid ();
4025- String hostNameInTargetCluster = cmd .getHostGuidInTargetCluster ();
4026- VmwareHypervisorHost hostInTargetCluster = null ;
4027- if (StringUtils .isNotBlank (hostNameInTargetCluster )) {
4028- String hostInTargetClusterMorInfo = hostNameInTargetCluster .split ("@" )[0 ];
4029- ManagedObjectReference morHostInTargetCluster = new ManagedObjectReference ();
4030- morHostInTargetCluster .setType (hostInTargetClusterMorInfo .split (":" )[0 ]);
4031- morHostInTargetCluster .setValue (hostInTargetClusterMorInfo .split (":" )[1 ]);
4032- hostInTargetCluster = new HostMO (getServiceContext (), morHostInTargetCluster );
4033- }
4017+ VmwareHypervisorHost hostInTargetCluster = VmwareHelper .getHostMOFromHostName (getServiceContext (),
4018+ cmd .getHostGuidInTargetCluster ());
40344019 VmwareHypervisorHost dsHost = hostInTargetCluster == null ? hyperHost : hostInTargetCluster ;
4035- ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , hyperHost );
4020+ ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , dsHost );
40364021 if (morTargetDS == null ) {
40374022 String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
40384023 s_logger .error (msg );
@@ -6291,30 +6276,23 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
62916276 VmwareHypervisorHost targetHyperHost = hostInTargetCluster ;
62926277 VirtualMachineMO vmMo = null ;
62936278 ManagedObjectReference morSourceHostDc = null ;
6294- ManagedObjectReference morTargetHostDc = null ;
6295- ManagedObjectReference morTargetHost = new ManagedObjectReference ();
62966279 VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec ();
62976280 List <VirtualMachineRelocateSpecDiskLocator > diskLocators = new ArrayList <VirtualMachineRelocateSpecDiskLocator >();
62986281 Set <String > mountedDatastoresAtSource = new HashSet <String >();
62996282 List <VolumeObjectTO > volumeToList = new ArrayList <>();
63006283 Map <Long , Integer > volumeDeviceKey = new HashMap <Long , Integer >();
6301- if (StringUtils .isNotBlank (targetHost )) {
6302- String targetHostMorInfo = targetHost .split ("@" )[0 ];
6303- morTargetHost .setType (targetHostMorInfo .split (":" )[0 ]);
6304- morTargetHost .setValue (targetHostMorInfo .split (":" )[1 ]);
6305- }
63066284
63076285 try {
63086286 if (sourceHyperHost == null ) {
63096287 sourceHyperHost = getHyperHost (getServiceContext ());
63106288 }
63116289 if (targetHyperHost == null && StringUtils .isNotBlank (targetHost )) {
6312- targetHyperHost = new HostMO (getServiceContext (), morTargetHost );
6290+ targetHyperHost = VmwareHelper . getHostMOFromHostName (getServiceContext (), targetHost );
63136291 }
63146292 morSourceHostDc = sourceHyperHost .getHyperHostDatacenter ();
63156293 DatacenterMO dcMo = new DatacenterMO (sourceHyperHost .getContext (), morSourceHostDc );
63166294 if (targetHyperHost != null ) {
6317- morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
6295+ ManagedObjectReference morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
63186296 if (!morSourceHostDc .getValue ().equalsIgnoreCase (morTargetHostDc .getValue ())) {
63196297 String msg = "VM " + vmName + " cannot be migrated between different datacenter" ;
63206298 throw new CloudRuntimeException (msg );
@@ -6405,12 +6383,12 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
64056383 }
64066384
64076385 // Specific section for MigrateVmWithStorageCommand
6408- if (vmTo != null ) {
6386+ if (vmTo != null && targetHyperHost != null ) {
64096387 // Prepare network at target before migration
64106388 NicTO [] nics = vmTo .getNics ();
64116389 for (NicTO nic : nics ) {
64126390 // prepare network on the host
6413- prepareNetworkFromNicInfo (new HostMO ( getServiceContext (), morTargetHost ) , nic , false , vmTo .getType ());
6391+ prepareNetworkFromNicInfo (( HostMO ) targetHyperHost , nic , false , vmTo .getType ());
64146392 }
64156393 // Ensure secondary storage mounted on target host
64166394 VmwareManager mgr = targetHyperHost .getContext ().getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
0 commit comments