Search in sources :

Example 36 with PublicIp

use of com.cloud.network.addr.PublicIp in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method getPublicIpsToApply.

protected ArrayList<? extends PublicIpAddress> getPublicIpsToApply(final VirtualRouter router, final Provider provider, final Long guestNetworkId, final com.cloud.network.IpAddress.State... skipInStates) {
    final long ownerId = router.getAccountId();
    final List<? extends IpAddress> userIps;
    final Network guestNetwork = _networkDao.findById(guestNetworkId);
    if (guestNetwork.getGuestType() == GuestType.Shared) {
        // ignore the account id for the shared network
        userIps = _networkModel.listPublicIpsAssignedToGuestNtwk(guestNetworkId, null);
    } else {
        userIps = _networkModel.listPublicIpsAssignedToGuestNtwk(ownerId, guestNetworkId, null);
    }
    final List<PublicIp> allPublicIps = new ArrayList<PublicIp>();
    if (userIps != null && !userIps.isEmpty()) {
        boolean addIp = true;
        for (final IpAddress userIp : userIps) {
            if (skipInStates != null) {
                for (final IpAddress.State stateToSkip : skipInStates) {
                    if (userIp.getState() == stateToSkip) {
                        s_logger.debug("Skipping ip address " + userIp + " in state " + userIp.getState());
                        addIp = false;
                        break;
                    }
                }
            }
            if (addIp) {
                final IPAddressVO ipVO = _ipAddressDao.findById(userIp.getId());
                final PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipVO, _vlanDao.findById(userIp.getVlanId()));
                allPublicIps.add(publicIp);
            }
        }
    }
    // Get public Ips that should be handled by router
    final Network network = _networkDao.findById(guestNetworkId);
    final Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(allPublicIps, false, true);
    final Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = _networkModel.getProviderToIpList(network, ipToServices);
    // Only cover virtual router for now, if ELB use it this need to be
    // modified
    final ArrayList<PublicIpAddress> publicIps = providerToIpList.get(provider);
    return publicIps;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.network.Network.Provider) PublicIpAddress(com.cloud.network.PublicIpAddress) Network(com.cloud.network.Network) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 37 with PublicIp

use of com.cloud.network.addr.PublicIp in project cloudstack by apache.

the class VpcManagerImpl method assignSourceNatIpAddressToVpc.

@Override
public PublicIp assignSourceNatIpAddressToVpc(final Account owner, final Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException {
    final long dcId = vpc.getZoneId();
    final IPAddressVO sourceNatIp = getExistingSourceNatInVpc(owner.getId(), vpc.getId());
    PublicIp ipToReturn = null;
    if (sourceNatIp != null) {
        ipToReturn = PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()));
    } else {
        ipToReturn = _ipAddrMgr.assignDedicateIpAddress(owner, null, vpc.getId(), dcId, true);
    }
    return ipToReturn;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 38 with PublicIp

use of com.cloud.network.addr.PublicIp in project cloudstack by apache.

the class InternalLbElementTest method verifyApplyIps.

//TEST FOR applyIps METHOD
@Test
public void verifyApplyIps() throws ResourceUnavailableException {
    List<PublicIp> ips = new ArrayList<PublicIp>();
    boolean result = _lbEl.applyIps(new NetworkVO(), ips, new HashSet<Service>());
    assertTrue("Wrong value is returned by applyIps method", result);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) Test(org.junit.Test)

Aggregations

PublicIp (com.cloud.network.addr.PublicIp)38 IPAddressVO (com.cloud.network.dao.IPAddressVO)20 ArrayList (java.util.ArrayList)16 Network (com.cloud.network.Network)9 Account (com.cloud.user.Account)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 DataCenter (com.cloud.dc.DataCenter)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 Test (org.junit.Test)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)5 Service (com.cloud.network.Network.Service)5 DB (com.cloud.utils.db.DB)5 TransactionStatus (com.cloud.utils.db.TransactionStatus)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 VlanVO (com.cloud.dc.VlanVO)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 Provider (com.cloud.network.Network.Provider)4