diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java index 6a300a5170e..debf66aa75d 100644 --- a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java @@ -380,7 +380,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl IPAddressVO sourceNatIp = null; if (!sharedSourceNat) { // Get the source NAT IP address for this network - List sourceNatIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(network.getAccountId(), zoneId, true, null); + List sourceNatIps = _networkMgr.listPublicIpsAssignedToGuestNtwk(network.getAccountId(), zoneId, true, null); if (sourceNatIps.size() != 1) { String errorMsg = "External firewall was unable to find the source NAT IP address for account " + account.getAccountName(); diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index bdd07175b5b..6d3d44c98d8 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -42,6 +42,7 @@ import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.StaticNat; +import com.cloud.network.vpc.Vpc; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.user.Account; @@ -77,17 +78,6 @@ public interface NetworkManager extends NetworkService { PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException; - /** - * assigns a source nat ip address to an account within a network. - * - * @param owner - * @param network - * @param callerId - * @return - * @throws ConcurrentOperationException - * @throws InsufficientAddressCapacityException - */ - PublicIp assignSourceNatIpAddress(Account owner, Network network, long callerId) throws ConcurrentOperationException, InsufficientAddressCapacityException; /** * Do all of the work of releasing public ip addresses. Note that if this method fails, there can be side effects. @@ -113,7 +103,7 @@ public interface NetworkManager extends NetworkService { * TODO * @return - list of IP addresses */ - List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId); + List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId); List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) throws ConcurrentOperationException; @@ -314,4 +304,23 @@ public interface NetworkManager extends NetworkService { * @return */ NetworkElement getElementImplementingProvider(String providerName); + + /** + * @param owner + * @param guestNetwork + * @return + * @throws ConcurrentOperationException + * @throws InsufficientAddressCapacityException + */ + PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException; + + + /** + * @param owner + * @param vpc + * @return + * @throws ConcurrentOperationException + * @throws InsufficientAddressCapacityException + */ + PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 2150d7e32db..8c14e15c101 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -149,6 +149,7 @@ import com.cloud.network.rules.StaticNat; import com.cloud.network.rules.StaticNatRule; import com.cloud.network.rules.StaticNatRuleImpl; import com.cloud.network.rules.dao.PortForwardingRulesDao; +import com.cloud.network.vpc.Vpc; import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; @@ -354,11 +355,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException { - return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isSystem); + return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isSystem, null); } @DB - public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem) + public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, + Long guestNetworkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem, Long vpcId) throws InsufficientAddressCapacityException { StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in "); Transaction txn = Transaction.currentTxn(); @@ -384,8 +386,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // for direct network take ip addresses only from the vlans belonging to the network if (vlanUse == VlanType.DirectAttached) { - sc.setJoinParameters("vlan", "networkId", networkId); - errorMessage.append(", network id=" + networkId); + sc.setJoinParameters("vlan", "networkId", guestNetworkId); + errorMessage.append(", network id=" + guestNetworkId); } sc.setJoinParameters("vlan", "type", vlanUse); @@ -423,7 +425,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating); if (vlanUse != VlanType.DirectAttached || zone.getNetworkType() == NetworkType.Basic) { - addr.setAssociatedWithNetworkId(networkId); + addr.setAssociatedWithNetworkId(guestNetworkId); + addr.setVpcId(vpcId); } _ipAddressDao.update(addr.getId(), addr); @@ -468,17 +471,80 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.commit(); } - + + @Override + public PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { + long dcId = vpc.getZoneId(); + + List addrs = listPublicIpsAssignedToVpc(owner.getId(), true, vpc.getId()); + + PublicIp ipToReturn = null; + if (!addrs.isEmpty()) { + IPAddressVO sourceNatIp = null; + // Account already has ip addresses + for (IPAddressVO addr : addrs) { + if (addr.isSourceNat()) { + sourceNatIp = addr; + break; + } + } + + assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + + "account=" + owner.getId() + "; vpc=" + vpc; + ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress())); + } else { + ipToReturn = assignSourceNatIpAddress(owner, null, vpc.getId(), dcId); + } + + return ipToReturn; + } + + @Override + public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException { + assert (guestNetwork.getTrafficType() != null) : "You're asking for a source nat but your network " + + "can't participate in source nat. What do you have to say for yourself?"; + long dcId = guestNetwork.getDataCenterId(); + List addrs = listPublicIpsAssignedToGuestNtwk(owner.getId(), dcId, null, guestNetwork.getId()); + + PublicIp ipToReturn = null; + if (!addrs.isEmpty()) { + IPAddressVO sourceNatIp = null; + // Account already has ip addresses + for (IPAddressVO addr : addrs) { + if (addr.isSourceNat()) { + sourceNatIp = addr; + break; + } + } + + assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + + "account=" + owner.getId() + "; guestNetwork=" + guestNetwork; + ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress())); + } else { + ipToReturn = assignSourceNatIpAddress(owner, guestNetwork.getId(), null, dcId); + } + + return ipToReturn; + } + @DB - public PublicIp assignSourceNatIpAddress(Account owner, Network network, long callerId) throws ConcurrentOperationException, InsufficientAddressCapacityException { - assert (network.getTrafficType() != null) : "You're asking for a source nat but your network can't participate in source nat. What do you have to say for yourself?"; + public PublicIp assignSourceNatIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId) + throws ConcurrentOperationException, InsufficientAddressCapacityException { - long dcId = network.getDataCenterId(); long ownerId = owner.getId(); - + + // 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."); + } + PublicIp ip = null; - Transaction txn = Transaction.currentTxn(); try { txn.start(); @@ -493,52 +559,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (s_logger.isDebugEnabled()) { s_logger.debug("lock account " + ownerId + " is acquired"); } - - IPAddressVO sourceNat = null; - List addrs = listPublicIpAddressesInVirtualNetwork(ownerId, dcId, null, network.getId()); - if (addrs.size() == 0) { - - // 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 (s_logger.isDebugEnabled()) { - s_logger.debug("assigning a new ip address in " + dcId + " to " + owner); - } - - // If account has Account specific ip ranges, try to allocate ip from there - Long vlanId = null; - List maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ownerId); - if (maps != null && !maps.isEmpty()) { - //check if the ips from this vlan are associated with this network - List ips = _ipAddressDao.listByVlanId(maps.get(0).getVlanDbId()); - if (ips != null && !ips.isEmpty() && ips.get(0).getAssociatedWithNetworkId() == network.getId()) { - vlanId = maps.get(0).getVlanDbId(); - } - } - - ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, network.getId(), true, false, null, false); - sourceNat = ip.ip(); - - markPublicIpAsAllocated(sourceNat); - _ipAddressDao.update(sourceNat.getId(), sourceNat); - } else { - // Account already has ip addresses - for (IPAddressVO addr : addrs) { - if (addr.isSourceNat()) { - sourceNat = addr; - break; - } - } - - assert (sourceNat != null) : "How do we get a bunch of ip addresses but none of them are source nat? account=" + ownerId + "; dc=" + dcId; - ip = new PublicIp(sourceNat, _vlanDao.findById(sourceNat.getVlanId()), NetUtils.createSequenceBasedMacAddress(sourceNat.getMacAddress())); + + // If account has Account specific ip ranges, try to allocate ip from there + Long vlanId = null; + List maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ownerId); + if (maps != null && !maps.isEmpty()) { + vlanId = maps.get(0).getVlanDbId(); } + + ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, guestNtwkId, + true, false, null, false, vpcId); + IPAddressVO sourceNatIp = ip.ip(); + + markPublicIpAsAllocated(sourceNatIp); + _ipAddressDao.update(sourceNatIp.getId(), sourceNatIp); + txn.commit(); return ip; } finally { @@ -1013,8 +1049,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // Check that network belongs to IP owner - skip this check for Basic zone as there is just one guest network, -// and it - // belongs to the system + // and it belongs to the system if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != ipOwner.getId()) { throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP"); } @@ -1060,14 +1095,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!sharedSourceNat) { // First IP address should be source nat when it's being associated with Guest Virtual network - List addrs = listPublicIpAddressesInVirtualNetwork(ownerId, zone.getId(), true, networkId); + List addrs = listPublicIpsAssignedToGuestNtwk(ownerId, zone.getId(), true, networkId); if (addrs.isEmpty() && network.getGuestType() == Network.GuestType.Isolated) { isSourceNat = true; } } - ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), isSourceNat, assign, null, isSystem); + ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), + isSourceNat, assign, null, isSystem, network.getVpcId()); if (ip == null) { InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId()); @@ -1343,6 +1379,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag IpAddressSearch = _ipAddressDao.createSearchBuilder(); IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ); IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ); + IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ); IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ); SearchBuilder virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ); @@ -1414,7 +1451,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { + public List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { SearchCriteria sc = IpAddressSearch.create(); sc.setParameters("accountId", accountId); sc.setParameters("dataCenterId", dcId); @@ -1429,6 +1466,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return _ipAddressDao.search(sc, null); } + + protected List listPublicIpsAssignedToVpc(long accountId, Boolean sourceNat, long vpcId) { + SearchCriteria sc = IpAddressSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("vpcId", vpcId); + + if (sourceNat != null) { + sc.addAnd("sourceNat", SearchCriteria.Op.EQ, sourceNat); + } + sc.setJoinParameters("virtualNetworkVlanSB", "vlanType", VlanType.VirtualNetwork); + + return _ipAddressDao.search(sc, null); + } @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) @@ -1613,7 +1663,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nics.add(vo); Integer networkRate = getNetworkRate(config.getId(), vm.getId()); - vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network.first()), getNetworkTag(vm.getHypervisorType(), + vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, + isSecurityGroupSupportedInNetwork(network.first()), getNetworkTag(vm.getHypervisorType(), network.first()))); } @@ -1795,7 +1846,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (ips.isEmpty()) { s_logger.debug("Creating a source nat ip for " + network); Account owner = _accountMgr.getAccount(network.getAccountId()); - assignSourceNatIpAddress(owner, network, context.getCaller().getId()); + assignSourceNatIpAddressToGuestNetwork(owner, network); } } diff --git a/server/src/com/cloud/network/addr/PublicIp.java b/server/src/com/cloud/network/addr/PublicIp.java index 5322674e19b..11948e5c836 100644 --- a/server/src/com/cloud/network/addr/PublicIp.java +++ b/server/src/com/cloud/network/addr/PublicIp.java @@ -180,4 +180,20 @@ public class PublicIp implements PublicIpAddress { public boolean getSystem() { return _addr.getSystem(); } + + /* (non-Javadoc) + * @see com.cloud.network.IpAddress#getVpcId() + */ + @Override + public Long getVpcId() { + return _addr.getVpcId(); + } + + /* (non-Javadoc) + * @see com.cloud.network.IpAddress#setVpcId(java.lang.Long) + */ + @Override + public void setVpcId(Long vpcId) { + _addr.setVpcId(vpcId); + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f8f87d8752d..2f4a1157a20 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1249,9 +1249,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //3) Deploy Virtual Router(s) try { int count = routerCount - routers.size(); + PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, guestNetwork, isRedundant, - vrProvider, offeringId); + vrProvider, offeringId, sourceNatIp); routers.add(router); } } finally { @@ -1264,7 +1265,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean setupPublicNetwork, Network guestNetwork, boolean isRedundant, - VirtualRouterProvider vrProvider, long svcOffId) throws ConcurrentOperationException, + VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1275,7 +1276,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //1) Create router networks List> networks = createRouterNetworks(owner, setupPublicNetwork, guestNetwork, - isRedundant, plan); + isRedundant, plan, sourceNatIp); ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId); @@ -1365,38 +1366,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } protected List> createRouterNetworks(Account owner, boolean setupPublicNetwork, - Network guestNetwork, boolean isRedundant, DeploymentPlan plan) throws ConcurrentOperationException, + Network guestNetwork, boolean isRedundant, DeploymentPlan plan, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException { //Form networks - //1) Public network List> networks = new ArrayList>(3); - if (setupPublicNetwork) { - s_logger.debug("Adding nic for Virtual Router in Public network "); - //if source nat service is supported by the network, get the source nat ip address - PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddress(owner, guestNetwork, _accountMgr.getSystemUser().getId()); - NicProfile defaultNic = new NicProfile(); - defaultNic.setDefaultNic(true); - defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); - defaultNic.setGateway(sourceNatIp.getGateway()); - defaultNic.setNetmask(sourceNatIp.getNetmask()); - defaultNic.setMacAddress(sourceNatIp.getMacAddress()); - defaultNic.setBroadcastType(BroadcastDomainType.Vlan); - defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setDeviceId(2); - NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); - List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); - networks.add(new Pair(publicNetworks.get(0), defaultNic)); - } - - //2) Control network - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - s_logger.debug("Adding nic for Virtual Router in Control network "); - networks.add(new Pair(controlConfig, null)); - //3) Guest network + //1) Guest network if (guestNetwork != null) { String defaultNetworkStartIp = null; s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); @@ -1409,6 +1384,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian " is already allocated, can't use it for domain router; will get random ip address from the range"); } } + + NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); if (setupPublicNetwork) { @@ -1428,6 +1405,31 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); } + + //2) Control network + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + s_logger.debug("Adding nic for Virtual Router in Control network "); + networks.add(new Pair(controlConfig, null)); + + //3) Public network + if (setupPublicNetwork) { + s_logger.debug("Adding nic for Virtual Router in Public network "); + //if source nat service is supported by the network, get the source nat ip address + NicProfile defaultNic = new NicProfile(); + defaultNic.setDefaultNic(true); + defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); + defaultNic.setGateway(sourceNatIp.getGateway()); + defaultNic.setNetmask(sourceNatIp.getNetmask()); + defaultNic.setMacAddress(sourceNatIp.getMacAddress()); + defaultNic.setBroadcastType(BroadcastDomainType.Vlan); + defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); + defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); + NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); + List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); + networks.add(new Pair(publicNetworks.get(0), defaultNic)); + } return networks; } @@ -1566,6 +1568,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId()); + _dcDao.loadDetails(dc); //1) Set router details DomainRouterVO router = profile.getVirtualMachine(); @@ -1848,7 +1851,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian long ownerId = router.getAccountId(); long zoneId = router.getDataCenterIdToDeployIn(); - final List userIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId, zoneId, null, guestNetworkId); + final List userIps = _networkMgr.listPublicIpsAssignedToGuestNtwk(ownerId, zoneId, null, guestNetworkId); List allPublicIps = new ArrayList(); if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index e2287a58f35..55b6070459e 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -27,6 +27,7 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.VirtualRouterProvider; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; +import com.cloud.network.addr.PublicIp; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; @@ -65,6 +66,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian Map params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + s_logger.debug("Deploying Virtual Router in VPC "+ vpc); Vpc vpcLock = _vpcDao.acquireInLockTable(vpc.getId()); if (vpcLock == null) { throw new ConcurrentOperationException("Unable to lock vpc " + vpc.getId()); @@ -89,8 +91,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian try { //FIXME - remove hardcoded provider type when decide if we want cross physical networks vpcs VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(1, VirtualRouterProviderType.VirtualRouter); + + PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, - vrProvider, offeringId); + vrProvider, offeringId, sourceNatIp); routers.add(router); } finally { diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 7fb6bc646ce..5241057a516 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -31,17 +31,19 @@ import com.cloud.deploy.DeployDestination; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.UnsupportedServiceException; +import com.cloud.network.IPAddressVO; import com.cloud.network.Network; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; +import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.NetworkDao; -import com.cloud.network.element.NetworkElement; import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.network.vpc.Dao.VpcDao; @@ -641,6 +643,6 @@ public class VpcManagerImpl implements VpcManager, Manager{ throw new CloudRuntimeException("Failed to start vpc " + vpc); //FIXME - add cleanup logic here } - } + } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 323e85df475..5ebc85bdac7 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -180,7 +180,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override - public PublicIp assignSourceNatIpAddress(Account owner, Network network, long callerId) throws ConcurrentOperationException, InsufficientAddressCapacityException { + public PublicIp assignSourceNatIpAddress(Account owner, Network guestNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException { // TODO Auto-generated method stub return null; } @@ -192,7 +192,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { + public List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { // TODO Auto-generated method stub return null; } diff --git a/wscript b/wscript index 83041135c0a..daf6c5ffbb8 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-21T20:55:19Z' +VERSION = '3.0.3.2012-05-22T00:32:35Z' APPNAME = 'cloud' import shutil,os