VPC: CS-15805 - verify vpc guest network cidr only against networks in the same vpc

This commit is contained in:
Alena Prokharchyk 2012-08-01 17:58:51 -07:00
parent 3efec6456a
commit f47d3f7b59
4 changed files with 16 additions and 12 deletions

View File

@ -1618,9 +1618,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return configs;
}
}
} else if (predefined != null && predefined.getCidr() != null && predefined.getBroadcastUri() == null) {
} else if (predefined != null && predefined.getCidr() != null && predefined.getBroadcastUri() == null && vpcId == null) {
// don't allow to have 2 networks with the same cidr in the same zone for the account
List<NetworkVO> configs = _networksDao.listBy(owner.getId(), plan.getDataCenterId(), predefined.getCidr());
List<NetworkVO> configs = _networksDao.listBy(owner.getId(), plan.getDataCenterId(), predefined.getCidr(), true);
if (configs.size() > 0) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found existing network configuration for offering " + offering + ": " + configs.get(0));

View File

@ -29,7 +29,7 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
List<NetworkVO> listBy(long accountId, long offeringId, long dataCenterId);
List<NetworkVO> listBy(long accountId, long dataCenterId, String cidr);
List<NetworkVO> listBy(long accountId, long dataCenterId, String cidr, boolean skipVpc);
List<NetworkVO> listByZoneAndGuestType(long accountId, long dataCenterId, Network.GuestType type, Boolean isSystem);

View File

@ -109,6 +109,7 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
AccountSearch.join("accounts", join, AccountSearch.entity().getId(), join.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
AccountSearch.and("datacenter", AccountSearch.entity().getDataCenterId(), Op.EQ);
AccountSearch.and("cidr", AccountSearch.entity().getCidr(), Op.EQ);
AccountSearch.and("vpcId", AccountSearch.entity().getVpcId(), Op.EQ);
AccountSearch.done();
RelatedConfigSearch = createSearchBuilder();
@ -236,11 +237,14 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
}
@Override
public List<NetworkVO> listBy(long accountId, long dataCenterId, String cidr) {
public List<NetworkVO> listBy(long accountId, long dataCenterId, String cidr, boolean skipVpc) {
SearchCriteria<NetworkVO> sc = AccountSearch.create();
sc.setJoinParameters("accounts", "account", accountId);
sc.setParameters("datacenter", dataCenterId);
sc.setParameters("cidr", cidr);
if (skipVpc) {
sc.setParameters("vpcId", (Object)null);
}
return listBy(sc);
}

View File

@ -589,14 +589,14 @@ public class VpcManagerImpl implements VpcManager, Manager{
}
//don't allow overlapping CIDRS for the VPCs of the same account
List<? extends Vpc> vpcs = getVpcsForAccount(vpcOwner.getId());
for (Vpc vpc : vpcs) {
if (NetUtils.isNetworksOverlap(cidr, vpc.getCidr())) {
throw new InvalidParameterValueException("Account already has vpc with cidr " + vpc.getCidr() +
" that overlaps the cidr specified: " + cidr, null);
}
}
// //don't allow overlapping CIDRS for the VPCs of the same account
// List<? extends Vpc> vpcs = getVpcsForAccount(vpcOwner.getId());
// for (Vpc vpc : vpcs) {
// if (NetUtils.isNetworksOverlap(cidr, vpc.getCidr())) {
// throw new InvalidParameterValueException("Account already has vpc with cidr " + vpc.getCidr() +
// " that overlaps the cidr specified: " + cidr, null);
// }
// }
Transaction txn = Transaction.currentTxn();
txn.start();