@@ -1614,7 +1614,7 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16141614
16151615 temporaryConvertLocation = selectInstanceConversionTemporaryLocation (
16161616 destinationCluster , convertHost , convertStoragePoolId );
1617- List <StoragePoolVO > convertStoragePools = findInstanceConversionStoragePoolsInCluster (destinationCluster );
1617+ List <StoragePoolVO > convertStoragePools = findInstanceConversionStoragePoolsInCluster (destinationCluster , dataDiskOfferingMap );
16181618 long importStartTime = System .currentTimeMillis ();
16191619 Pair <UnmanagedInstanceTO , Boolean > sourceInstanceDetails = getSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password , clusterName , sourceHostName , sourceVMName );
16201620 sourceVMwareInstance = sourceInstanceDetails .first ();
@@ -1633,13 +1633,14 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
16331633 ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password ,
16341634 clusterName , sourceHostName , sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
16351635 convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation (sourceVMName ,
1636- sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1637- temporaryConvertLocation , ovfTemplateOnConvertLocation );
1636+ sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1637+ dataDiskOfferingMap , temporaryConvertLocation , ovfTemplateOnConvertLocation );
16381638 } else {
16391639 // Uses KVM Host for OVF export to temporary conversion location, through ovftool
16401640 convertedInstance = convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1641- sourceVMName , sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1642- temporaryConvertLocation , vcenter , username , password , datacenterName );
1641+ sourceVMName , sourceVMwareInstance , convertHost , importHost ,
1642+ convertStoragePools , dataDiskOfferingMap , temporaryConvertLocation , vcenter ,
1643+ username , password , datacenterName );
16431644 }
16441645
16451646 sanitizeConvertedInstance (convertedInstance , sourceVMwareInstance );
@@ -1916,14 +1917,14 @@ private CheckConvertInstanceAnswer checkConversionSupportOnHost(HostVO convertHo
19161917 private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation (
19171918 String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
19181919 HostVO convertHost , HostVO importHost ,
1919- List <StoragePoolVO > convertStoragePools , DataStoreTO temporaryConvertLocation ,
1920+ List <StoragePoolVO > convertStoragePools , Map < String , Long > dataDiskOfferingMap , DataStoreTO temporaryConvertLocation ,
19201921 String ovfTemplateDirConvertLocation
19211922 ) {
19221923 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" ,
19231924 sourceVM , convertHost .getId (), convertHost .getName (), ovfTemplateDirConvertLocation ));
19241925
19251926 RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO (sourceVM );
1926- List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks ());
1927+ List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), dataDiskOfferingMap );
19271928 ConvertInstanceCommand cmd = new ConvertInstanceCommand (remoteInstanceTO ,
19281929 Hypervisor .HypervisorType .KVM , temporaryConvertLocation , ovfTemplateDirConvertLocation , false , false );
19291930 int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
@@ -1936,14 +1937,14 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation(
19361937 private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
19371938 String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
19381939 HostVO convertHost , HostVO importHost , List <StoragePoolVO > convertStoragePools ,
1939- DataStoreTO temporaryConvertLocation , String vcenterHost ,
1940+ Map < String , Long > dataDiskOfferingMap , DataStoreTO temporaryConvertLocation , String vcenterHost ,
19401941 String vcenterUsername , String vcenterPassword , String datacenterName
19411942 ) {
19421943 LOGGER .debug (String .format ("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) after OVF export through ovftool" ,
19431944 sourceVM , convertHost .getId (), convertHost .getName ()));
19441945
19451946 RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO (sourceVMwareInstance .getName (), vcenterHost , vcenterUsername , vcenterPassword , datacenterName );
1946- List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks ());
1947+ List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), dataDiskOfferingMap );
19471948 ConvertInstanceCommand cmd = new ConvertInstanceCommand (remoteInstanceTO ,
19481949 Hypervisor .HypervisorType .KVM , temporaryConvertLocation , null , false , true );
19491950 int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
@@ -2006,12 +2007,46 @@ private UnmanagedInstanceTO convertAndImportToKVM(ConvertInstanceCommand convert
20062007 return ((ImportConvertedInstanceAnswer ) importAnswer ).getConvertedInstance ();
20072008 }
20082009
2009- private List <StoragePoolVO > findInstanceConversionStoragePoolsInCluster (Cluster destinationCluster ) {
2010+ private List <StoragePoolVO > findInstanceConversionStoragePoolsInCluster (Cluster destinationCluster , Map < String , Long > dataDiskOfferingMap ) {
20102011 List <StoragePoolVO > pools = new ArrayList <>();
20112012 List <StoragePoolVO > clusterPools = primaryDataStoreDao .findClusterWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem );
2012- pools .addAll (clusterPools );
20132013 List <StoragePoolVO > zonePools = primaryDataStoreDao .findZoneWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getDataCenterId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem );
2014- pools .addAll (zonePools );
2014+ List <String > diskOfferingTags = new ArrayList <>();
2015+ for (Long diskOfferingId : dataDiskOfferingMap .values ()) {
2016+ DiskOfferingVO diskOffering = diskOfferingDao .findById (diskOfferingId );
2017+ if (diskOffering == null ) {
2018+ String msg = String .format ("Cannot find disk offering with ID %s" , diskOfferingId );
2019+ LOGGER .error (msg );
2020+ throw new CloudRuntimeException (msg );
2021+ }
2022+ diskOfferingTags .add (diskOffering .getTags ());
2023+ }
2024+ if (dataDiskOfferingMap .isEmpty ()) {
2025+ pools .addAll (clusterPools );
2026+ pools .addAll (zonePools );
2027+ } else {
2028+ for (String tags : diskOfferingTags ) {
2029+ boolean tagsMatched = false ;
2030+ for (StoragePoolVO pool : clusterPools ) {
2031+ if (volumeApiService .doesTargetStorageSupportDiskOffering (pool , tags )) {
2032+ pools .add (pool );
2033+ tagsMatched = true ;
2034+ }
2035+ }
2036+ for (StoragePoolVO pool : zonePools ) {
2037+ if (volumeApiService .doesTargetStorageSupportDiskOffering (pool , tags )) {
2038+ pools .add (pool );
2039+ tagsMatched = true ;
2040+ }
2041+ }
2042+ if (!tagsMatched ) {
2043+ String msg = String .format ("Cannot find suitable storage pools in cluster %s for the conversion with disk offering tags %s" ,
2044+ destinationCluster , tags );
2045+ LOGGER .error (msg );
2046+ throw new CloudRuntimeException (msg );
2047+ }
2048+ }
2049+ }
20152050 if (pools .isEmpty ()) {
20162051 String msg = String .format ("Cannot find suitable storage pools in cluster %s for the conversion" , destinationCluster .getName ());
20172052 LOGGER .error (msg );
@@ -2020,12 +2055,22 @@ private List<StoragePoolVO> findInstanceConversionStoragePoolsInCluster(Cluster
20202055 return pools ;
20212056 }
20222057
2023- private List <String > selectInstanceConversionStoragePools (List <StoragePoolVO > pools , List <UnmanagedInstanceTO .Disk > disks ) {
2058+ private List <String > selectInstanceConversionStoragePools (List <StoragePoolVO > pools , List <UnmanagedInstanceTO .Disk > disks , Map < String , Long > dataDiskOfferingMap ) {
20242059 List <String > storagePools = new ArrayList <>(disks .size ());
20252060 //TODO: Choose pools by capacity
20262061 for (UnmanagedInstanceTO .Disk disk : disks ) {
2027- Long capacity = disk .getCapacity ();
2028- storagePools .add (pools .get (0 ).getUuid ());
2062+ Long diskOfferingId = dataDiskOfferingMap .get (disk .getDiskId ());
2063+ if (diskOfferingId == null ) {
2064+ storagePools .add (pools .get (0 ).getUuid ());
2065+ } else {
2066+ DiskOfferingVO diskOffering = diskOfferingDao .findById (diskOfferingId );
2067+ for (StoragePoolVO pool : pools ) {
2068+ if (volumeApiService .doesTargetStorageSupportDiskOffering (pool , diskOffering .getTags ())) {
2069+ storagePools .add (pool .getUuid ());
2070+ break ;
2071+ }
2072+ }
2073+ }
20292074 }
20302075 return storagePools ;
20312076 }
0 commit comments