2323import com .cloud .agent .api .CheckConvertInstanceCommand ;
2424import com .cloud .agent .api .CheckVolumeAnswer ;
2525import com .cloud .agent .api .CheckVolumeCommand ;
26- import com .cloud .agent .api .ConvertInstanceAnswer ;
2726import com .cloud .agent .api .ConvertInstanceCommand ;
2827import com .cloud .agent .api .CopyRemoteVolumeAnswer ;
2928import com .cloud .agent .api .CopyRemoteVolumeCommand ;
@@ -1600,6 +1599,7 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16001599 String ovfTemplateOnConvertLocation = null ;
16011600 try {
16021601 HostVO convertHost = selectInstanceConversionKVMHostInCluster (destinationCluster , convertInstanceHostId );
1602+ HostVO destinationHost = convertInstanceHostId == null ? convertHost : selectInstanceConversionKVMHostInCluster (destinationCluster , null );
16031603 CheckConvertInstanceAnswer conversionSupportAnswer = checkConversionSupportOnHost (convertHost , sourceVMName , false );
16041604 LOGGER .debug (String .format ("The host %s (%s) is selected to execute the conversion of the instance %s" +
16051605 " from VMware to KVM " , convertHost .getId (), convertHost .getName (), sourceVMName ));
@@ -1623,11 +1623,13 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16231623 int noOfThreads = UnmanagedVMsManager .ThreadsOnMSToImportVMwareVMFiles .value ();
16241624 ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password ,
16251625 clusterName , sourceHostName , sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
1626- convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation (sourceVMName , sourceVMwareInstance , convertHost , convertStoragePools ,
1626+ convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation (sourceVMName ,
1627+ sourceVMwareInstance , convertHost , destinationHost , convertStoragePools ,
16271628 temporaryConvertLocation , ovfTemplateOnConvertLocation );
16281629 } else {
16291630 // Uses KVM Host for OVF export to temporary conversion location, through ovftool
1630- convertedInstance = convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (sourceVMName , sourceVMwareInstance , convertHost , convertStoragePools ,
1631+ convertedInstance = convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1632+ sourceVMName , sourceVMwareInstance , convertHost , destinationHost , convertStoragePools ,
16311633 temporaryConvertLocation , vcenter , username , password , datacenterName );
16321634 }
16331635
@@ -1844,9 +1846,12 @@ private CheckConvertInstanceAnswer checkConversionSupportOnHost(HostVO convertHo
18441846 return checkConvertInstanceAnswer ;
18451847 }
18461848
1847- private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation (String sourceVM , UnmanagedInstanceTO sourceVMwareInstance , HostVO convertHost ,
1848- List <StoragePoolVO > convertStoragePools , DataStoreTO temporaryConvertLocation ,
1849- String ovfTemplateDirConvertLocation ) {
1849+ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation (
1850+ String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1851+ HostVO convertHost , HostVO destinationHost ,
1852+ List <StoragePoolVO > convertStoragePools , DataStoreTO temporaryConvertLocation ,
1853+ String ovfTemplateDirConvertLocation
1854+ ) {
18501855 LOGGER .debug (String .format ("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) using OVF %s on conversion datastore" ,
18511856 sourceVM , convertHost .getId (), convertHost .getName (), ovfTemplateDirConvertLocation ));
18521857
@@ -1877,21 +1882,24 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation(S
18771882 try {
18781883 ImportConvertedInstanceCommand importCmd = new ImportConvertedInstanceCommand (remoteInstanceTO ,
18791884 destinationStoragePools , temporaryConvertLocation );
1880- importAnswer = agentManager .send (convertHost .getId (), importCmd );
1885+ importAnswer = agentManager .send (destinationHost .getId (), importCmd );
18811886 } catch (AgentUnavailableException | OperationTimedoutException e ) {
18821887 String err = String .format (
1883- "Could not import the converted instance command to host %d (%s) due to: %s" ,
1884- convertHost .getId (), convertHost .getName (), e .getMessage ());
1888+ "Could not send the import converted instance command to host %d (%s) due to: %s" ,
1889+ destinationHost .getId (), destinationHost .getName (), e .getMessage ());
18851890 LOGGER .error (err , e );
18861891 throw new CloudRuntimeException (err );
18871892 }
18881893
18891894 return ((ImportConvertedInstanceAnswer ) importAnswer ).getConvertedInstance ();
18901895 }
18911896
1892- private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (String sourceVM , UnmanagedInstanceTO sourceVMwareInstance , HostVO convertHost ,
1893- List <StoragePoolVO > convertStoragePools , DataStoreTO temporaryConvertLocation ,
1894- String vcenterHost , String vcenterUsername , String vcenterPassword , String datacenterName ) {
1897+ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1898+ String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1899+ HostVO convertHost , HostVO destinationHost , List <StoragePoolVO > convertStoragePools ,
1900+ DataStoreTO temporaryConvertLocation , String vcenterHost ,
1901+ String vcenterUsername , String vcenterPassword , String datacenterName
1902+ ) {
18951903 LOGGER .debug (String .format ("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) after OVF export through ovftool" ,
18961904 sourceVM , convertHost .getId (), convertHost .getName ()));
18971905
@@ -1924,7 +1932,20 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
19241932 LOGGER .error (err );
19251933 throw new CloudRuntimeException (err );
19261934 }
1927- return ((ConvertInstanceAnswer ) convertAnswer ).getConvertedInstance ();
1935+
1936+ Answer importAnswer ;
1937+ try {
1938+ ImportConvertedInstanceCommand importCmd = new ImportConvertedInstanceCommand (remoteInstanceTO ,
1939+ destinationStoragePools , temporaryConvertLocation );
1940+ importAnswer = agentManager .send (destinationHost .getId (), importCmd );
1941+ } catch (AgentUnavailableException | OperationTimedoutException e ) {
1942+ String err = String .format (
1943+ "Could not send the import converted instance command to host %d (%s) due to: %s" ,
1944+ destinationHost .getId (), destinationHost .getName (), e .getMessage ());
1945+ LOGGER .error (err , e );
1946+ throw new CloudRuntimeException (err );
1947+ }
1948+ return ((ImportConvertedInstanceAnswer ) importAnswer ).getConvertedInstance ();
19281949 }
19291950
19301951 private List <StoragePoolVO > findInstanceConversionStoragePoolsInCluster (Cluster destinationCluster ) {
0 commit comments