@@ -1600,7 +1600,7 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16001600 String ovfTemplateOnConvertLocation = null ;
16011601 try {
16021602 HostVO convertHost = selectInstanceConversionKVMHostInCluster (destinationCluster , convertInstanceHostId );
1603- HostVO destinationHost = convertInstanceHostId == null ? convertHost : selectInstanceConversionKVMHostInCluster (destinationCluster , null );
1603+ HostVO importHost = convertInstanceHostId == null ? convertHost : selectInstanceConversionKVMHostInCluster (destinationCluster , null );
16041604 CheckConvertInstanceAnswer conversionSupportAnswer = checkConversionSupportOnHost (convertHost , sourceVMName , false );
16051605 LOGGER .debug (String .format ("The host %s (%s) is selected to execute the conversion of the instance %s" +
16061606 " from VMware to KVM " , convertHost .getId (), convertHost .getName (), sourceVMName ));
@@ -1625,12 +1625,12 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16251625 ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password ,
16261626 clusterName , sourceHostName , sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
16271627 convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation (sourceVMName ,
1628- sourceVMwareInstance , convertHost , destinationHost , convertStoragePools ,
1628+ sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
16291629 temporaryConvertLocation , ovfTemplateOnConvertLocation );
16301630 } else {
16311631 // Uses KVM Host for OVF export to temporary conversion location, through ovftool
16321632 convertedInstance = convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1633- sourceVMName , sourceVMwareInstance , convertHost , destinationHost , convertStoragePools ,
1633+ sourceVMName , sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
16341634 temporaryConvertLocation , vcenter , username , password , datacenterName );
16351635 }
16361636
@@ -1849,7 +1849,7 @@ private CheckConvertInstanceAnswer checkConversionSupportOnHost(HostVO convertHo
18491849
18501850 private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation (
18511851 String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1852- HostVO convertHost , HostVO destinationHost ,
1852+ HostVO convertHost , HostVO importHost ,
18531853 List <StoragePoolVO > convertStoragePools , DataStoreTO temporaryConvertLocation ,
18541854 String ovfTemplateDirConvertLocation
18551855 ) {
@@ -1863,50 +1863,13 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation(
18631863 int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
18641864 cmd .setWait (timeoutSeconds );
18651865
1866- Answer convertAnswer ;
1867- try {
1868- convertAnswer = agentManager .send (convertHost .getId (), cmd );
1869- } catch (AgentUnavailableException | OperationTimedoutException e ) {
1870- String err = String .format ("Could not send the convert instance command to host %s (%s) due to: %s" ,
1871- convertHost .getId (), convertHost .getName (), e .getMessage ());
1872- LOGGER .error (err , e );
1873- throw new CloudRuntimeException (err );
1874- }
1875-
1876- if (!convertAnswer .getResult ()) {
1877- String err = String .format ("The convert process failed for instance %s from VMware to KVM on host %s: %s" ,
1878- sourceVM , convertHost .getName (), convertAnswer .getDetails ());
1879- LOGGER .error (err );
1880- throw new CloudRuntimeException (err );
1881- }
1882- Answer importAnswer ;
1883- try {
1884- ImportConvertedInstanceCommand importCmd = new ImportConvertedInstanceCommand (
1885- remoteInstanceTO , destinationStoragePools , temporaryConvertLocation ,
1886- ((ConvertInstanceAnswer )convertAnswer ).getTemporaryConvertUuid ());
1887- importAnswer = agentManager .send (destinationHost .getId (), importCmd );
1888- } catch (AgentUnavailableException | OperationTimedoutException e ) {
1889- String err = String .format (
1890- "Could not send the import converted instance command to host %d (%s) due to: %s" ,
1891- destinationHost .getId (), destinationHost .getName (), e .getMessage ());
1892- LOGGER .error (err , e );
1893- throw new CloudRuntimeException (err );
1894- }
1895-
1896- if (!importAnswer .getResult ()) {
1897- String err = String .format (
1898- "The import process failed for instance %s from VMware to KVM on host %s: %s" ,
1899- sourceVM , destinationHost .getName (), importAnswer .getDetails ());
1900- LOGGER .error (err );
1901- throw new CloudRuntimeException (err );
1902- }
1903-
1904- return ((ImportConvertedInstanceAnswer ) importAnswer ).getConvertedInstance ();
1866+ return convertAndImportToKVM (cmd , convertHost , importHost , sourceVM ,
1867+ remoteInstanceTO , destinationStoragePools , temporaryConvertLocation );
19051868 }
19061869
19071870 private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
19081871 String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1909- HostVO convertHost , HostVO destinationHost , List <StoragePoolVO > convertStoragePools ,
1872+ HostVO convertHost , HostVO importHost , List <StoragePoolVO > convertStoragePools ,
19101873 DataStoreTO temporaryConvertLocation , String vcenterHost ,
19111874 String vcenterUsername , String vcenterPassword , String datacenterName
19121875 ) {
@@ -1926,9 +1889,18 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
19261889 }
19271890 cmd .setThreadsCountToExportOvf (noOfThreads );
19281891
1892+ return convertAndImportToKVM (cmd , convertHost , importHost , sourceVM ,
1893+ remoteInstanceTO , destinationStoragePools , temporaryConvertLocation );
1894+ }
1895+
1896+ private UnmanagedInstanceTO convertAndImportToKVM (ConvertInstanceCommand convertInstanceCommand , HostVO convertHost , HostVO importHost ,
1897+ String sourceVM ,
1898+ RemoteInstanceTO remoteInstanceTO ,
1899+ List <String > destinationStoragePools ,
1900+ DataStoreTO temporaryConvertLocation ) {
19291901 Answer convertAnswer ;
19301902 try {
1931- convertAnswer = agentManager .send (convertHost .getId (), cmd );
1903+ convertAnswer = agentManager .send (convertHost .getId (), convertInstanceCommand );
19321904 } catch (AgentUnavailableException | OperationTimedoutException e ) {
19331905 String err = String .format ("Could not send the convert instance command to host %s (%s) due to: %s" ,
19341906 convertHost .getId (), convertHost .getName (), e .getMessage ());
@@ -1948,19 +1920,19 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
19481920 ImportConvertedInstanceCommand importCmd = new ImportConvertedInstanceCommand (
19491921 remoteInstanceTO , destinationStoragePools , temporaryConvertLocation ,
19501922 ((ConvertInstanceAnswer )convertAnswer ).getTemporaryConvertUuid ());
1951- importAnswer = agentManager .send (destinationHost .getId (), importCmd );
1923+ importAnswer = agentManager .send (importHost .getId (), importCmd );
19521924 } catch (AgentUnavailableException | OperationTimedoutException e ) {
19531925 String err = String .format (
19541926 "Could not send the import converted instance command to host %d (%s) due to: %s" ,
1955- destinationHost .getId (), destinationHost .getName (), e .getMessage ());
1927+ importHost .getId (), importHost .getName (), e .getMessage ());
19561928 LOGGER .error (err , e );
19571929 throw new CloudRuntimeException (err );
19581930 }
19591931
19601932 if (!importAnswer .getResult ()) {
19611933 String err = String .format (
19621934 "The import process failed for instance %s from VMware to KVM on host %s: %s" ,
1963- sourceVM , destinationHost .getName (), importAnswer .getDetails ());
1935+ sourceVM , importHost .getName (), importAnswer .getDetails ());
19641936 LOGGER .error (err );
19651937 throw new CloudRuntimeException (err );
19661938 }
0 commit comments