@@ -3826,7 +3826,6 @@ protected Answer execute(MigrateVmToPoolCommand cmd) {
3826
3826
3827
3827
private Answer migrateAndAnswer (VirtualMachineMO vmMo , String poolUuid , VmwareHypervisorHost hyperHost , Command cmd ) throws Exception {
3828
3828
String hostNameInTargetCluster = null ;
3829
- VmwareHypervisorHost hostInTargetCluster = null ;
3830
3829
List <Pair <VolumeTO , StorageFilerTO >> volToFiler = new ArrayList <>();
3831
3830
if (cmd instanceof MigrateVmToPoolCommand ) {
3832
3831
MigrateVmToPoolCommand mcmd = (MigrateVmToPoolCommand )cmd ;
@@ -3835,13 +3834,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
3835
3834
} else if (cmd instanceof MigrateVolumeCommand ) {
3836
3835
hostNameInTargetCluster = ((MigrateVolumeCommand )cmd ).getHostGuidInTargetCluster ();
3837
3836
}
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 );
3845
3838
try {
3846
3839
// OfflineVmwareMigration: getVolumesFromCommand(cmd);
3847
3840
Map <Integer , Long > volumeDeviceKey = new HashMap <>();
@@ -4020,19 +4013,11 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
4020
4013
4021
4014
ManagedObjectReference morSourceDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , cmd .getSourcePool ().getUuid ());
4022
4015
DatastoreMO sourceDsMo = new DatastoreMO (hyperHost .getContext (), morSourceDs );
4023
- DatacenterMO dcMo = new DatacenterMO (hyperHost .getContext (), hyperHost .getHyperHostDatacenter ());
4024
4016
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 ());
4034
4019
VmwareHypervisorHost dsHost = hostInTargetCluster == null ? hyperHost : hostInTargetCluster ;
4035
- ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , hyperHost );
4020
+ ManagedObjectReference morTargetDS = getTargetDatastoreMOReference (targetDsName , dsHost );
4036
4021
if (morTargetDS == null ) {
4037
4022
String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
4038
4023
s_logger .error (msg );
@@ -6291,30 +6276,23 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
6291
6276
VmwareHypervisorHost targetHyperHost = hostInTargetCluster ;
6292
6277
VirtualMachineMO vmMo = null ;
6293
6278
ManagedObjectReference morSourceHostDc = null ;
6294
- ManagedObjectReference morTargetHostDc = null ;
6295
- ManagedObjectReference morTargetHost = new ManagedObjectReference ();
6296
6279
VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec ();
6297
6280
List <VirtualMachineRelocateSpecDiskLocator > diskLocators = new ArrayList <VirtualMachineRelocateSpecDiskLocator >();
6298
6281
Set <String > mountedDatastoresAtSource = new HashSet <String >();
6299
6282
List <VolumeObjectTO > volumeToList = new ArrayList <>();
6300
6283
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
- }
6306
6284
6307
6285
try {
6308
6286
if (sourceHyperHost == null ) {
6309
6287
sourceHyperHost = getHyperHost (getServiceContext ());
6310
6288
}
6311
6289
if (targetHyperHost == null && StringUtils .isNotBlank (targetHost )) {
6312
- targetHyperHost = new HostMO (getServiceContext (), morTargetHost );
6290
+ targetHyperHost = VmwareHelper . getHostMOFromHostName (getServiceContext (), targetHost );
6313
6291
}
6314
6292
morSourceHostDc = sourceHyperHost .getHyperHostDatacenter ();
6315
6293
DatacenterMO dcMo = new DatacenterMO (sourceHyperHost .getContext (), morSourceHostDc );
6316
6294
if (targetHyperHost != null ) {
6317
- morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
6295
+ ManagedObjectReference morTargetHostDc = targetHyperHost .getHyperHostDatacenter ();
6318
6296
if (!morSourceHostDc .getValue ().equalsIgnoreCase (morTargetHostDc .getValue ())) {
6319
6297
String msg = "VM " + vmName + " cannot be migrated between different datacenter" ;
6320
6298
throw new CloudRuntimeException (msg );
@@ -6405,12 +6383,12 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
6405
6383
}
6406
6384
6407
6385
// Specific section for MigrateVmWithStorageCommand
6408
- if (vmTo != null ) {
6386
+ if (vmTo != null && targetHyperHost != null ) {
6409
6387
// Prepare network at target before migration
6410
6388
NicTO [] nics = vmTo .getNics ();
6411
6389
for (NicTO nic : nics ) {
6412
6390
// prepare network on the host
6413
- prepareNetworkFromNicInfo (new HostMO ( getServiceContext (), morTargetHost ) , nic , false , vmTo .getType ());
6391
+ prepareNetworkFromNicInfo (( HostMO ) targetHyperHost , nic , false , vmTo .getType ());
6414
6392
}
6415
6393
// Ensure secondary storage mounted on target host
6416
6394
VmwareManager mgr = targetHyperHost .getContext ().getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
0 commit comments