Skip to content

Commit 18ec438

Browse files
author
Sheng Yang
committed
Revert zone guest cidr setting
1 parent b97914c commit 18ec438

16 files changed

Lines changed: 196 additions & 58 deletions

api/src/com/cloud/api/commands/CreateZoneCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class CreateZoneCmd extends BaseCmd {
4747
@Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS for the Zone")
4848
private String dns2;
4949

50+
@Parameter(name=ApiConstants.GUEST_CIDR_ADDRESS, type=CommandType.STRING, description="the guest CIDR address for the Zone")
51+
private String guestCidrAddress;
52+
5053
@Parameter(name=ApiConstants.INTERNAL_DNS1, type=CommandType.STRING, required=true, description="the first internal DNS for the Zone")
5154
private String internalDns1;
5255

@@ -84,6 +87,10 @@ public String getDns2() {
8487
return dns2;
8588
}
8689

90+
public String getGuestCidrAddress() {
91+
return guestCidrAddress;
92+
}
93+
8794
public String getInternalDns1() {
8895
return internalDns1;
8996
}

api/src/com/cloud/api/commands/UpdateZoneCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class UpdateZoneCmd extends BaseCmd {
5050
@Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS for the Zone")
5151
private String dns2;
5252

53+
@Parameter(name=ApiConstants.GUEST_CIDR_ADDRESS, type=CommandType.STRING, description="the guest CIDR address for the Zone")
54+
private String guestCidrAddress;
55+
5356
@IdentityMapper(entityTableName="data_center")
5457
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the Zone")
5558
private Long id;
@@ -93,6 +96,10 @@ public String getDns2() {
9396
return dns2;
9497
}
9598

99+
public String getGuestCidrAddress() {
100+
return guestCidrAddress;
101+
}
102+
96103
public Long getId() {
97104
return id;
98105
}

api/src/com/cloud/api/response/ZoneResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class ZoneResponse extends BaseResponse {
5050
@SerializedName(ApiConstants.VLAN) @Param(description="the vlan range of the zone")
5151
private String vlan;
5252

53+
@SerializedName(ApiConstants.GUEST_CIDR_ADDRESS) @Param(description="the guest CIDR address for the Zone")
54+
private String guestCidrAddress;
55+
5356
//TODO - generate description
5457
@SerializedName("status")
5558
private String status;
@@ -116,6 +119,10 @@ public void setVlan(String vlan) {
116119
this.vlan = vlan;
117120
}
118121

122+
public void setGuestCidrAddress(String guestCidrAddress) {
123+
this.guestCidrAddress = guestCidrAddress;
124+
}
125+
119126
public void setStatus(String status) {
120127
this.status = status;
121128
}

api/src/com/cloud/dc/DataCenter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public enum NetworkType {
4141

4242
String getDns2();
4343

44+
String getGuestNetworkCidr();
45+
4446
String getName();
4547

4648
Long getDomainId();

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ public ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapaci
861861
zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
862862
zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
863863
// FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
864+
zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
864865
}
865866

866867
if (showCapacities != null && showCapacities) {

server/src/com/cloud/configuration/ConfigurationManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMa
123123
* @param dns2
124124
* @param internalDns1
125125
* @param internalDns2
126+
* @param guestCidr
126127
* @param zoneType
127128
* @param allocationState
128129
* @param networkDomain
@@ -133,7 +134,7 @@ ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMa
133134
* @throws
134135
* @throws
135136
*/
136-
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String domain, Long domainId, NetworkType zoneType, String allocationState,
137+
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String guestCidr, String domain, Long domainId, NetworkType zoneType, String allocationState,
137138
String networkDomain, boolean isSecurityGroupEnabled);
138139

139140
/**

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

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)) {

server/src/com/cloud/dc/DataCenterVO.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class DataCenterVO implements DataCenter, Identity {
6969
@Column(name="router_mac_address", updatable = false, nullable=false)
7070
private String routerMacAddress = "02:00:00:00:00:01";
7171

72+
@Column(name="guest_network_cidr")
73+
private String guestNetworkCidr = null;
74+
7275
@Column(name="domain_id")
7376
private Long domainId = null;
7477

@@ -171,20 +174,21 @@ public void setFirewallProvider(String firewallProvider) {
171174
this.firewallProvider = firewallProvider;
172175
}
173176

174-
public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix) {
175-
this(name, description, dns1, dns2, dns3, dns4, domain, domainId, zoneType, zoneToken, domainSuffix, false);
177+
public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4,String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix) {
178+
this(name, description, dns1, dns2, dns3, dns4, guestCidr, domain, domainId, zoneType, zoneToken, domainSuffix, false);
176179
this.id = id;
177180
this.allocationState = Grouping.AllocationState.Enabled;
178181
this.uuid = UUID.randomUUID().toString();
179182
}
180183

181-
public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix, boolean securityGroupEnabled) {
184+
public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix, boolean securityGroupEnabled) {
182185
this.name = name;
183186
this.description = description;
184187
this.dns1 = dns1;
185188
this.dns2 = dns2;
186189
this.internalDns1 = dns3;
187190
this.internalDns2 = dns4;
191+
this.guestNetworkCidr = guestCidr;
188192
this.domain = domain;
189193
this.domainId = domainId;
190194
this.networkType = zoneType;
@@ -230,6 +234,17 @@ public void setUserDataProvider(String userDataProvider) {
230234
this.userDataProvider = userDataProvider;
231235
}
232236

237+
@Override
238+
public String getGuestNetworkCidr()
239+
{
240+
return guestNetworkCidr;
241+
}
242+
243+
public void setGuestNetworkCidr(String guestNetworkCidr)
244+
{
245+
this.guestNetworkCidr = guestNetworkCidr;
246+
}
247+
233248
@Override
234249
public Long getDomainId() {
235250
return domainId;

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,11 +2491,14 @@ public Network createGuestNetwork(long networkOfferingId, String name, String di
24912491
if (networks == null || networks.isEmpty()) {
24922492
throw new CloudRuntimeException("Fail to create a network");
24932493
} else {
2494-
if (networks.size() > 1) {
2495-
throw new InvalidParameterValueException("Cannot determine a guest network to deploy in, please specify one");
2496-
}
24972494
if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && networks.get(0).getTrafficType() == TrafficType.Guest) {
2498-
network = networks.get(0);
2495+
Network defaultGuestNetwork = networks.get(0);
2496+
for (Network nw : networks) {
2497+
if (nw.getCidr() != null && nw.getCidr().equals(zone.getGuestNetworkCidr())) {
2498+
defaultGuestNetwork = nw;
2499+
}
2500+
}
2501+
network = defaultGuestNetwork;
24992502
} else {
25002503
// For shared network
25012504
network = networks.get(0);

0 commit comments

Comments
 (0)