throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
Account owner = _accountMgr.getAccount(networkOwnerId);
// Get system network offeirng
NetworkOfferingVO ntwkOff = _systemNetworks.get(NetworkOffering.SystemPrivateGatewayNetworkOffering);
// Validate physical network
PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
if (pNtwk == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a physical network" +
" having the given id");
ex.addProxyObject("physical_network", physicalNetworkId, "physicalNetworkId");
throw ex;
}
// VALIDATE IP INFO
// if end ip is not specified, default it to startIp
if (!NetUtils.isValidIp(startIp)) {
throw new InvalidParameterValueException("Invalid format for the startIp parameter");
}
if (endIp == null) {
endIp = startIp;
} else if (!NetUtils.isValidIp(endIp)) {
throw new InvalidParameterValueException("Invalid format for the endIp parameter");
}
String cidr = null;
if (!NetUtils.isValidIp(gateway)) {
throw new InvalidParameterValueException("Invalid gateway");
}
if (!NetUtils.isValidNetmask(netmask)) {
throw new InvalidParameterValueException("Invalid netmask");
}
cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
Transaction txn = Transaction.currentTxn();
txn.start();
//lock datacenter as we need to get mac address seq from there
DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true);
//check if we need to create guest network
Network privateNetwork = _networksDao.getPrivateNetwork(BroadcastDomainType.Vlan.toUri(vlan).toString(), cidr,
networkOwnerId, pNtwk.getDataCenterId());
if (privateNetwork == null) {
//create Guest network
privateNetwork = createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan,
null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, null);
s_logger.debug("Created private network " + privateNetwork);
} else {
s_logger.debug("Private network already exists: " + privateNetwork);
}