4343import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
4444import org .apache .cloudstack .storage .datastore .db .StoragePoolDetailsDao ;
4545import org .apache .cloudstack .storage .datastore .lifecycle .BasePrimaryDataStoreLifeCycleImpl ;
46+ import org .apache .cloudstack .storage .feign .model .Igroup ;
47+ import org .apache .cloudstack .storage .feign .model .Initiator ;
4648import org .apache .cloudstack .storage .feign .model .OntapStorage ;
49+ import org .apache .cloudstack .storage .feign .model .Svm ;
4750import org .apache .cloudstack .storage .provider .StorageProviderFactory ;
4851import org .apache .cloudstack .storage .service .StorageStrategy ;
4952import org .apache .cloudstack .storage .service .model .AccessGroup ;
@@ -271,13 +274,13 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
271274 StorageStrategy strategy = Utility .getStrategyByStoragePoolDetails (details );
272275 ProtocolType protocol = ProtocolType .valueOf (details .get (Constants .PROTOCOL ));
273276 //TODO- Check if we have to handle heterogeneous host within the cluster
274- if (!isProtocolSupportedByAllHosts (hostsToConnect , protocol , hostsIdentifier )) {
277+ if (!validateProtocolSupportAndFetchHostsIndentifier (hostsToConnect , protocol , hostsIdentifier )) {
275278 s_logger .error ("attachCluster: Not all hosts in the cluster support the protocol: " + protocol .name ());
276279 throw new CloudRuntimeException ("attachCluster: Not all hosts in the cluster support the protocol: " + protocol .name ());
277280 }
278281 //TODO - check if no host to connect then also need to create access group without initiators
279282 if (hostsIdentifier != null && hostsIdentifier .size () > 0 ) {
280- AccessGroup accessGroupRequest = Utility . createAccessGroupRequestByProtocol (storagePool , scope .getScopeId (), details , hostsIdentifier );
283+ AccessGroup accessGroupRequest = createAccessGroupRequestByProtocol (storagePool , scope .getScopeId (), details , hostsIdentifier );
281284 strategy .createAccessGroup (accessGroupRequest );
282285 }
283286 logger .debug ("attachCluster: Attaching the pool to each of the host in the cluster: {}" , primaryStore .getClusterId ());
@@ -320,12 +323,12 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper
320323 StorageStrategy strategy = Utility .getStrategyByStoragePoolDetails (details );
321324 ProtocolType protocol = ProtocolType .valueOf (details .get (Constants .PROTOCOL ));
322325 //TODO- Check if we have to handle heterogeneous host within the zone
323- if (!isProtocolSupportedByAllHosts (hostsToConnect , protocol , hostsIdentifier )) {
326+ if (!validateProtocolSupportAndFetchHostsIndentifier (hostsToConnect , protocol , hostsIdentifier )) {
324327 s_logger .error ("attachZone: Not all hosts in the zone support the protocol: " + protocol .name ());
325328 throw new CloudRuntimeException ("attachZone: Not all hosts in the zone support the protocol: " + protocol .name ());
326329 }
327330 if (hostsIdentifier != null && !hostsIdentifier .isEmpty ()) {
328- AccessGroup accessGroupRequest = Utility . createAccessGroupRequestByProtocol (storagePool , scope .getScopeId (), details , hostsIdentifier );
331+ AccessGroup accessGroupRequest = createAccessGroupRequestByProtocol (storagePool , scope .getScopeId (), details , hostsIdentifier );
329332 strategy .createAccessGroup (accessGroupRequest );
330333 }
331334 for (HostVO host : hostsToConnect ) {
@@ -339,7 +342,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper
339342 return true ;
340343 }
341344
342- private boolean isProtocolSupportedByAllHosts (List <HostVO > hosts , ProtocolType protocolType , List <String > hostIdentifiers ) {
345+ private boolean validateProtocolSupportAndFetchHostsIndentifier (List <HostVO > hosts , ProtocolType protocolType , List <String > hostIdentifiers ) {
343346 switch (protocolType ) {
344347 case ISCSI :
345348 String protocolPrefix = Constants .IQN ;
@@ -357,6 +360,53 @@ private boolean isProtocolSupportedByAllHosts(List<HostVO> hosts, ProtocolType p
357360 return true ;
358361 }
359362
363+ private AccessGroup createAccessGroupRequestByProtocol (StoragePoolVO storagePool , long scopeId , Map <String , String > details , List <String > hostsIdentifier ) {
364+ ProtocolType protocol = ProtocolType .valueOf (details .get (Constants .PROTOCOL ).toLowerCase ());
365+ String svmName = details .get (Constants .SVM_NAME );
366+ switch (protocol ) {
367+ case ISCSI :
368+ // Access group name format: cs_svmName_scopeId
369+ String igroupName = Utility .getIgroupName (svmName , scopeId );
370+ Hypervisor .HypervisorType hypervisorType = storagePool .getHypervisor ();
371+ return createSANAccessGroupRequest (svmName , igroupName , hypervisorType , hostsIdentifier );
372+ default :
373+ s_logger .error ("createAccessGroupRequestByProtocol: Unsupported protocol " + protocol );
374+ throw new CloudRuntimeException ("createAccessGroupRequestByProtocol: Unsupported protocol " + protocol );
375+ }
376+ }
377+
378+ private AccessGroup createSANAccessGroupRequest (String svmName , String igroupName , Hypervisor .HypervisorType hypervisorType , List <String > hostsIdentifier ) {
379+ AccessGroup accessGroupRequest = new AccessGroup ();
380+ Igroup igroup = new Igroup ();
381+
382+ if (svmName != null && !svmName .isEmpty ()) {
383+ Svm svm = new Svm ();
384+ svm .setName (svmName );
385+ igroup .setSvm (svm );
386+ }
387+
388+ if (igroupName != null && !igroupName .isEmpty ()) {
389+ igroup .setName (igroupName );
390+ }
391+
392+ if (hypervisorType != null ) {
393+ String hypervisorName = hypervisorType .name ();
394+ igroup .setOsType (Igroup .OsTypeEnum .valueOf (Utility .getOSTypeFromHypervisor (hypervisorName )));
395+ }
396+
397+ if (hostsIdentifier != null && hostsIdentifier .size () > 0 ) {
398+ List <Initiator > initiators = new ArrayList <>();
399+ for (String hostIdentifier : hostsIdentifier ) {
400+ Initiator initiator = new Initiator ();
401+ initiator .setName (hostIdentifier );
402+ initiators .add (initiator );
403+ }
404+ igroup .setInitiators (initiators );
405+ }
406+ accessGroupRequest .setIgroup (igroup );
407+ return accessGroupRequest ;
408+ }
409+
360410 @ Override
361411 public boolean maintain (DataStore store ) {
362412 return true ;
0 commit comments