if (!canHandle(offering, dc.getNetworkType(), physnet)) {
return null;
}
NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(),
State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId());
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
(userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
throw new InvalidParameterValueException("cidr and gateway must be specified together.");
}
if (userSpecified.getCidr() != null) {
network.setCidr(userSpecified.getCidr());
network.setGateway(userSpecified.getGateway());
} else {
String guestNetworkCidr = dc.getGuestNetworkCidr();
if (guestNetworkCidr != null) {
String[] cidrTuple = guestNetworkCidr.split("\\/");
network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
network.setCidr(guestNetworkCidr);
} else if (dc.getNetworkType() == NetworkType.Advanced) {
throw new CloudRuntimeException("Can't design network " + network + "; guest CIDR is not configured per zone " + dc);
}
}
if (offering.getSpecifyVlan()) {
network.setBroadcastUri(userSpecified.getBroadcastUri());
network.setState(State.Setup);
}
} else {
String guestNetworkCidr = dc.getGuestNetworkCidr();
if (guestNetworkCidr == null && dc.getNetworkType() == NetworkType.Advanced) {
throw new CloudRuntimeException("Can't design network " + network + "; guest CIDR is not configured per zone " + dc);
}
String[] cidrTuple = guestNetworkCidr.split("\\/");
network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
network.setCidr(guestNetworkCidr);
}
return network;
}