Skip to content

Commit 95aef33

Browse files
committed
CLOUDSTACK-737,
allow to add security group enabled networks in security group enabled zone
1 parent 485761f commit 95aef33

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
@@ -1526,13 +1526,11 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
15261526
// check if zone has necessary trafficTypes before enabling
15271527
try {
15281528
PhysicalNetwork mgmtPhyNetwork;
1529-
if (NetworkType.Advanced == zone.getNetworkType()) {
1530-
// zone should have a physical network with public and management traffiType
1529+
// zone should have a physical network with management traffiType
1530+
mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
1531+
if (NetworkType.Advanced == zone.getNetworkType() && ! zone.isSecurityGroupEnabled() ) {
1532+
// advanced zone without SG should have a physical network with public Thpe
15311533
_networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public);
1532-
mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
1533-
} else {
1534-
// zone should have a physical network with management traffiType
1535-
mgmtPhyNetwork = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
15361534
}
15371535

15381536
try {

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

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

757757
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
758758

759-
TrafficType defaultTrafficType = TrafficType.Public;
760-
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
761-
defaultTrafficType = TrafficType.Guest;
762-
}
763-
764-
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
759+
NetworkVO defaultNetwork = null;
760+
if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
761+
List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
762+
if (networks == null || networks.size() == 0) {
763+
throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
764+
}
765+
defaultNetwork = networks.get(0);
766+
} else {
767+
TrafficType defaultTrafficType = TrafficType.Public;
768+
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
769+
defaultTrafficType = TrafficType.Guest;
770+
}
771+
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
765772

766-
if (defaultNetworks.size() != 1) {
767-
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
773+
// api should never allow this situation to happen
774+
if (defaultNetworks.size() != 1) {
775+
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type "
776+
+ defaultTrafficType + " when expect to find 1");
777+
}
778+
defaultNetwork = defaultNetworks.get(0);
768779
}
769780

770-
NetworkVO defaultNetwork = defaultNetworks.get(0);
771-
772781
List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
773782
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
774783
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
@@ -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

Comments
 (0)