@@ -3387,7 +3387,6 @@ protected Answer execute(MigrateVmToPoolCommand cmd) {
3387
3387
3388
3388
private Answer migrateAndAnswer (VirtualMachineMO vmMo , String poolUuid , VmwareHypervisorHost hyperHost , Command cmd ) throws Exception {
3389
3389
String hostNameInTargetCluster = null ;
3390
- VmwareHypervisorHost hostInTargetCluster = null ;
3391
3390
List <Pair <VolumeTO , StorageFilerTO >> volToFiler = new ArrayList <>();
3392
3391
if (cmd instanceof MigrateVmToPoolCommand ) {
3393
3392
MigrateVmToPoolCommand mcmd = (MigrateVmToPoolCommand )cmd ;
@@ -3396,13 +3395,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
3396
3395
} else if (cmd instanceof MigrateVolumeCommand ) {
3397
3396
hostNameInTargetCluster = ((MigrateVolumeCommand )cmd ).getHostGuidInTargetCluster ();
3398
3397
}
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 );
3406
3399
try {
3407
3400
// OfflineVmwareMigration: getVolumesFromCommand(cmd);
3408
3401
Map <Integer , Long > volumeDeviceKey = new HashMap <>();
@@ -3581,19 +3574,11 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
3581
3574
3582
3575
ManagedObjectReference morSourceDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , cmd .getSourcePool ().getUuid ());
3583
3576
DatastoreMO sourceDsMo = new DatastoreMO (hyperHost .getContext (), morSourceDs );
3584
- DatacenterMO dcMo = new DatacenterMO (hyperHost .getContext (), hyperHost .getHyperHostDatacenter ());
3585
3577
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 ());
3595
3580
VmwareHypervisorHost dsHost = hostInTargetCluster == null ? hyperHost : hostInTargetCluster ;
3596
- ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , hyperHost );
3581
+ ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , dsHost );
3597
3582
if (morTargetDS == null ) {
3598
3583
String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
3599
3584
s_logger .error (msg );
@@ -5731,30 +5716,23 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
5731
5716
VmwareHypervisorHost targetHyperHost = hostInTargetCluster ;
5732
5717
VirtualMachineMO vmMo = null ;
5733
5718
ManagedObjectReference morSourceHostDc = null ;
5734
- ManagedObjectReference morTargetHostDc = null ;
5735
- ManagedObjectReference morTargetHost = new ManagedObjectReference ();
5736
5719
VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec ();
5737
5720
List <VirtualMachineRelocateSpecDiskLocator > diskLocators = new ArrayList <VirtualMachineRelocateSpecDiskLocator >();
5738
5721
Set <String > mountedDatastoresAtSource = new HashSet <String >();
5739
5722
List <VolumeObjectTO > volumeToList = new ArrayList <>();
5740
5723
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
- }
5746
5724
5747
5725
try {
5748
5726
if (sourceHyperHost == null ) {
5749
5727
sourceHyperHost = getHyperHost (getServiceContext ());
5750
5728
}
5751
5729
if (targetHyperHost == null && StringUtils .isNotBlank (targetHost )) {
5752
- targetHyperHost = new HostMO (getServiceContext (), morTargetHost );
5730
+ targetHyperHost = VmwareHelper . getHostMOFromHostName (getServiceContext (), targetHost );
5753
5731
}
5754
5732
morSourceHostDc = sourceHyperHost .getHyperHostDatacenter ();
5755
5733
DatacenterMO dcMo = new DatacenterMO (sourceHyperHost .getContext (), morSourceHostDc );
5756
5734
if (targetHyperHost != null ) {
5757
- morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
5735
+ ManagedObjectReference morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
5758
5736
if (!morSourceHostDc .getValue ().equalsIgnoreCase (morTargetHostDc .getValue ())) {
5759
5737
String msg = "VM " + vmName + " cannot be migrated between different datacenter" ;
5760
5738
throw new CloudRuntimeException (msg );
@@ -5845,12 +5823,12 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
5845
5823
}
5846
5824
5847
5825
// Specific section for MigrateVmWithStorageCommand
5848
- if (vmTo != null ) {
5826
+ if (vmTo != null && targetHyperHost != null ) {
5849
5827
// Prepare network at target before migration
5850
5828
NicTO [] nics = vmTo .getNics ();
5851
5829
for (NicTO nic : nics ) {
5852
5830
// prepare network on the host
5853
- prepareNetworkFromNicInfo (new HostMO ( getServiceContext (), morTargetHost ) , nic , false , vmTo .getType ());
5831
+ prepareNetworkFromNicInfo (( HostMO ) targetHyperHost , nic , false , vmTo .getType ());
5854
5832
}
5855
5833
// Ensure secondary storage mounted on target host
5856
5834
VmwareManager mgr = targetHyperHost .getContext ().getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
0 commit comments