@@ -1360,6 +1360,7 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
13601360 String dns2 = cmd .getDns2 ();
13611361 String internalDns1 = cmd .getInternalDns1 ();
13621362 String internalDns2 = cmd .getInternalDns2 ();
1363+ String guestCidr = cmd .getGuestCidrAddress ();
13631364 List <String > dnsSearchOrder = cmd .getDnsSearchOrder ();
13641365 Boolean isPublic = cmd .isPublic ();
13651366 String allocationStateStr = cmd .getAllocationState ();
@@ -1410,6 +1411,10 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
14101411 zoneName = zone .getName ();
14111412 }
14121413
1414+ if ((guestCidr != null ) && !NetUtils .validateGuestCidr (guestCidr )) {
1415+ throw new InvalidParameterValueException ("Please enter a valid guest cidr" );
1416+ }
1417+
14131418 // Make sure the zone exists
14141419 if (!validZone (zoneId )) {
14151420 throw new InvalidParameterValueException ("A zone with ID: " + zoneId + " does not exist." );
@@ -1433,6 +1438,10 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
14331438 internalDns1 = zone .getInternalDns1 ();
14341439 }
14351440
1441+ if (guestCidr == null ) {
1442+ guestCidr = zone .getGuestNetworkCidr ();
1443+ }
1444+
14361445 // validate network domain
14371446 if (networkDomain != null && !networkDomain .isEmpty ()) {
14381447 if (!NetUtils .verifyDomainName (networkDomain )) {
@@ -1459,6 +1468,7 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
14591468 zone .setDns2 (dns2 );
14601469 zone .setInternalDns1 (internalDns1 );
14611470 zone .setInternalDns2 (internalDns2 );
1471+ zone .setGuestNetworkCidr (guestCidr );
14621472
14631473 if (networkDomain != null ) {
14641474 if (networkDomain .isEmpty ()) {
@@ -1531,12 +1541,15 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
15311541
15321542 @ Override
15331543 @ DB
1534- public DataCenterVO createZone (long userId , String zoneName , String dns1 , String dns2 , String internalDns1 , String internalDns2 , String domain , Long domainId ,
1544+ public DataCenterVO createZone (long userId , String zoneName , String dns1 , String dns2 , String internalDns1 , String internalDns2 , String guestCidr , String domain , Long domainId ,
15351545 NetworkType zoneType , String allocationStateStr , String networkDomain , boolean isSecurityGroupEnabled ) {
15361546
15371547 // checking the following params outside checkzoneparams method as we do
15381548 // not use these params for updatezone
15391549 // hence the method below is generic to check for common params
1550+ if ((guestCidr != null ) && !NetUtils .validateGuestCidr (guestCidr )) {
1551+ throw new InvalidParameterValueException ("Please enter a valid guest cidr" );
1552+ }
15401553
15411554 // Validate network domain
15421555 if (networkDomain != null ) {
@@ -1555,7 +1568,7 @@ public DataCenterVO createZone(long userId, String zoneName, String dns1, String
15551568 try {
15561569 txn .start ();
15571570 // Create the new zone in the database
1558- DataCenterVO zone = new DataCenterVO (zoneName , null , dns1 , dns2 , internalDns1 , internalDns2 , domain , domainId , zoneType , zoneToken , networkDomain , isSecurityGroupEnabled );
1571+ DataCenterVO zone = new DataCenterVO (zoneName , null , dns1 , dns2 , internalDns1 , internalDns2 , guestCidr , domain , domainId , zoneType , zoneToken , networkDomain , isSecurityGroupEnabled );
15591572 if (allocationStateStr != null && !allocationStateStr .isEmpty ()) {
15601573 Grouping .AllocationState allocationState = Grouping .AllocationState .valueOf (allocationStateStr );
15611574 zone .setAllocationState (allocationState );
@@ -1625,6 +1638,7 @@ public DataCenter createZone(CreateZoneCmd cmd) {
16251638 String dns2 = cmd .getDns2 ();
16261639 String internalDns1 = cmd .getInternalDns1 ();
16271640 String internalDns2 = cmd .getInternalDns2 ();
1641+ String guestCidr = cmd .getGuestCidrAddress ();
16281642 Long domainId = cmd .getDomainId ();
16291643 String type = cmd .getNetworkType ();
16301644 Boolean isBasic = false ;
@@ -1644,6 +1658,14 @@ public DataCenter createZone(CreateZoneCmd cmd) {
16441658
16451659 NetworkType zoneType = isBasic ? NetworkType .Basic : NetworkType .Advanced ;
16461660
1661+ // Guest cidr is required for Advanced zone creation; error out when the
1662+ // parameter specified for Basic zone
1663+ if (zoneType == NetworkType .Advanced && guestCidr == null && !isSecurityGroupEnabled ) {
1664+ throw new InvalidParameterValueException ("guestCidrAddress parameter is required for Advanced zone creation" );
1665+ } else if (zoneType == NetworkType .Basic && guestCidr != null ) {
1666+ throw new InvalidParameterValueException ("guestCidrAddress parameter is not supported for Basic zone" );
1667+ }
1668+
16471669 DomainVO domainVO = null ;
16481670
16491671 if (userId == null ) {
@@ -1658,7 +1680,7 @@ public DataCenter createZone(CreateZoneCmd cmd) {
16581680 isSecurityGroupEnabled = true ;
16591681 }
16601682
1661- return createZone (userId , zoneName , dns1 , dns2 , internalDns1 , internalDns2 , domainVO != null ? domainVO .getName () : null , domainId , zoneType , allocationState , networkDomain ,
1683+ return createZone (userId , zoneName , dns1 , dns2 , internalDns1 , internalDns2 , guestCidr , domainVO != null ? domainVO .getName () : null , domainId , zoneType , allocationState , networkDomain ,
16621684 isSecurityGroupEnabled );
16631685 }
16641686
@@ -2345,8 +2367,29 @@ public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, Str
23452367
23462368 String newVlanSubnet = NetUtils .getSubNet (vlanGateway , vlanNetmask );
23472369
2348- // TODO: Check if the new VLAN's subnet conflicts with the guest network in
2370+ // Check if the new VLAN's subnet conflicts with the guest network in
23492371 // the specified zone (guestCidr is null for basic zone)
2372+ String guestNetworkCidr = zone .getGuestNetworkCidr ();
2373+ if (guestNetworkCidr != null ) {
2374+ String [] cidrPair = guestNetworkCidr .split ("\\ /" );
2375+ String guestIpNetwork = NetUtils .getIpRangeStartIpFromCidr (cidrPair [0 ], Long .parseLong (cidrPair [1 ]));
2376+ long guestCidrSize = Long .parseLong (cidrPair [1 ]);
2377+ long vlanCidrSize = NetUtils .getCidrSize (vlanNetmask );
2378+
2379+ long cidrSizeToUse = -1 ;
2380+ if (vlanCidrSize < guestCidrSize ) {
2381+ cidrSizeToUse = vlanCidrSize ;
2382+ } else {
2383+ cidrSizeToUse = guestCidrSize ;
2384+ }
2385+
2386+ String guestSubnet = NetUtils .getCidrSubNet (guestIpNetwork , cidrSizeToUse );
2387+
2388+ if (newVlanSubnet .equals (guestSubnet )) {
2389+ throw new InvalidParameterValueException ("The new IP range you have specified has the same subnet as the guest network in zone: " + zone .getName ()
2390+ + ". Please specify a different gateway/netmask." );
2391+ }
2392+ }
23502393
23512394 // Check if there are any errors with the IP range
23522395 checkPublicIpRangeErrors (zoneId , vlanId , vlanGateway , vlanNetmask , startIP , endIP );
@@ -2758,6 +2801,18 @@ public void checkPodCidrSubnets(long dcId, Long podIdToBeSkipped, String cidr) {
27582801 newCidrPair .add (1 , (long ) getCidrSize (cidr ));
27592802 currentPodCidrSubnets .put (new Long (-1 ), newCidrPair );
27602803
2804+ DataCenterVO dcVo = _zoneDao .findById (dcId );
2805+ String guestNetworkCidr = dcVo .getGuestNetworkCidr ();
2806+
2807+ // Guest cidr can be null for Basic zone
2808+ String guestIpNetwork = null ;
2809+ Long guestCidrSize = null ;
2810+ if (guestNetworkCidr != null ) {
2811+ String [] cidrTuple = guestNetworkCidr .split ("\\ /" );
2812+ guestIpNetwork = NetUtils .getIpRangeStartIpFromCidr (cidrTuple [0 ], Long .parseLong (cidrTuple [1 ]));
2813+ guestCidrSize = Long .parseLong (cidrTuple [1 ]);
2814+ }
2815+
27612816 String zoneName = getZoneName (dcId );
27622817
27632818 // Iterate through all pods in this zone
@@ -2774,10 +2829,27 @@ public void checkPodCidrSubnets(long dcId, Long podIdToBeSkipped, String cidr) {
27742829 long cidrSize = ((Long ) cidrPair .get (1 )).longValue ();
27752830
27762831 long cidrSizeToUse = -1 ;
2777- cidrSizeToUse = cidrSize ;
2832+ if (guestCidrSize == null || cidrSize < guestCidrSize ) {
2833+ cidrSizeToUse = cidrSize ;
2834+ } else {
2835+ cidrSizeToUse = guestCidrSize ;
2836+ }
27782837
27792838 String cidrSubnet = NetUtils .getCidrSubNet (cidrAddress , cidrSizeToUse );
27802839
2840+ if (guestNetworkCidr != null ) {
2841+ String guestSubnet = NetUtils .getCidrSubNet (guestIpNetwork , cidrSizeToUse );
2842+ // Check that cidrSubnet does not equal guestSubnet
2843+ if (cidrSubnet .equals (guestSubnet )) {
2844+ if (podName .equals ("newPod" )) {
2845+ throw new InvalidParameterValueException ("The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR." );
2846+ } else {
2847+ throw new InvalidParameterValueException ("Warning: The subnet of pod " + podName + " in zone " + zoneName
2848+ + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management." );
2849+ }
2850+ }
2851+ }
2852+
27812853 // Iterate through the rest of the pods
27822854 for (Long otherPodId : currentPodCidrSubnets .keySet ()) {
27832855 if (podId .equals (otherPodId )) {
0 commit comments