@@ -538,7 +538,7 @@ private Map<String, Network.IpAddresses> getNicIpAddresses(final List<UnmanagedI
538
538
return nicIpAddresses ;
539
539
}
540
540
541
- private StoragePool getStoragePool (final UnmanagedInstanceTO .Disk disk , final DataCenter zone , final Cluster cluster ) {
541
+ private StoragePool getStoragePool (final UnmanagedInstanceTO .Disk disk , final DataCenter zone , final Cluster cluster , String diskOfferingTags ) {
542
542
StoragePool storagePool = null ;
543
543
final String dsHost = disk .getDatastoreHost ();
544
544
final String dsPath = disk .getDatastorePath ();
@@ -548,7 +548,8 @@ private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final Da
548
548
List <StoragePoolVO > pools = primaryDataStoreDao .listPoolByHostPath (dsHost , dsPath );
549
549
for (StoragePool pool : pools ) {
550
550
if (pool .getDataCenterId () == zone .getId () &&
551
- (pool .getClusterId () == null || pool .getClusterId ().equals (cluster .getId ()))) {
551
+ (pool .getClusterId () == null || pool .getClusterId ().equals (cluster .getId ())) &&
552
+ volumeApiService .doesTargetStorageSupportDiskOffering (pool , diskOfferingTags )) {
552
553
storagePool = pool ;
553
554
break ;
554
555
}
@@ -560,7 +561,8 @@ private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final Da
560
561
pools .addAll (primaryDataStoreDao .listByDataCenterId (zone .getId ()));
561
562
for (StoragePool pool : pools ) {
562
563
String searchPoolParam = StringUtils .isNotBlank (dsPath ) ? dsPath : dsName ;
563
- if (StringUtils .contains (pool .getPath (), searchPoolParam )) {
564
+ if (StringUtils .contains (pool .getPath (), searchPoolParam ) &&
565
+ volumeApiService .doesTargetStorageSupportDiskOffering (pool , diskOfferingTags )) {
564
566
storagePool = pool ;
565
567
break ;
566
568
}
@@ -623,7 +625,8 @@ private void checkUnmanagedDiskAndOfferingForImport(String instanceName, Unmanag
623
625
if (diskOffering != null && !diskOffering .isCustomized () && diskOffering .getDiskSize () < disk .getCapacity ()) {
624
626
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
627
}
626
- StoragePool storagePool = getStoragePool (disk , zone , cluster );
628
+ diskOffering = diskOffering != null ? diskOffering : diskOfferingDao .findById (serviceOffering .getDiskOfferingId ());
629
+ StoragePool storagePool = getStoragePool (disk , zone , cluster , diskOffering != null ? diskOffering .getTags () : null );
627
630
if (diskOffering != null && !migrateAllowed && !storagePoolSupportsDiskOffering (storagePool , diskOffering )) {
628
631
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 ()));
629
632
}
@@ -860,7 +863,7 @@ private Pair<DiskProfile, StoragePool> importDisk(UnmanagedInstanceTO.Disk disk,
860
863
diskInfo .setDiskChain (new String []{disk .getImagePath ()});
861
864
chainInfo = gson .toJson (diskInfo );
862
865
}
863
- StoragePool storagePool = getStoragePool (disk , zone , cluster );
866
+ StoragePool storagePool = getStoragePool (disk , zone , cluster , diskOffering != null ? diskOffering . getTags () : null );
864
867
DiskProfile profile = volumeManager .importVolume (type , name , diskOffering , diskSize ,
865
868
minIops , maxIops , vm .getDataCenterId (), vm .getHypervisorType (), vm , template , owner , deviceId , storagePool .getId (), path , chainInfo );
866
869
@@ -1645,7 +1648,7 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
1645
1648
1646
1649
temporaryConvertLocation = selectInstanceConversionTemporaryLocation (
1647
1650
destinationCluster , convertHost , convertStoragePoolId );
1648
- List <StoragePoolVO > convertStoragePools = findInstanceConversionStoragePoolsInCluster (destinationCluster );
1651
+ List <StoragePoolVO > convertStoragePools = findInstanceConversionStoragePoolsInCluster (destinationCluster , serviceOffering , dataDiskOfferingMap );
1649
1652
long importStartTime = System .currentTimeMillis ();
1650
1653
Pair <UnmanagedInstanceTO , Boolean > sourceInstanceDetails = getSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password , clusterName , sourceHostName , sourceVMName );
1651
1654
sourceVMwareInstance = sourceInstanceDetails .first ();
@@ -1661,15 +1664,18 @@ protected UserVm importUnmanagedInstanceFromVmwareToKvm(DataCenter zone, Cluster
1661
1664
if (cmd .getForceMsToImportVmFiles () || !conversionSupportAnswer .isOvfExportSupported ()) {
1662
1665
// Uses MS for OVF export to temporary conversion location
1663
1666
int noOfThreads = UnmanagedVMsManager .ThreadsOnMSToImportVMwareVMFiles .value ();
1664
- ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (vcenter , datacenterName , username , password ,
1665
- clusterName , sourceHostName , sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
1667
+ ovfTemplateOnConvertLocation = createOvfTemplateOfSourceVmwareUnmanagedInstance (
1668
+ vcenter , datacenterName , username , password , clusterName , sourceHostName ,
1669
+ sourceVMwareInstance .getName (), temporaryConvertLocation , noOfThreads );
1666
1670
convertedInstance = convertVmwareInstanceToKVMWithOVFOnConvertLocation (sourceVMName ,
1667
- sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1668
- temporaryConvertLocation , ovfTemplateOnConvertLocation );
1671
+ sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1672
+ serviceOffering , dataDiskOfferingMap , temporaryConvertLocation ,
1673
+ ovfTemplateOnConvertLocation );
1669
1674
} else {
1670
1675
// Uses KVM Host for OVF export to temporary conversion location, through ovftool
1671
1676
convertedInstance = convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1672
- sourceVMName , sourceVMwareInstance , convertHost , importHost , convertStoragePools ,
1677
+ sourceVMName , sourceVMwareInstance , convertHost , importHost ,
1678
+ convertStoragePools , serviceOffering , dataDiskOfferingMap ,
1673
1679
temporaryConvertLocation , vcenter , username , password , datacenterName );
1674
1680
}
1675
1681
@@ -1759,9 +1765,9 @@ private void sanitizeConvertedInstance(UnmanagedInstanceTO convertedInstance, Un
1759
1765
convertedInstance .setPowerState (UnmanagedInstanceTO .PowerState .PowerOff );
1760
1766
List <UnmanagedInstanceTO .Disk > convertedInstanceDisks = convertedInstance .getDisks ();
1761
1767
List <UnmanagedInstanceTO .Disk > sourceVMwareInstanceDisks = sourceVMwareInstance .getDisks ();
1762
- for (int i = 0 ; i < convertedInstanceDisks . size (); i ++ ) {
1763
- UnmanagedInstanceTO .Disk disk = convertedInstanceDisks .get (i );
1764
- disk .setDiskId (sourceVMwareInstanceDisks . get ( i ) .getDiskId ());
1768
+ for (UnmanagedInstanceTO . Disk sourceVMwareInstanceDisk : sourceVMwareInstanceDisks ) {
1769
+ UnmanagedInstanceTO .Disk convertedDisk = convertedInstanceDisks .get (sourceVMwareInstanceDisk . getPosition () );
1770
+ convertedDisk .setDiskId (sourceVMwareInstanceDisk .getDiskId ());
1765
1771
}
1766
1772
List <UnmanagedInstanceTO .Nic > convertedInstanceNics = convertedInstance .getNics ();
1767
1773
List <UnmanagedInstanceTO .Nic > sourceVMwareInstanceNics = sourceVMwareInstance .getNics ();
@@ -1945,16 +1951,16 @@ private CheckConvertInstanceAnswer checkConversionSupportOnHost(HostVO convertHo
1945
1951
}
1946
1952
1947
1953
private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation (
1948
- String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1949
- HostVO convertHost , HostVO importHost ,
1950
- List < StoragePoolVO > convertStoragePools , DataStoreTO temporaryConvertLocation ,
1951
- String ovfTemplateDirConvertLocation
1954
+ String sourceVM , UnmanagedInstanceTO sourceVMwareInstance , HostVO convertHost ,
1955
+ HostVO importHost , List < StoragePoolVO > convertStoragePools ,
1956
+ ServiceOfferingVO serviceOffering , Map < String , Long > dataDiskOfferingMap ,
1957
+ DataStoreTO temporaryConvertLocation , String ovfTemplateDirConvertLocation
1952
1958
) {
1953
1959
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" ,
1954
1960
sourceVM , convertHost .getId (), convertHost .getName (), ovfTemplateDirConvertLocation ));
1955
1961
1956
1962
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO (sourceVM );
1957
- List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks ());
1963
+ List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), serviceOffering , dataDiskOfferingMap );
1958
1964
ConvertInstanceCommand cmd = new ConvertInstanceCommand (remoteInstanceTO ,
1959
1965
Hypervisor .HypervisorType .KVM , destinationStoragePools , temporaryConvertLocation , ovfTemplateDirConvertLocation , false , false );
1960
1966
int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
@@ -1980,16 +1986,17 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation(
1980
1986
}
1981
1987
1982
1988
private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation (
1983
- String sourceVM , UnmanagedInstanceTO sourceVMwareInstance ,
1984
- HostVO convertHost , HostVO importHost , List <StoragePoolVO > convertStoragePools ,
1985
- DataStoreTO temporaryConvertLocation , String vcenterHost ,
1986
- String vcenterUsername , String vcenterPassword , String datacenterName
1989
+ String sourceVM , UnmanagedInstanceTO sourceVMwareInstance , HostVO convertHost ,
1990
+ HostVO importHost , List <StoragePoolVO > convertStoragePools ,
1991
+ ServiceOfferingVO serviceOffering , Map <String , Long > dataDiskOfferingMap ,
1992
+ DataStoreTO temporaryConvertLocation , String vcenterHost , String vcenterUsername ,
1993
+ String vcenterPassword , String datacenterName
1987
1994
) {
1988
1995
logger .debug (String .format ("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) after OVF export through ovftool" ,
1989
1996
sourceVM , convertHost .getId (), convertHost .getName ()));
1990
1997
1991
1998
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO (sourceVMwareInstance .getName (), vcenterHost , vcenterUsername , vcenterPassword , datacenterName );
1992
- List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks ());
1999
+ List <String > destinationStoragePools = selectInstanceConversionStoragePools (convertStoragePools , sourceVMwareInstance .getDisks (), serviceOffering , dataDiskOfferingMap );
1993
2000
ConvertInstanceCommand cmd = new ConvertInstanceCommand (remoteInstanceTO ,
1994
2001
Hypervisor .HypervisorType .KVM , destinationStoragePools , temporaryConvertLocation , null , false , true );
1995
2002
int timeoutSeconds = UnmanagedVMsManager .ConvertVmwareInstanceToKvmTimeout .value () * 60 * 60 ;
@@ -2052,12 +2059,31 @@ private UnmanagedInstanceTO convertAndImportToKVM(ConvertInstanceCommand convert
2052
2059
return ((ImportConvertedInstanceAnswer ) importAnswer ).getConvertedInstance ();
2053
2060
}
2054
2061
2055
- private List <StoragePoolVO > findInstanceConversionStoragePoolsInCluster (Cluster destinationCluster ) {
2062
+ private List <StoragePoolVO > findInstanceConversionStoragePoolsInCluster (
2063
+ Cluster destinationCluster , ServiceOfferingVO serviceOffering ,
2064
+ Map <String , Long > dataDiskOfferingMap
2065
+ ) {
2056
2066
List <StoragePoolVO > pools = new ArrayList <>();
2057
- List <StoragePoolVO > clusterPools = primaryDataStoreDao .findClusterWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem );
2058
- pools .addAll (clusterPools );
2059
- List <StoragePoolVO > zonePools = primaryDataStoreDao .findZoneWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getDataCenterId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem );
2060
- pools .addAll (zonePools );
2067
+ pools .addAll (primaryDataStoreDao .findClusterWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem ));
2068
+ pools .addAll (primaryDataStoreDao .findZoneWideStoragePoolsByHypervisorAndPoolType (destinationCluster .getDataCenterId (), Hypervisor .HypervisorType .KVM , Storage .StoragePoolType .NetworkFilesystem ));
2069
+ List <String > diskOfferingTags = new ArrayList <>();
2070
+ for (Long diskOfferingId : dataDiskOfferingMap .values ()) {
2071
+ DiskOfferingVO diskOffering = diskOfferingDao .findById (diskOfferingId );
2072
+ if (diskOffering == null ) {
2073
+ String msg = String .format ("Cannot find disk offering with ID %s" , diskOfferingId );
2074
+ logger .error (msg );
2075
+ throw new CloudRuntimeException (msg );
2076
+ }
2077
+ diskOfferingTags .add (diskOffering .getTags ());
2078
+ }
2079
+ if (serviceOffering .getDiskOfferingId () != null ) {
2080
+ DiskOfferingVO diskOffering = diskOfferingDao .findById (serviceOffering .getDiskOfferingId ());
2081
+ if (diskOffering != null ) {
2082
+ diskOfferingTags .add (diskOffering .getTags ());
2083
+ }
2084
+ }
2085
+
2086
+ pools = getPoolsWithMatchingTags (pools , diskOfferingTags );
2061
2087
if (pools .isEmpty ()) {
2062
2088
String msg = String .format ("Cannot find suitable storage pools in cluster %s for the conversion" , destinationCluster .getName ());
2063
2089
logger .error (msg );
@@ -2066,12 +2092,54 @@ private List<StoragePoolVO> findInstanceConversionStoragePoolsInCluster(Cluster
2066
2092
return pools ;
2067
2093
}
2068
2094
2069
- private List <String > selectInstanceConversionStoragePools (List <StoragePoolVO > pools , List <UnmanagedInstanceTO .Disk > disks ) {
2095
+ private List <StoragePoolVO > getPoolsWithMatchingTags (List <StoragePoolVO > pools , List <String > diskOfferingTags ) {
2096
+ if (diskOfferingTags .isEmpty ()) {
2097
+ return pools ;
2098
+ }
2099
+ List <StoragePoolVO > poolsSupportingTags = new ArrayList <>(pools );
2100
+ for (String tags : diskOfferingTags ) {
2101
+ boolean tagsMatched = false ;
2102
+ for (StoragePoolVO pool : pools ) {
2103
+ if (volumeApiService .doesTargetStorageSupportDiskOffering (pool , tags )) {
2104
+ poolsSupportingTags .add (pool );
2105
+ tagsMatched = true ;
2106
+ }
2107
+ }
2108
+ if (!tagsMatched ) {
2109
+ String msg = String .format ("Cannot find suitable storage pools for the conversion with disk offering tags %s" , tags );
2110
+ logger .error (msg );
2111
+ throw new CloudRuntimeException (msg );
2112
+ }
2113
+ }
2114
+ return poolsSupportingTags ;
2115
+ }
2116
+
2117
+ private List <String > selectInstanceConversionStoragePools (
2118
+ List <StoragePoolVO > pools , List <UnmanagedInstanceTO .Disk > disks ,
2119
+ ServiceOfferingVO serviceOffering , Map <String , Long > dataDiskOfferingMap
2120
+ ) {
2070
2121
List <String > storagePools = new ArrayList <>(disks .size ());
2071
- //TODO: Choose pools by capacity
2122
+ for (int i = 0 ; i < disks .size (); i ++) {
2123
+ storagePools .add (null );
2124
+ }
2125
+ Set <String > dataDiskIds = dataDiskOfferingMap .keySet ();
2072
2126
for (UnmanagedInstanceTO .Disk disk : disks ) {
2073
- Long capacity = disk .getCapacity ();
2074
- storagePools .add (pools .get (0 ).getUuid ());
2127
+ Long diskOfferingId = dataDiskOfferingMap .get (disk .getDiskId ());
2128
+ if (diskOfferingId == null && !dataDiskIds .contains (disk .getDiskId ())) {
2129
+ diskOfferingId = serviceOffering .getDiskOfferingId ();
2130
+ }
2131
+ //TODO: Choose pools by capacity
2132
+ if (diskOfferingId == null ) {
2133
+ storagePools .set (disk .getPosition (), pools .get (0 ).getUuid ());
2134
+ } else {
2135
+ DiskOfferingVO diskOffering = diskOfferingDao .findById (diskOfferingId );
2136
+ for (StoragePoolVO pool : pools ) {
2137
+ if (volumeApiService .doesTargetStorageSupportDiskOffering (pool , diskOffering .getTags ())) {
2138
+ storagePools .set (disk .getPosition (), pool .getUuid ());
2139
+ break ;
2140
+ }
2141
+ }
2142
+ }
2075
2143
}
2076
2144
return storagePools ;
2077
2145
}
0 commit comments