Skip to content

Commit b32d7c0

Browse files
anthonyxuAnthony Xu
authored andcommitted
CLOUDSTACK-737,
allow to add security group enabled networks in security group enabled zone
1 parent 3bb8131 commit b32d7c0

3 files changed

Lines changed: 43 additions & 28 deletions

File tree

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,13 +1774,11 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
17741774
// check if zone has necessary trafficTypes before enabling
17751775
try {
17761776
PhysicalNetwork mgmtPhyNetwork;
1777-
if (NetworkType.Advanced == zone.getNetworkType()) {
1778-
// zone should have a physical network with public and management traffiType
1777+
// zone should have a physical network with management traffiType
1778+
mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
1779+
if (NetworkType.Advanced == zone.getNetworkType() && ! zone.isSecurityGroupEnabled() ) {
1780+
// advanced zone without SG should have a physical network with public Thpe
17791781
_networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public);
1780-
mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
1781-
} else {
1782-
// zone should have a physical network with management traffiType
1783-
mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
17841782
}
17851783

17861784
try {

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -687,19 +687,28 @@ protected Map<String, Object> createProxyInstance(long dataCenterId, HypervisorT
687687

688688
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
689689

690-
TrafficType defaultTrafficType = TrafficType.Public;
691-
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
692-
defaultTrafficType = TrafficType.Guest;
693-
}
694-
695-
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
690+
NetworkVO defaultNetwork = null;
691+
if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
692+
List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
693+
if (networks == null || networks.size() == 0) {
694+
throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
695+
}
696+
defaultNetwork = networks.get(0);
697+
} else {
698+
TrafficType defaultTrafficType = TrafficType.Public;
699+
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
700+
defaultTrafficType = TrafficType.Guest;
701+
}
702+
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
696703

697-
if (defaultNetworks.size() != 1) {
698-
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
704+
// api should never allow this situation to happen
705+
if (defaultNetworks.size() != 1) {
706+
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type "
707+
+ defaultTrafficType + " when expect to find 1");
708+
}
709+
defaultNetwork = defaultNetworks.get(0);
699710
}
700711

701-
NetworkVO defaultNetwork = defaultNetworks.get(0);
702-
703712
List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
704713
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
705714
NicProfile defaultNic = new NicProfile();

‎server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -538,19 +538,27 @@ protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, Seco
538538
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
539539
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
540540

541-
TrafficType defaultTrafficType = TrafficType.Public;
542-
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
543-
defaultTrafficType = TrafficType.Guest;
544-
}
545-
546-
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
547-
548-
//api should never allow this situation to happen
549-
if (defaultNetworks.size() != 1) {
550-
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
541+
NetworkVO defaultNetwork = null;
542+
if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
543+
List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
544+
if (networks == null || networks.size() == 0) {
545+
throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
546+
}
547+
defaultNetwork = networks.get(0);
548+
} else {
549+
TrafficType defaultTrafficType = TrafficType.Public;
550+
551+
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
552+
defaultTrafficType = TrafficType.Guest;
553+
}
554+
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
555+
// api should never allow this situation to happen
556+
if (defaultNetworks.size() != 1) {
557+
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type "
558+
+ defaultTrafficType + " when expect to find 1");
559+
}
560+
defaultNetwork = defaultNetworks.get(0);
551561
}
552-
553-
NetworkVO defaultNetwork = defaultNetworks.get(0);
554562

555563
List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork, NetworkOfferingVO.SystemStorageNetwork);
556564
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);

0 commit comments

Comments
 (0)