You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2014/01/17 23:40:43 UTC
[41/50] [abbrv] Merge branch 'master' into rbac.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/929fbaba/server/src/com/cloud/network/IpAddressManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/IpAddressManagerImpl.java
index 2347a6e,6596074..e8de7f0
--- a/server/src/com/cloud/network/IpAddressManagerImpl.java
+++ b/server/src/com/cloud/network/IpAddressManagerImpl.java
@@@ -392,11 -387,8 +387,8 @@@ public class IpAddressManagerImpl exten
podVlanSearch.and("networkId", podVlanSearch.entity().getNetworkId(), Op.EQ);
SearchBuilder<PodVlanMapVO> podVlanMapSB = _podVlanMapDao.createSearchBuilder();
podVlanMapSB.and("podId", podVlanMapSB.entity().getPodId(), Op.EQ);
- AssignIpAddressFromPodVlanSearch.join("podVlanMapSB",
- podVlanMapSB,
- podVlanMapSB.entity().getVlanDbId(),
- AssignIpAddressFromPodVlanSearch.entity().getVlanId(),
+ AssignIpAddressFromPodVlanSearch.join("podVlanMapSB", podVlanMapSB, podVlanMapSB.entity().getVlanDbId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(),
- JoinType.INNER);
+ JoinType.INNER);
AssignIpAddressFromPodVlanSearch.join("vlan", podVlanSearch, podVlanSearch.entity().getId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER);
AssignIpAddressFromPodVlanSearch.done();
@@@ -657,134 -649,134 +649,134 @@@
}
@DB
- public PublicIp fetchNewPublicIp(final long dcId, final Long podId, final List<Long> vlanDbIds, final Account owner, final VlanType vlanUse, final Long guestNetworkId, final boolean sourceNat, final boolean assign,
- final String requestedIp, final boolean isSystem, final Long vpcId) throws InsufficientAddressCapacityException {
- IPAddressVO addr = Transaction.execute(new TransactionCallbackWithException<IPAddressVO,InsufficientAddressCapacityException>() {
+ public PublicIp fetchNewPublicIp(final long dcId, final Long podId, final List<Long> vlanDbIds, final Account owner, final VlanType vlanUse, final Long guestNetworkId,
+ final boolean sourceNat, final boolean assign, final String requestedIp, final boolean isSystem, final Long vpcId) throws InsufficientAddressCapacityException {
+ IPAddressVO addr = Transaction.execute(new TransactionCallbackWithException<IPAddressVO, InsufficientAddressCapacityException>() {
@Override
public IPAddressVO doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
- StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in ");
- boolean fetchFromDedicatedRange = false;
- List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
- List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
-
- SearchCriteria<IPAddressVO> sc = null;
- if (podId != null) {
- sc = AssignIpAddressFromPodVlanSearch.create();
- sc.setJoinParameters("podVlanMapSB", "podId", podId);
- errorMessage.append(" pod id=" + podId);
- } else {
- sc = AssignIpAddressSearch.create();
- errorMessage.append(" zone id=" + dcId);
- }
-
- // If owner has dedicated Public IP ranges, fetch IP from the dedicated range
- // Otherwise fetch IP from the system pool
- List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(owner.getId());
- for (AccountVlanMapVO map : maps) {
- if (vlanDbIds == null || vlanDbIds.contains(map.getVlanDbId()))
- dedicatedVlanDbIds.add(map.getVlanDbId());
- }
- List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(dcId);
- for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
- if (vlanDbIds == null || vlanDbIds.contains(nonDedicatedVlan.getId()))
- nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
- }
- if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
- fetchFromDedicatedRange = true;
- sc.setParameters("vlanId", dedicatedVlanDbIds.toArray());
- errorMessage.append(", vlanId id=" + dedicatedVlanDbIds.toArray());
- } else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
- sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
- errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
- } else {
- if (podId != null) {
- InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
- ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
- throw ex;
- }
- s_logger.warn(errorMessage.toString());
- InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
- ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
- throw ex;
- }
+ StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in ");
+ boolean fetchFromDedicatedRange = false;
+ List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
+ List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
+
+ SearchCriteria<IPAddressVO> sc = null;
+ if (podId != null) {
+ sc = AssignIpAddressFromPodVlanSearch.create();
+ sc.setJoinParameters("podVlanMapSB", "podId", podId);
+ errorMessage.append(" pod id=" + podId);
+ } else {
+ sc = AssignIpAddressSearch.create();
+ errorMessage.append(" zone id=" + dcId);
+ }
+
+ // If owner has dedicated Public IP ranges, fetch IP from the dedicated range
+ // Otherwise fetch IP from the system pool
+ List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(owner.getId());
+ for (AccountVlanMapVO map : maps) {
+ if (vlanDbIds == null || vlanDbIds.contains(map.getVlanDbId()))
+ dedicatedVlanDbIds.add(map.getVlanDbId());
+ }
+ List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(dcId);
+ for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
+ if (vlanDbIds == null || vlanDbIds.contains(nonDedicatedVlan.getId()))
+ nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
+ }
+ if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
+ fetchFromDedicatedRange = true;
+ sc.setParameters("vlanId", dedicatedVlanDbIds.toArray());
+ errorMessage.append(", vlanId id=" + dedicatedVlanDbIds.toArray());
+ } else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
+ sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
+ errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
+ } else {
+ if (podId != null) {
+ InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
+ ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
+ throw ex;
+ }
+ s_logger.warn(errorMessage.toString());
+ InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
+ ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
+ throw ex;
+ }
- sc.setParameters("dc", dcId);
+ sc.setParameters("dc", dcId);
- DataCenter zone = _entityMgr.findById(DataCenter.class, dcId);
+ DataCenter zone = _entityMgr.findById(DataCenter.class, dcId);
- // for direct network take ip addresses only from the vlans belonging to the network
- if (vlanUse == VlanType.DirectAttached) {
- sc.setJoinParameters("vlan", "networkId", guestNetworkId);
- errorMessage.append(", network id=" + guestNetworkId);
- }
- sc.setJoinParameters("vlan", "type", vlanUse);
+ // for direct network take ip addresses only from the vlans belonging to the network
+ if (vlanUse == VlanType.DirectAttached) {
+ sc.setJoinParameters("vlan", "networkId", guestNetworkId);
+ errorMessage.append(", network id=" + guestNetworkId);
+ }
+ sc.setJoinParameters("vlan", "type", vlanUse);
- if (requestedIp != null) {
- sc.addAnd("address", SearchCriteria.Op.EQ, requestedIp);
- errorMessage.append(": requested ip " + requestedIp + " is not available");
- }
+ if (requestedIp != null) {
+ sc.addAnd("address", SearchCriteria.Op.EQ, requestedIp);
+ errorMessage.append(": requested ip " + requestedIp + " is not available");
+ }
- Filter filter = new Filter(IPAddressVO.class, "vlanId", true, 0l, 1l);
+ Filter filter = new Filter(IPAddressVO.class, "vlanId", true, 0l, 1l);
- List<IPAddressVO> addrs = _ipAddressDao.lockRows(sc, filter, true);
+ List<IPAddressVO> addrs = _ipAddressDao.lockRows(sc, filter, true);
- // If all the dedicated IPs of the owner are in use fetch an IP from the system pool
- if (addrs.size() == 0 && fetchFromDedicatedRange) {
- // Verify if account is allowed to acquire IPs from the system
- boolean useSystemIps = UseSystemPublicIps.valueIn(owner.getId());
- if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
- fetchFromDedicatedRange = false;
- sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
- errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
- addrs = _ipAddressDao.lockRows(sc, filter, true);
- }
- }
+ // If all the dedicated IPs of the owner are in use fetch an IP from the system pool
+ if (addrs.size() == 0 && fetchFromDedicatedRange) {
+ // Verify if account is allowed to acquire IPs from the system
+ boolean useSystemIps = UseSystemPublicIps.valueIn(owner.getId());
+ if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
+ fetchFromDedicatedRange = false;
+ sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
+ errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
+ addrs = _ipAddressDao.lockRows(sc, filter, true);
+ }
+ }
- if (addrs.size() == 0) {
- if (podId != null) {
- InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
- // for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object.
- ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
- throw ex;
- }
- s_logger.warn(errorMessage.toString());
- InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
- ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
- throw ex;
- }
+ if (addrs.size() == 0) {
+ if (podId != null) {
+ InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
+ // for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object.
+ ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
+ throw ex;
+ }
+ s_logger.warn(errorMessage.toString());
+ InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
+ ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
+ throw ex;
+ }
- assert (addrs.size() == 1) : "Return size is incorrect: " + addrs.size();
+ assert (addrs.size() == 1) : "Return size is incorrect: " + addrs.size();
- if (!fetchFromDedicatedRange) {
- // Check that the maximum number of public IPs for the given accountId will not be exceeded
- try {
- _resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip);
- } catch (ResourceAllocationException ex) {
- s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner);
- throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded.");
- }
- }
+ if (!fetchFromDedicatedRange) {
+ // Check that the maximum number of public IPs for the given accountId will not be exceeded
+ try {
+ _resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip);
+ } catch (ResourceAllocationException ex) {
+ s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner);
+ throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded.");
+ }
+ }
- IPAddressVO addr = addrs.get(0);
- addr.setSourceNat(sourceNat);
- addr.setAllocatedTime(new Date());
- addr.setAllocatedInDomainId(owner.getDomainId());
- addr.setAllocatedToAccountId(owner.getId());
- addr.setSystem(isSystem);
+ IPAddressVO addr = addrs.get(0);
+ addr.setSourceNat(sourceNat);
+ addr.setAllocatedTime(new Date());
+ addr.setAllocatedInDomainId(owner.getDomainId());
+ addr.setAllocatedToAccountId(owner.getId());
+ addr.setSystem(isSystem);
- if (assign) {
- markPublicIpAsAllocated(addr);
- } else {
- addr.setState(IpAddress.State.Allocating);
- }
- addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating);
+ if (assign) {
+ markPublicIpAsAllocated(addr);
+ } else {
+ addr.setState(IpAddress.State.Allocating);
+ }
+ addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating);
- if (vlanUse != VlanType.DirectAttached) {
- addr.setAssociatedWithNetworkId(guestNetworkId);
- addr.setVpcId(vpcId);
- }
+ if (vlanUse != VlanType.DirectAttached) {
+ addr.setAssociatedWithNetworkId(guestNetworkId);
+ addr.setVpcId(vpcId);
+ }
- _ipAddressDao.update(addr.getId(), addr);
+ _ipAddressDao.update(addr.getId(), addr);
return addr;
}
@@@ -806,34 -798,26 +798,26 @@@
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
- Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId());
+ Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId());
- addr.setState(IpAddress.State.Allocated);
- _ipAddressDao.update(addr.getId(), addr);
+ addr.setState(IpAddress.State.Allocated);
+ _ipAddressDao.update(addr.getId(), addr);
- // Save usage event
- if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
- VlanVO vlan = _vlanDao.findById(addr.getVlanId());
+ // Save usage event
+ if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
+ VlanVO vlan = _vlanDao.findById(addr.getVlanId());
- String guestType = vlan.getVlanType().toString();
+ String guestType = vlan.getVlanType().toString();
- if (!isIpDedicated(addr)) {
+ if (!isIpDedicated(addr)) {
- UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN,
- owner.getId(),
- addr.getDataCenterId(),
- addr.getId(),
- addr.getAddress().toString(),
- addr.isSourceNat(),
- guestType,
- addr.getSystem(),
- addr.getClass().getName(),
- addr.getUuid());
+ UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(),
+ addr.isSourceNat(), guestType, addr.getSystem(), addr.getClass().getName(), addr.getUuid());
- }
+ }
if (updateIpResourceCount(addr)) {
- _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip);
- }
- }
+ _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip);
+ }
+ }
}
});
}
@@@ -1024,15 -1008,16 +1008,16 @@@
public PublicIp doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
PublicIp ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, null, isSystem, null);
- if (ip == null) {
+ if (ip == null) {
- InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId());
+ InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone
+ .getId());
- ex.addProxyObject(ApiDBUtils.findZoneById(zone.getId()).getUuid());
- throw ex;
- }
- CallContext.current().setEventDetails("Ip Id: " + ip.getId());
- Ip ipAddress = ip.getAddress();
+ ex.addProxyObject(ApiDBUtils.findZoneById(zone.getId()).getUuid());
+ throw ex;
+ }
+ CallContext.current().setEventDetails("Ip Id: " + ip.getId());
+ Ip ipAddress = ip.getAddress();
- s_logger.debug("Got " + ipAddress + " to assign for account " + ipOwner.getId() + " in zone " + zone.getId());
+ s_logger.debug("Got " + ipAddress + " to assign for account " + ipOwner.getId() + " in zone " + zone.getId());
return ip;
}
@@@ -1066,59 -1051,43 +1051,43 @@@
public IPAddressVO doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
PortableIpVO allocatedPortableIp;
- List<PortableIpVO> portableIpVOs = _portableIpDao.listByRegionIdAndState(1, PortableIp.State.Free);
- if (portableIpVOs == null || portableIpVOs.isEmpty()) {
+ List<PortableIpVO> portableIpVOs = _portableIpDao.listByRegionIdAndState(1, PortableIp.State.Free);
+ if (portableIpVOs == null || portableIpVOs.isEmpty()) {
- InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available portable IP addresses", Region.class, new Long(1));
+ InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available portable IP addresses", Region.class,
+ new Long(1));
- throw ex;
- }
+ throw ex;
+ }
- // allocate first portable IP to the user
- allocatedPortableIp = portableIpVOs.get(0);
- allocatedPortableIp.setAllocatedTime(new Date());
- allocatedPortableIp.setAllocatedToAccountId(ipOwner.getAccountId());
- allocatedPortableIp.setAllocatedInDomainId(ipOwner.getDomainId());
- allocatedPortableIp.setState(PortableIp.State.Allocated);
- _portableIpDao.update(allocatedPortableIp.getId(), allocatedPortableIp);
-
- // To make portable IP available as a zone level resource we need to emulate portable IP's (which are
- // provisioned at region level) as public IP provisioned in a zone. user_ip_address and vlan combo give the
- // identity of a public IP in zone. Create entry for portable ip in these tables.
-
- // provision portable IP range VLAN into the zone
- long physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public).getId();
- Network network = _networkModel.getSystemNetworkByZoneAndTrafficType(dcId, TrafficType.Public);
- String range = allocatedPortableIp.getAddress() + "-" + allocatedPortableIp.getAddress();
+ // allocate first portable IP to the user
+ allocatedPortableIp = portableIpVOs.get(0);
+ allocatedPortableIp.setAllocatedTime(new Date());
+ allocatedPortableIp.setAllocatedToAccountId(ipOwner.getAccountId());
+ allocatedPortableIp.setAllocatedInDomainId(ipOwner.getDomainId());
+ allocatedPortableIp.setState(PortableIp.State.Allocated);
+ _portableIpDao.update(allocatedPortableIp.getId(), allocatedPortableIp);
+
+ // To make portable IP available as a zone level resource we need to emulate portable IP's (which are
+ // provisioned at region level) as public IP provisioned in a zone. user_ip_address and vlan combo give the
+ // identity of a public IP in zone. Create entry for portable ip in these tables.
+
+ // provision portable IP range VLAN into the zone
+ long physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public).getId();
+ Network network = _networkModel.getSystemNetworkByZoneAndTrafficType(dcId, TrafficType.Public);
+ String range = allocatedPortableIp.getAddress() + "-" + allocatedPortableIp.getAddress();
- VlanVO vlan = new VlanVO(VlanType.VirtualNetwork,
- allocatedPortableIp.getVlan(),
- allocatedPortableIp.getGateway(),
- allocatedPortableIp.getNetmask(),
- dcId,
- range,
- network.getId(),
- physicalNetworkId,
- null,
- null,
- null);
+ VlanVO vlan = new VlanVO(VlanType.VirtualNetwork, allocatedPortableIp.getVlan(), allocatedPortableIp.getGateway(), allocatedPortableIp.getNetmask(), dcId,
+ range, network.getId(), physicalNetworkId, null, null, null);
- vlan = _vlanDao.persist(vlan);
+ vlan = _vlanDao.persist(vlan);
- // provision the portable IP in to user_ip_address table
+ // provision the portable IP in to user_ip_address table
IPAddressVO ipaddr = new IPAddressVO(new Ip(allocatedPortableIp.getAddress()), dcId, networkId, vpcID, physicalNetworkId, network.getId(), vlan.getId(), true);
- ipaddr.setState(State.Allocated);
- ipaddr.setAllocatedTime(new Date());
- ipaddr.setAllocatedInDomainId(ipOwner.getDomainId());
- ipaddr.setAllocatedToAccountId(ipOwner.getId());
- ipaddr = _ipAddressDao.persist(ipaddr);
+ ipaddr.setState(State.Allocated);
+ ipaddr.setAllocatedTime(new Date());
+ ipaddr.setAllocatedInDomainId(ipOwner.getDomainId());
+ ipaddr.setAllocatedToAccountId(ipOwner.getId());
+ ipaddr = _ipAddressDao.persist(ipaddr);
- UsageEventUtils.publishUsageEvent(EventTypes.EVENT_PORTABLE_IP_ASSIGN,
- ipaddr.getId(),
- ipaddr.getDataCenterId(),
- ipaddr.getId(),
- ipaddr.getAddress().toString(),
- ipaddr.isSourceNat(),
- null,
- ipaddr.getSystem(),
- ipaddr.getClass().getName(),
- ipaddr.getUuid());
+ UsageEventUtils.publishUsageEvent(EventTypes.EVENT_PORTABLE_IP_ASSIGN, ipaddr.getId(), ipaddr.getDataCenterId(), ipaddr.getId(),
+ ipaddr.getAddress().toString(), ipaddr.isSourceNat(), null, ipaddr.getSystem(), ipaddr.getClass().getName(), ipaddr.getUuid());
return ipaddr;
}
@@@ -1475,14 -1446,10 +1446,10 @@@
}
});
-
// trigger an action event for the transfer of portable IP across the networks, so that external entities
// monitoring for this event can initiate the route advertisement for the availability of IP from the zoe
- ActionEventUtils.onActionEvent(User.UID_SYSTEM,
- Account.ACCOUNT_ID_SYSTEM,
- Domain.ROOT_DOMAIN,
- EventTypes.EVENT_PORTABLE_IP_TRANSFER,
+ ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, Domain.ROOT_DOMAIN, EventTypes.EVENT_PORTABLE_IP_TRANSFER,
- "Portable IP associated is transferred from network " + currentNetworkId + " to " + newNetworkId);
+ "Portable IP associated is transferred from network " + currentNetworkId + " to " + newNetworkId);
}
protected List<? extends Network> getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner) {
@@@ -1508,92 -1476,77 +1476,77 @@@
boolean createNetwork = false;
Network guestNetwork = guestNetworkFinal;
- if (guestNetwork == null) {
- List<? extends Network> networks = getIsolatedNetworksWithSourceNATOwnedByAccountInZone(zoneId, owner);
- if (networks.size() == 0) {
- createNetwork = true;
- } else if (networks.size() == 1) {
- guestNetwork = networks.get(0);
- } else {
- throw new InvalidParameterValueException("Error, more than 1 Guest Isolated Networks with SourceNAT "
- + "service enabled found for this account, cannot assosiate the IP range, please provide the network ID");
- }
- }
+ if (guestNetwork == null) {
+ List<? extends Network> networks = getIsolatedNetworksWithSourceNATOwnedByAccountInZone(zoneId, owner);
+ if (networks.size() == 0) {
+ createNetwork = true;
+ } else if (networks.size() == 1) {
+ guestNetwork = networks.get(0);
+ } else {
+ throw new InvalidParameterValueException("Error, more than 1 Guest Isolated Networks with SourceNAT "
+ + "service enabled found for this account, cannot assosiate the IP range, please provide the network ID");
+ }
+ }
- // create new Virtual network (Isolated with SourceNAT) for the user if it doesn't exist
- List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
- if (requiredOfferings.size() < 1) {
+ // create new Virtual network (Isolated with SourceNAT) for the user if it doesn't exist
+ List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
+ if (requiredOfferings.size() < 1) {
- throw new CloudRuntimeException("Unable to find network offering with availability=" + Availability.Required +
- " to automatically create the network as part of createVlanIpRange");
+ throw new CloudRuntimeException("Unable to find network offering with availability=" + Availability.Required
+ + " to automatically create the network as part of createVlanIpRange");
- }
- if (createNetwork) {
- if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
- long physicalNetworkId = _networkModel.findPhysicalNetworkId(zoneId, requiredOfferings.get(0).getTags(), requiredOfferings.get(0).getTrafficType());
- // Validate physical network
- PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
- if (physicalNetwork == null) {
+ }
+ if (createNetwork) {
+ if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
+ long physicalNetworkId = _networkModel.findPhysicalNetworkId(zoneId, requiredOfferings.get(0).getTags(), requiredOfferings.get(0).getTrafficType());
+ // Validate physical network
+ PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+ if (physicalNetwork == null) {
- throw new InvalidParameterValueException("Unable to find physical network with id: " + physicalNetworkId + " and tag: " + requiredOfferings.get(0).getTags());
- }
-
- s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId() +
- " as a part of createVlanIpRange process");
- guestNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(),
- owner.getAccountName() + "-network",
- owner.getAccountName() + "-network",
- null,
- null,
- null,
- null,
- owner,
- null,
- physicalNetwork,
- zoneId,
- ACLType.Account,
- null,
- null,
- null,
- null,
- true,
- null);
+ throw new InvalidParameterValueException("Unable to find physical network with id: " + physicalNetworkId + " and tag: "
+ + requiredOfferings.get(0).getTags());
+ }
+
+ s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId()
+ + " as a part of createVlanIpRange process");
+ guestNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName()
+ + "-network", null, null, null, null, owner, null, physicalNetwork, zoneId, ACLType.Account, null, null, null, null, true, null);
- if (guestNetwork == null) {
- s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId);
+ if (guestNetwork == null) {
+ s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId);
- throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT " +
- "service enabled as a part of createVlanIpRange, for the account " + accountId + "in zone " + zoneId);
+ throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT "
+ + "service enabled as a part of createVlanIpRange, for the account " + accountId + "in zone " + zoneId);
- }
- } else {
- throw new CloudRuntimeException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled);
- }
- }
+ }
+ } else {
+ throw new CloudRuntimeException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled);
+ }
+ }
- // Check if there is a source nat ip address for this account; if not - we have to allocate one
- boolean allocateSourceNat = false;
- List<IPAddressVO> sourceNat = _ipAddressDao.listByAssociatedNetwork(guestNetwork.getId(), true);
- if (sourceNat.isEmpty()) {
- allocateSourceNat = true;
- }
+ // Check if there is a source nat ip address for this account; if not - we have to allocate one
+ boolean allocateSourceNat = false;
+ List<IPAddressVO> sourceNat = _ipAddressDao.listByAssociatedNetwork(guestNetwork.getId(), true);
+ if (sourceNat.isEmpty()) {
+ allocateSourceNat = true;
+ }
- // update all ips with a network id, mark them as allocated and update resourceCount/usage
- List<IPAddressVO> ips = _ipAddressDao.listByVlanId(vlanId);
- boolean isSourceNatAllocated = false;
- for (IPAddressVO addr : ips) {
- if (addr.getState() != State.Allocated) {
- if (!isSourceNatAllocated && allocateSourceNat) {
- addr.setSourceNat(true);
- isSourceNatAllocated = true;
- } else {
- addr.setSourceNat(false);
- }
- addr.setAssociatedWithNetworkId(guestNetwork.getId());
- addr.setVpcId(guestNetwork.getVpcId());
- addr.setAllocatedTime(new Date());
- addr.setAllocatedInDomainId(owner.getDomainId());
- addr.setAllocatedToAccountId(owner.getId());
- addr.setSystem(false);
- addr.setState(IpAddress.State.Allocating);
- markPublicIpAsAllocated(addr);
- }
- }
+ // update all ips with a network id, mark them as allocated and update resourceCount/usage
+ List<IPAddressVO> ips = _ipAddressDao.listByVlanId(vlanId);
+ boolean isSourceNatAllocated = false;
+ for (IPAddressVO addr : ips) {
+ if (addr.getState() != State.Allocated) {
+ if (!isSourceNatAllocated && allocateSourceNat) {
+ addr.setSourceNat(true);
+ isSourceNatAllocated = true;
+ } else {
+ addr.setSourceNat(false);
+ }
+ addr.setAssociatedWithNetworkId(guestNetwork.getId());
+ addr.setVpcId(guestNetwork.getVpcId());
+ addr.setAllocatedTime(new Date());
+ addr.setAllocatedInDomainId(owner.getDomainId());
+ addr.setAllocatedToAccountId(owner.getId());
+ addr.setSystem(false);
+ addr.setState(IpAddress.State.Allocating);
+ markPublicIpAsAllocated(addr);
+ }
+ }
- return new Ternary<Boolean,List<NetworkOfferingVO>, Network>(createNetwork, requiredOfferings, guestNetwork);
+ return new Ternary<Boolean, List<NetworkOfferingVO>, Network>(createNetwork, requiredOfferings, guestNetwork);
}
});
} catch (Exception e1) {
@@@ -1648,28 -1601,20 +1601,20 @@@
@Override
public IPAddressVO doInTransaction(TransactionStatus status) {
if (updateIpResourceCount(ip)) {
- _resourceLimitMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAllocatedToAccountId(), ResourceType.public_ip);
- }
+ _resourceLimitMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAllocatedToAccountId(), ResourceType.public_ip);
+ }
- // Save usage event
- if (ip.getAllocatedToAccountId() != null && ip.getAllocatedToAccountId() != Account.ACCOUNT_ID_SYSTEM) {
- VlanVO vlan = _vlanDao.findById(ip.getVlanId());
+ // Save usage event
+ if (ip.getAllocatedToAccountId() != null && ip.getAllocatedToAccountId() != Account.ACCOUNT_ID_SYSTEM) {
+ VlanVO vlan = _vlanDao.findById(ip.getVlanId());
- String guestType = vlan.getVlanType().toString();
- if (!isIpDedicated(ip)) {
- String eventType = ip.isPortable() ? EventTypes.EVENT_PORTABLE_IP_RELEASE : EventTypes.EVENT_NET_IP_RELEASE;
+ String guestType = vlan.getVlanType().toString();
+ if (!isIpDedicated(ip)) {
+ String eventType = ip.isPortable() ? EventTypes.EVENT_PORTABLE_IP_RELEASE : EventTypes.EVENT_NET_IP_RELEASE;
- UsageEventUtils.publishUsageEvent(eventType,
- ip.getAllocatedToAccountId(),
- ip.getDataCenterId(),
- addrId,
- ip.getAddress().addr(),
- ip.isSourceNat(),
- guestType,
- ip.getSystem(),
- ip.getClass().getName(),
- ip.getUuid());
+ UsageEventUtils.publishUsageEvent(eventType, ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), ip.isSourceNat(),
+ guestType, ip.getSystem(), ip.getClass().getName(), ip.getUuid());
- }
- }
+ }
+ }
return _ipAddressDao.markAsUnavailable(addrId);
}
@@@ -1863,67 -1811,70 +1811,70 @@@
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientAddressCapacityException>() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) throws InsufficientAddressCapacityException {
- //This method allocates direct ip for the Shared network in Advance zones
- boolean ipv4 = false;
-
- if (network.getGateway() != null) {
- if (nic.getIp4Address() == null) {
- ipv4 = true;
- PublicIp ip = null;
-
- //Get ip address from the placeholder and don't allocate a new one
- if (requestedIpv4 != null && vm.getType() == VirtualMachine.Type.DomainRouter) {
- Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);
- if (placeholderNic != null) {
- IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIp4Address());
- ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
- s_logger.debug("Nic got an ip address " + placeholderNic.getIp4Address() + " stored in placeholder nic for the network " + network);
- }
- }
+ //This method allocates direct ip for the Shared network in Advance zones
+ boolean ipv4 = false;
+
+ if (network.getGateway() != null) {
+ if (nic.getIp4Address() == null) {
+ ipv4 = true;
+ PublicIp ip = null;
+
+ //Get ip address from the placeholder and don't allocate a new one
+ if (requestedIpv4 != null && vm.getType() == VirtualMachine.Type.DomainRouter) {
+ Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);
+ if (placeholderNic != null) {
+ IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIp4Address());
+ ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
+ s_logger.debug("Nic got an ip address " + placeholderNic.getIp4Address() + " stored in placeholder nic for the network " + network);
+ }
+ }
- if (ip == null) {
- ip = assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIpv4, false);
- }
+ if (ip == null) {
+ ip = assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIpv4, false);
+ }
- nic.setIp4Address(ip.getAddress().toString());
- nic.setGateway(ip.getGateway());
- nic.setNetmask(ip.getNetmask());
- nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
- //nic.setBroadcastType(BroadcastDomainType.Vlan);
- //nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
- nic.setBroadcastType(network.getBroadcastDomainType());
+ nic.setIp4Address(ip.getAddress().toString());
+ nic.setGateway(ip.getGateway());
+ nic.setNetmask(ip.getNetmask());
+ nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
+ //nic.setBroadcastType(BroadcastDomainType.Vlan);
+ //nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
+ nic.setBroadcastType(network.getBroadcastDomainType());
+ if (network.getBroadcastUri() != null)
- nic.setBroadcastUri(network.getBroadcastUri());
+ nic.setBroadcastUri(network.getBroadcastUri());
+ else
+ nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
- nic.setFormat(AddressFormat.Ip4);
- nic.setReservationId(String.valueOf(ip.getVlanTag()));
- nic.setMacAddress(ip.getMacAddress());
- }
- nic.setDns1(dc.getDns1());
- nic.setDns2(dc.getDns2());
- }
-
- //FIXME - get ipv6 address from the placeholder if it's stored there
- if (network.getIp6Gateway() != null) {
- if (nic.getIp6Address() == null) {
- UserIpv6Address ip = _ipv6Mgr.assignDirectIp6Address(dc.getId(), vm.getOwner(), network.getId(), requestedIpv6);
- Vlan vlan = _vlanDao.findById(ip.getVlanId());
- nic.setIp6Address(ip.getAddress().toString());
- nic.setIp6Gateway(vlan.getIp6Gateway());
- nic.setIp6Cidr(vlan.getIp6Cidr());
- if (ipv4) {
- nic.setFormat(AddressFormat.DualStack);
- } else {
- nic.setIsolationUri(IsolationType.Vlan.toUri(vlan.getVlanTag()));
- nic.setBroadcastType(BroadcastDomainType.Vlan);
- nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlan.getVlanTag()));
- nic.setFormat(AddressFormat.Ip6);
- nic.setReservationId(String.valueOf(vlan.getVlanTag()));
- nic.setMacAddress(ip.getMacAddress());
- }
- }
- nic.setIp6Dns1(dc.getIp6Dns1());
- nic.setIp6Dns2(dc.getIp6Dns2());
+ nic.setFormat(AddressFormat.Ip4);
+ nic.setReservationId(String.valueOf(ip.getVlanTag()));
+ nic.setMacAddress(ip.getMacAddress());
+ }
+ nic.setDns1(dc.getDns1());
+ nic.setDns2(dc.getDns2());
+ }
+
+ //FIXME - get ipv6 address from the placeholder if it's stored there
+ if (network.getIp6Gateway() != null) {
+ if (nic.getIp6Address() == null) {
+ UserIpv6Address ip = _ipv6Mgr.assignDirectIp6Address(dc.getId(), vm.getOwner(), network.getId(), requestedIpv6);
+ Vlan vlan = _vlanDao.findById(ip.getVlanId());
+ nic.setIp6Address(ip.getAddress().toString());
+ nic.setIp6Gateway(vlan.getIp6Gateway());
+ nic.setIp6Cidr(vlan.getIp6Cidr());
+ if (ipv4) {
+ nic.setFormat(AddressFormat.DualStack);
+ } else {
+ nic.setIsolationUri(IsolationType.Vlan.toUri(vlan.getVlanTag()));
+ nic.setBroadcastType(BroadcastDomainType.Vlan);
+ nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlan.getVlanTag()));
+ nic.setFormat(AddressFormat.Ip6);
+ nic.setReservationId(String.valueOf(vlan.getVlanTag()));
+ nic.setMacAddress(ip.getMacAddress());
}
}
+ nic.setIp6Dns1(dc.getIp6Dns1());
+ nic.setIp6Dns2(dc.getIp6Dns2());
+ }
+ }
});
}