Search in sources :

Example 26 with PublicIpAddress

use of com.cloud.network.PublicIpAddress 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)

Aggregations

PublicIpAddress (com.cloud.network.PublicIpAddress)26 ArrayList (java.util.ArrayList)15 Network (com.cloud.network.Network)12 HashMap (java.util.HashMap)9 Map (java.util.Map)8 NicVO (com.cloud.vm.NicVO)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)6 PublicIp (com.cloud.network.addr.PublicIp)5 Pair (com.cloud.utils.Pair)5 Ip (com.cloud.utils.net.Ip)5 Nic (com.cloud.vm.Nic)5 URI (java.net.URI)5 ConfigurePublicIpsOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer)4 ConfigurePublicIpsOnLogicalRouterCommand (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand)4 Commands (com.cloud.agent.manager.Commands)4 DataCenterVO (com.cloud.dc.DataCenterVO)4 NicDao (com.cloud.vm.dao.NicDao)4 HostVO (com.cloud.host.HostVO)3 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)3 NiciraNvpRouterMappingVO (com.cloud.network.NiciraNvpRouterMappingVO)3