@@ -1600,7 +1600,7 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
1600
1600
String ovfTemplateOnConvertLocation = null ;
1601
1601
try {
1602
1602
HostVO convertHost = selectInstanceConversionKVMHostInCluster (destinationCluster , convertInstanceHostId );
1603
- HostVO destinationHost = convertInstanceHostId == null ? convertHost : selectInstanceConversionKVMHostInCluster (destinationCluster , null );
1603
+ HostVO importHost = convertInstanceHostId == null ? convertHost : selectInstanceConversionKVMHostInCluster (destinationCluster , null );
1604
1604
CheckConvertInstanceAnswer conversionSupportAnswer = checkConversionSupportOnHost (convertHost , sourceVMName , false );
1605
1605
LOGGER .debug (String .format ("The host %s (%s) is selected to execute the conversion of the instance %s" +
1606
1606
" from VMware to KVM " , convertHost .getId (), convertHost .getName (), sourceVMName ));
@@ -1625,12 +1625,12 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
1625
1625
ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password ,
1626
1626
clusterName , sourceHostName , sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
1627
1627
convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation (sourceVMName ,
1628
- sourceVMwareInstance , convertHost , destinationHost , convertStoragePools ,
1628
+ sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1629
1629
temporaryConvertLocation , ovfTemplateOnConvertLocation );
1630
1630
} else {
1631
1631
// Uses KVM Host for OVF export to temporary conversion location, through ovftool
1632
1632
convertedInstance = convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1633
- sourceVMName , sourceVMwareInstance , convertHost , destinationHost , convertStoragePools ,
1633
+ sourceVMName , sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1634
1634
temporaryConvertLocation , vcenter , username , password , datacenterName );
1635
1635
}
1636
1636
@@ -1849,7 +1849,7 @@ private CheckConvertInstanceAnswer checkConversionSupportOnHost(HostVO convertHo
1849
1849
1850
1850
private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation (
1851
1851
String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1852
- HostVO convertHost , HostVO destinationHost ,
1852
+ HostVO convertHost , HostVO importHost ,
1853
1853
List <StoragePoolVO > convertStoragePools , DataStoreTO temporaryConvertLocation ,
1854
1854
String ovfTemplateDirConvertLocation
1855
1855
) {
@@ -1863,50 +1863,13 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation(
1863
1863
int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
1864
1864
cmd .setWait (timeoutSeconds );
1865
1865
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 );
1905
1868
}
1906
1869
1907
1870
private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1908
1871
String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1909
- HostVO convertHost , HostVO destinationHost , List <StoragePoolVO > convertStoragePools ,
1872
+ HostVO convertHost , HostVO importHost , List <StoragePoolVO > convertStoragePools ,
1910
1873
DataStoreTO temporaryConvertLocation , String vcenterHost ,
1911
1874
String vcenterUsername , String vcenterPassword , String datacenterName
1912
1875
) {
@@ -1926,9 +1889,18 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
1926
1889
}
1927
1890
cmd .setThreadsCountToExportOvf (noOfThreads );
1928
1891
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 ) {
1929
1901
Answer convertAnswer ;
1930
1902
try {
1931
- convertAnswer = agentManager .send (convertHost .getId (), cmd );
1903
+ convertAnswer = agentManager .send (convertHost .getId (), convertInstanceCommand );
1932
1904
} catch (AgentUnavailableException | OperationTimedoutException e ) {
1933
1905
String err = String .format ("Could not send the convert instance command to host %s (%s) due to: %s" ,
1934
1906
convertHost .getId (), convertHost .getName (), e .getMessage ());
@@ -1948,19 +1920,19 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
1948
1920
ImportConvertedInstanceCommand importCmd = new ImportConvertedInstanceCommand (
1949
1921
remoteInstanceTO , destinationStoragePools , temporaryConvertLocation ,
1950
1922
((ConvertInstanceAnswer )convertAnswer ).getTemporaryConvertUuid ());
1951
- importAnswer = agentManager .send (destinationHost .getId (), importCmd );
1923
+ importAnswer = agentManager .send (importHost .getId (), importCmd );
1952
1924
} catch (AgentUnavailableException | OperationTimedoutException e ) {
1953
1925
String err = String .format (
1954
1926
"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 ());
1956
1928
LOGGER .error (err , e );
1957
1929
throw new CloudRuntimeException (err );
1958
1930
}
1959
1931
1960
1932
if (!importAnswer .getResult ()) {
1961
1933
String err = String .format (
1962
1934
"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 ());
1964
1936
LOGGER .error (err );
1965
1937
throw new CloudRuntimeException (err );
1966
1938
}
0 commit comments