@@ -623,6 +623,7 @@ private void checkUnmanagedDiskAndOfferingForImport(String instanceName, Unmanag
623
623
if (diskOffering != null && !diskOffering .isCustomized () && diskOffering .getDiskSize () < disk .getCapacity ()) {
624
624
throw new ServerApiException (ApiErrorCode .INTERNAL_ERROR , String .format ("Size of disk offering(ID: %s) %dGB is found less than the size of disk(ID: %s) %dGB during VM import" , diskOffering .getUuid (), (diskOffering .getDiskSize () / Resource .ResourceType .bytesToGiB ), disk .getDiskId (), (disk .getCapacity () / (Resource .ResourceType .bytesToGiB ))));
625
625
}
626
+ diskOffering = diskOffering != null ? diskOffering : diskOfferingDao .findById (serviceOffering .getDiskOfferingId ());
626
627
StoragePool storagePool = getStoragePool (disk , zone , cluster , diskOffering != null ? diskOffering .getTags () : null );
627
628
if (diskOffering != null && !migrateAllowed && !storagePoolSupportsDiskOffering (storagePool , diskOffering )) {
628
629
throw new InvalidParameterValueException (String .format ("Disk offering: %s is not compatible with storage pool: %s of unmanaged disk: %s" , diskOffering .getUuid (), storagePool .getUuid (), disk .getDiskId ()));
@@ -1614,7 +1615,7 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
1614
1615
1615
1616
temporaryConvertLocation = selectInstanceConversionTemporaryLocation (
1616
1617
destinationCluster , convertHost , convertStoragePoolId );
1617
- List <StoragePoolVO > convertStoragePools = findInstanceConversionStoragePoolsInCluster (destinationCluster , dataDiskOfferingMap );
1618
+ List <StoragePoolVO > convertStoragePools = findInstanceConversionStoragePoolsInCluster (destinationCluster , serviceOffering , dataDiskOfferingMap );
1618
1619
long importStartTime = System .currentTimeMillis ();
1619
1620
Pair <UnmanagedInstanceTO , Boolean > sourceInstanceDetails = getSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password , clusterName , sourceHostName , sourceVMName );
1620
1621
sourceVMwareInstance = sourceInstanceDetails .first ();
@@ -1630,17 +1631,19 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
1630
1631
if (cmd .getForceMsToImportVmFiles () || !conversionSupportAnswer .isOvfExportSupported ()) {
1631
1632
// Uses MS for OVF export to temporary conversion location
1632
1633
int noOfThreads = UnmanagedVMsManager .ThreadsOnMSToImportVMwareVMFiles .value ();
1633
- ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password ,
1634
- clusterName , sourceHostName , sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
1634
+ ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (
1635
+ vcenter , datacenterName , username , password , clusterName , sourceHostName ,
1636
+ sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
1635
1637
convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation (sourceVMName ,
1636
1638
sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1637
- dataDiskOfferingMap , temporaryConvertLocation , ovfTemplateOnConvertLocation );
1639
+ serviceOffering , dataDiskOfferingMap , temporaryConvertLocation ,
1640
+ ovfTemplateOnConvertLocation );
1638
1641
} else {
1639
1642
// Uses KVM Host for OVF export to temporary conversion location, through ovftool
1640
1643
convertedInstance = convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1641
1644
sourceVMName , sourceVMwareInstance , convertHost , importHost ,
1642
- convertStoragePools , dataDiskOfferingMap , temporaryConvertLocation , vcenter ,
1643
- username , password , datacenterName );
1645
+ convertStoragePools , serviceOffering , dataDiskOfferingMap ,
1646
+ temporaryConvertLocation , vcenter , username , password , datacenterName );
1644
1647
}
1645
1648
1646
1649
sanitizeConvertedInstance (convertedInstance , sourceVMwareInstance );
@@ -1729,9 +1732,9 @@ private void sanitizeConvertedInstance(UnmanagedInstanceTO convertedInstance, Un
1729
1732
convertedInstance .setPowerState (UnmanagedInstanceTO .PowerState .PowerOff );
1730
1733
List <UnmanagedInstanceTO .Disk > convertedInstanceDisks = convertedInstance .getDisks ();
1731
1734
List <UnmanagedInstanceTO .Disk > sourceVMwareInstanceDisks = sourceVMwareInstance .getDisks ();
1732
- for (int i = 0 ; i < convertedInstanceDisks . size (); i ++ ) {
1733
- UnmanagedInstanceTO .Disk disk = convertedInstanceDisks .get (i );
1734
- disk .setDiskId (sourceVMwareInstanceDisks . get ( i ) .getDiskId ());
1735
+ for (UnmanagedInstanceTO . Disk sourceVMwareInstanceDisk : sourceVMwareInstanceDisks ) {
1736
+ UnmanagedInstanceTO .Disk convertedDisk = convertedInstanceDisks .get (sourceVMwareInstanceDisk . getPosition () );
1737
+ convertedDisk .setDiskId (sourceVMwareInstanceDisk .getDiskId ());
1735
1738
}
1736
1739
List <UnmanagedInstanceTO .Nic > convertedInstanceNics = convertedInstance .getNics ();
1737
1740
List <UnmanagedInstanceTO .Nic > sourceVMwareInstanceNics = sourceVMwareInstance .getNics ();
@@ -1915,16 +1918,16 @@ private CheckConvertInstanceAnswer checkConversionSupportOnHost(HostVO convertHo
1915
1918
}
1916
1919
1917
1920
private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation (
1918
- String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1919
- HostVO convertHost , HostVO importHost ,
1920
- List < StoragePoolVO > convertStoragePools , Map <String , Long > dataDiskOfferingMap , DataStoreTO temporaryConvertLocation ,
1921
- String ovfTemplateDirConvertLocation
1921
+ String sourceVM , UnmanagedInstanceTO sourceVMwareInstance , HostVO convertHost ,
1922
+ HostVO importHost , List < StoragePoolVO > convertStoragePools ,
1923
+ ServiceOfferingVO serviceOffering , Map <String , Long > dataDiskOfferingMap ,
1924
+ DataStoreTO temporaryConvertLocation , String ovfTemplateDirConvertLocation
1922
1925
) {
1923
1926
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" ,
1924
1927
sourceVM , convertHost .getId (), convertHost .getName (), ovfTemplateDirConvertLocation ));
1925
1928
1926
1929
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO (sourceVM );
1927
- List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), dataDiskOfferingMap );
1930
+ List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), serviceOffering , dataDiskOfferingMap );
1928
1931
ConvertInstanceCommand cmd = new ConvertInstanceCommand (remoteInstanceTO ,
1929
1932
Hypervisor .HypervisorType .KVM , temporaryConvertLocation , ovfTemplateDirConvertLocation , false , false );
1930
1933
int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
@@ -1935,16 +1938,17 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation(
1935
1938
}
1936
1939
1937
1940
private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1938
- String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1939
- HostVO convertHost , HostVO importHost , List <StoragePoolVO > convertStoragePools ,
1940
- Map <String , Long > dataDiskOfferingMap , DataStoreTO temporaryConvertLocation , String vcenterHost ,
1941
- String vcenterUsername , String vcenterPassword , String datacenterName
1941
+ String sourceVM , UnmanagedInstanceTO sourceVMwareInstance , HostVO convertHost ,
1942
+ HostVO importHost , List <StoragePoolVO > convertStoragePools ,
1943
+ ServiceOfferingVO serviceOffering , Map <String , Long > dataDiskOfferingMap ,
1944
+ DataStoreTO temporaryConvertLocation , String vcenterHost , String vcenterUsername ,
1945
+ String vcenterPassword , String datacenterName
1942
1946
) {
1943
1947
LOGGER .debug (String .format ("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) after OVF export through ovftool" ,
1944
1948
sourceVM , convertHost .getId (), convertHost .getName ()));
1945
1949
1946
1950
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO (sourceVMwareInstance .getName (), vcenterHost , vcenterUsername , vcenterPassword , datacenterName );
1947
- List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), dataDiskOfferingMap );
1951
+ List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), serviceOffering , dataDiskOfferingMap );
1948
1952
ConvertInstanceCommand cmd = new ConvertInstanceCommand (remoteInstanceTO ,
1949
1953
Hypervisor .HypervisorType .KVM , temporaryConvertLocation , null , false , true );
1950
1954
int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
@@ -2007,7 +2011,10 @@ private UnmanagedInstanceTO convertAndImportToKVM(ConvertInstanceCommand convert
2007
2011
return ((ImportConvertedInstanceAnswer ) importAnswer ).getConvertedInstance ();
2008
2012
}
2009
2013
2010
- private List <StoragePoolVO > findInstanceConversionStoragePoolsInCluster (Cluster destinationCluster , Map <String , Long > dataDiskOfferingMap ) {
2014
+ private List <StoragePoolVO > findInstanceConversionStoragePoolsInCluster (
2015
+ Cluster destinationCluster , ServiceOfferingVO serviceOffering ,
2016
+ Map <String , Long > dataDiskOfferingMap
2017
+ ) {
2011
2018
List <StoragePoolVO > pools = new ArrayList <>();
2012
2019
List <StoragePoolVO > clusterPools = primaryDataStoreDao .findClusterWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem );
2013
2020
List <StoragePoolVO > zonePools = primaryDataStoreDao .findZoneWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getDataCenterId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem );
@@ -2021,7 +2028,13 @@ private List<StoragePoolVO> findInstanceConversionStoragePoolsInCluster(Cluster
2021
2028
}
2022
2029
diskOfferingTags .add (diskOffering .getTags ());
2023
2030
}
2024
- if (dataDiskOfferingMap .isEmpty ()) {
2031
+ if (serviceOffering .getDiskOfferingId () != null ) {
2032
+ DiskOfferingVO diskOffering = diskOfferingDao .findById (serviceOffering .getDiskOfferingId ());
2033
+ if (diskOffering != null ) {
2034
+ diskOfferingTags .add (diskOffering .getTags ());
2035
+ }
2036
+ }
2037
+ if (diskOfferingTags .isEmpty ()) {
2025
2038
pools .addAll (clusterPools );
2026
2039
pools .addAll (zonePools );
2027
2040
} else {
@@ -2055,18 +2068,28 @@ private List<StoragePoolVO> findInstanceConversionStoragePoolsInCluster(Cluster
2055
2068
return pools ;
2056
2069
}
2057
2070
2058
- private List <String > selectInstanceConversionStoragePools (List <StoragePoolVO > pools , List <UnmanagedInstanceTO .Disk > disks , Map <String , Long > dataDiskOfferingMap ) {
2071
+ private List <String > selectInstanceConversionStoragePools (
2072
+ List <StoragePoolVO > pools , List <UnmanagedInstanceTO .Disk > disks ,
2073
+ ServiceOfferingVO serviceOffering , Map <String , Long > dataDiskOfferingMap
2074
+ ) {
2059
2075
List <String > storagePools = new ArrayList <>(disks .size ());
2060
- //TODO: Choose pools by capacity
2076
+ for (int i = 0 ; i < disks .size (); i ++) {
2077
+ storagePools .add (null );
2078
+ }
2079
+ Set <String > dataDiskIds = dataDiskOfferingMap .keySet ();
2061
2080
for (UnmanagedInstanceTO .Disk disk : disks ) {
2062
2081
Long diskOfferingId = dataDiskOfferingMap .get (disk .getDiskId ());
2082
+ if (diskOfferingId == null && !dataDiskIds .contains (disk .getDiskId ())) {
2083
+ diskOfferingId = serviceOffering .getDiskOfferingId ();
2084
+ }
2085
+ //TODO: Choose pools by capacity
2063
2086
if (diskOfferingId == null ) {
2064
- storagePools .add ( pools .get (0 ).getUuid ());
2087
+ storagePools .set ( disk . getPosition (), pools .get (0 ).getUuid ());
2065
2088
} else {
2066
2089
DiskOfferingVO diskOffering = diskOfferingDao .findById (diskOfferingId );
2067
2090
for (StoragePoolVO pool : pools ) {
2068
2091
if (volumeApiService .doesTargetStorageSupportDiskOffering (pool , diskOffering .getTags ())) {
2069
- storagePools .add ( pool .getUuid ());
2092
+ storagePools .set ( disk . getPosition (), pool .getUuid ());
2070
2093
break ;
2071
2094
}
2072
2095
}
0 commit comments