28
28
import java .util .UUID ;
29
29
30
30
import org .apache .cloudstack .storage .datastore .client .ScaleIOGatewayClient ;
31
+ import org .apache .cloudstack .storage .datastore .manager .ScaleIOSDCManager ;
31
32
import org .apache .cloudstack .storage .datastore .util .ScaleIOUtil ;
32
33
import org .apache .cloudstack .utils .cryptsetup .CryptSetup ;
33
34
import org .apache .cloudstack .utils .cryptsetup .CryptSetupException ;
@@ -148,12 +149,37 @@ public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) {
148
149
@ Override
149
150
public KVMStoragePool createStoragePool (String uuid , String host , int port , String path , String userInfo , Storage .StoragePoolType type , Map <String , String > details ) {
150
151
ScaleIOStoragePool storagePool = new ScaleIOStoragePool (uuid , host , port , path , type , details , this );
152
+ if (details != null && details .containsKey (ScaleIOSDCManager .ConnectOnDemand .key ())) {
153
+ String connectOnDemand = details .get (ScaleIOSDCManager .ConnectOnDemand .key ());
154
+ if (connectOnDemand != null && !Boolean .parseBoolean (connectOnDemand )) {
155
+ Ternary <Boolean , Map <String , String >, String > prepareStorageClientStatus = prepareStorageClient (uuid , details );
156
+ if (prepareStorageClientStatus .first ()) {
157
+ details .putAll (prepareStorageClientStatus .second ());
158
+ }
159
+ }
160
+ }
151
161
MapStorageUuidToStoragePool .put (uuid , storagePool );
152
162
return storagePool ;
153
163
}
154
164
155
165
@ Override
156
166
public boolean deleteStoragePool (String uuid ) {
167
+ ScaleIOStoragePool storagePool = (ScaleIOStoragePool ) MapStorageUuidToStoragePool .get (uuid );
168
+ if (storagePool != null ) {
169
+ unprepareStorageClient (uuid , storagePool .getDetails ());
170
+ }
171
+ return MapStorageUuidToStoragePool .remove (uuid ) != null ;
172
+ }
173
+
174
+ @ Override
175
+ public boolean deleteStoragePool (String uuid , Map <String , String > details ) {
176
+ if (details != null && details .containsKey (ScaleIOSDCManager .ConnectOnDemand .key ())) {
177
+ String connectOnDemand = details .get (ScaleIOSDCManager .ConnectOnDemand .key ());
178
+ if (connectOnDemand != null && !Boolean .parseBoolean (connectOnDemand )) {
179
+ Pair <Boolean , String > unprepareStorageClientStatus = unprepareStorageClient (uuid , details );
180
+ return MapStorageUuidToStoragePool .remove (uuid ) != null && unprepareStorageClientStatus .first ();
181
+ }
182
+ }
157
183
return MapStorageUuidToStoragePool .remove (uuid ) != null ;
158
184
}
159
185
@@ -567,7 +593,7 @@ public void resizeQcow2ToVolume(String volumePath, QemuImageOptions options, Lis
567
593
qemu .resize (options , objects , usableSizeBytes );
568
594
}
569
595
570
- public Ternary <Boolean , Map <String , String >, String > prepareStorageClient (Storage . StoragePoolType type , String uuid , Map <String , String > details ) {
596
+ public Ternary <Boolean , Map <String , String >, String > prepareStorageClient (String uuid , Map <String , String > details ) {
571
597
if (!ScaleIOUtil .isSDCServiceInstalled ()) {
572
598
logger .debug ("SDC service not installed on host, preparing the SDC client not possible" );
573
599
return new Ternary <>(false , null , "SDC service not installed on host" );
@@ -591,6 +617,10 @@ public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(Storag
591
617
String mdms = details .get (ScaleIOGatewayClient .STORAGE_POOL_MDMS );
592
618
String [] mdmAddresses = mdms .split ("," );
593
619
if (mdmAddresses .length > 0 ) {
620
+ if (ScaleIOUtil .mdmAdded (mdmAddresses [0 ])) {
621
+ return new Ternary <>(true , getSDCDetails (details ), "MDM added, no need to prepare the SDC client" );
622
+ }
623
+
594
624
ScaleIOUtil .addMdms (Arrays .asList (mdmAddresses ));
595
625
if (!ScaleIOUtil .mdmAdded (mdmAddresses [0 ])) {
596
626
return new Ternary <>(false , null , "Failed to add MDMs" );
@@ -601,7 +631,7 @@ public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(Storag
601
631
return new Ternary <>( true , getSDCDetails (details ), "Prepared client successfully" );
602
632
}
603
633
604
- public Pair <Boolean , String > unprepareStorageClient (Storage . StoragePoolType type , String uuid , Map <String , String > details ) {
634
+ public Pair <Boolean , String > unprepareStorageClient (String uuid , Map <String , String > details ) {
605
635
if (!ScaleIOUtil .isSDCServiceInstalled ()) {
606
636
logger .debug ("SDC service not installed on host, no need to unprepare the SDC client" );
607
637
return new Pair <>(true , "SDC service not installed on host, no need to unprepare the SDC client" );
0 commit comments