Search in sources :

Example 11 with Provider

use of com.cloud.network.Network.Provider in project cloudstack by apache.

the class NetworkServiceImpl method addDefaultBaremetalProvidersToPhysicalNetwork.

private PhysicalNetworkServiceProvider addDefaultBaremetalProvidersToPhysicalNetwork(long physicalNetworkId) {
    PhysicalNetworkVO pvo = _physicalNetworkDao.findById(physicalNetworkId);
    DataCenterVO dvo = _dcDao.findById(pvo.getDataCenterId());
    if (dvo.getNetworkType() == NetworkType.Basic) {
        Provider provider = Network.Provider.getProvider("BaremetalDhcpProvider");
        if (provider == null) {
            // baremetal is not loaded
            return null;
        }
        addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalDhcpProvider", null, null);
        addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalPxeProvider", null, null);
        addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalUserdataProvider", null, null);
    } else if (dvo.getNetworkType() == NetworkType.Advanced) {
        addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalPxeProvider", null, null);
        enableBaremetalProvider("BaremetalPxeProvider");
    }
    return null;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Provider(com.cloud.network.Network.Provider)

Example 12 with Provider

use of com.cloud.network.Network.Provider in project cloudstack by apache.

the class NetworkModelImpl method getProviderToIpList.

@Override
public Map<Provider, ArrayList<PublicIpAddress>> getProviderToIpList(Network network, Map<PublicIpAddress, Set<Service>> ipToServices) {
    NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (!offering.isConserveMode()) {
        for (PublicIpAddress ip : ipToServices.keySet()) {
            Set<Service> services = new HashSet<Service>();
            services.addAll(ipToServices.get(ip));
            if (services != null && services.contains(Service.Firewall)) {
                services.remove(Service.Firewall);
            }
            if (services != null && services.size() > 1) {
                throw new CloudRuntimeException("Ip " + ip.getAddress() + " is used by multiple services!");
            }
        }
    }
    Map<Service, Set<PublicIpAddress>> serviceToIps = new HashMap<Service, Set<PublicIpAddress>>();
    for (PublicIpAddress ip : ipToServices.keySet()) {
        for (Service service : ipToServices.get(ip)) {
            Set<PublicIpAddress> ips = serviceToIps.get(service);
            if (ips == null) {
                ips = new HashSet<PublicIpAddress>();
            }
            ips.add(ip);
            serviceToIps.put(service, ips);
        }
    }
    // TODO Check different provider for same IP
    Map<Provider, Set<Service>> providerToServices = getProviderServicesMap(network.getId());
    Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = new HashMap<Provider, ArrayList<PublicIpAddress>>();
    for (Provider provider : providerToServices.keySet()) {
        if (!(getElementImplementingProvider(provider.getName()) instanceof IpDeployingRequester)) {
            continue;
        }
        Set<Service> services = providerToServices.get(provider);
        ArrayList<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
        Set<PublicIpAddress> ipSet = new HashSet<PublicIpAddress>();
        for (Service service : services) {
            Set<PublicIpAddress> serviceIps = serviceToIps.get(service);
            if (serviceIps == null || serviceIps.isEmpty()) {
                continue;
            }
            ipSet.addAll(serviceIps);
        }
        Set<PublicIpAddress> sourceNatIps = serviceToIps.get(Service.SourceNat);
        if (sourceNatIps != null && !sourceNatIps.isEmpty()) {
            ipList.addAll(0, sourceNatIps);
            ipSet.removeAll(sourceNatIps);
        }
        ipList.addAll(ipSet);
        providerToIpList.put(provider, ipList);
    }
    return providerToIpList;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) NetworkOffering(com.cloud.offering.NetworkOffering) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HashSet(java.util.HashSet)

Example 13 with Provider

use of com.cloud.network.Network.Provider in project cloudstack by apache.

the class NetworkModelImpl method getServiceProvidersMap.

Map<Service, Set<Provider>> getServiceProvidersMap(long networkId) {
    Map<Service, Set<Provider>> map = new HashMap<Service, Set<Provider>>();
    List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (NetworkServiceMapVO nsm : nsms) {
        Set<Provider> providers = map.get(Service.getService(nsm.getService()));
        if (providers == null) {
            providers = new HashSet<Provider>();
        }
        providers.add(Provider.getProvider(nsm.getProvider()));
        map.put(Service.getService(nsm.getService()), providers);
    }
    return map;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 14 with Provider

use of com.cloud.network.Network.Provider in project cloudstack by apache.

the class NetworkModelImpl method start.

@Override
public boolean start() {
    // Need to do this in start() since _networkElements are not completely configured until then.
    for (NetworkElement element : networkElements) {
        Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
        Provider implementedProvider = element.getProvider();
        if (implementedProvider != null) {
            if (s_providerToNetworkElementMap.containsKey(implementedProvider.getName())) {
                s_logger.error("Cannot start NetworkModel: Provider <-> NetworkElement must be a one-to-one map, " + "multiple NetworkElements found for Provider: " + implementedProvider.getName());
                continue;
            }
            s_logger.info("Add provider <-> element map entry. " + implementedProvider.getName() + "-" + element.getName() + "-" + element.getClass().getSimpleName());
            s_providerToNetworkElementMap.put(implementedProvider.getName(), element.getName());
        }
        if (capabilities != null && implementedProvider != null) {
            for (Service service : capabilities.keySet()) {
                if (s_serviceToImplementedProvidersMap.containsKey(service)) {
                    List<Provider> providers = s_serviceToImplementedProvidersMap.get(service);
                    providers.add(implementedProvider);
                } else {
                    List<Provider> providers = new ArrayList<Provider>();
                    providers.add(implementedProvider);
                    s_serviceToImplementedProvidersMap.put(service, providers);
                }
            }
        }
    }
    s_logger.info("Started Network Model");
    return true;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 15 with Provider

use of com.cloud.network.Network.Provider in project cloudstack by apache.

the class NetworkModelImpl method canIpUsedForService.

public boolean canIpUsedForService(PublicIp publicIp, Service service, Long networkId) {
    List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
    ipList.add(publicIp);
    Map<PublicIpAddress, Set<Service>> ipToServices = getIpToServices(ipList, false, true);
    Set<Service> services = ipToServices.get(publicIp);
    if (services == null || services.isEmpty()) {
        return true;
    }
    if (networkId == null) {
        networkId = publicIp.getAssociatedWithNetworkId();
    }
    // We only support one provider for one service now
    Map<Service, Set<Provider>> serviceToProviders = getServiceProvidersMap(networkId);
    // Since IP already has service to bind with, the oldProvider can't be null
    Set<Provider> newProviders = serviceToProviders.get(service);
    if (newProviders == null || newProviders.isEmpty()) {
        throw new InvalidParameterException("There is no new provider for IP " + publicIp.getAddress() + " of service " + service.getName() + "!");
    }
    Provider newProvider = (Provider) newProviders.toArray()[0];
    Set<Provider> oldProviders = serviceToProviders.get(services.toArray()[0]);
    Provider oldProvider = (Provider) oldProviders.toArray()[0];
    Network network = _networksDao.findById(networkId);
    NetworkElement oldElement = getElementImplementingProvider(oldProvider.getName());
    NetworkElement newElement = getElementImplementingProvider(newProvider.getName());
    if (oldElement instanceof IpDeployingRequester && newElement instanceof IpDeployingRequester) {
        IpDeployer oldIpDeployer = ((IpDeployingRequester) oldElement).getIpDeployer(network);
        IpDeployer newIpDeployer = ((IpDeployingRequester) newElement).getIpDeployer(network);
    // FIXME: I ignored this check
    } else {
        throw new InvalidParameterException("Ip cannot be applied for new provider!");
    }
    return true;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) InvalidParameterException(java.security.InvalidParameterException) NetworkElement(com.cloud.network.element.NetworkElement) IpDeployer(com.cloud.network.element.IpDeployer)

Aggregations

Provider (com.cloud.network.Network.Provider)66 Service (com.cloud.network.Network.Service)35 HashSet (java.util.HashSet)31 HashMap (java.util.HashMap)28 Set (java.util.Set)27 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)25 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)25 NetworkElement (com.cloud.network.element.NetworkElement)22 ArrayList (java.util.ArrayList)19 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 Network (com.cloud.network.Network)17 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)15 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)12 Map (java.util.Map)12 ResourceLimitService (com.cloud.user.ResourceLimitService)11 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)11 NicProfile (com.cloud.vm.NicProfile)10