@@ -537,19 +537,27 @@ protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, Seco
537537 DataCenterDeployment plan = new DataCenterDeployment (dataCenterId );
538538 DataCenter dc = _dcDao .findById (plan .getDataCenterId ());
539539
540- TrafficType defaultTrafficType = TrafficType .Public ;
541- if (dc .getNetworkType () == NetworkType .Basic || dc .isSecurityGroupEnabled ()) {
542- defaultTrafficType = TrafficType .Guest ;
543- }
544-
545- List <NetworkVO > defaultNetworks = _networkDao .listByZoneAndTrafficType (dataCenterId , defaultTrafficType );
546-
547- //api should never allow this situation to happen
548- if (defaultNetworks .size () != 1 ) {
549- throw new CloudRuntimeException ("Found " + defaultNetworks .size () + " networks of type " + defaultTrafficType + " when expect to find 1" );
540+ NetworkVO defaultNetwork = null ;
541+ if (dc .getNetworkType () == NetworkType .Advanced && dc .isSecurityGroupEnabled ()) {
542+ List <NetworkVO > networks = _networkDao .listByZoneSecurityGroup (dataCenterId );
543+ if (networks == null || networks .size () == 0 ) {
544+ throw new CloudRuntimeException ("Can not found security enabled network in SG Zone " + dc );
545+ }
546+ defaultNetwork = networks .get (0 );
547+ } else {
548+ TrafficType defaultTrafficType = TrafficType .Public ;
549+
550+ if (dc .getNetworkType () == NetworkType .Basic || dc .isSecurityGroupEnabled ()) {
551+ defaultTrafficType = TrafficType .Guest ;
552+ }
553+ List <NetworkVO > defaultNetworks = _networkDao .listByZoneAndTrafficType (dataCenterId , defaultTrafficType );
554+ // api should never allow this situation to happen
555+ if (defaultNetworks .size () != 1 ) {
556+ throw new CloudRuntimeException ("Found " + defaultNetworks .size () + " networks of type "
557+ + defaultTrafficType + " when expect to find 1" );
558+ }
559+ defaultNetwork = defaultNetworks .get (0 );
550560 }
551-
552- NetworkVO defaultNetwork = defaultNetworks .get (0 );
553561
554562 List <? extends NetworkOffering > offerings = _networkModel .getSystemAccountNetworkOfferings (NetworkOfferingVO .SystemControlNetwork , NetworkOfferingVO .SystemManagementNetwork , NetworkOfferingVO .SystemStorageNetwork );
555563 List <Pair <NetworkVO , NicProfile >> networks = new ArrayList <Pair <NetworkVO , NicProfile >>(offerings .size () + 1 );
0 commit comments