Search in sources :

Example 26 with Provider

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

the class ApiResponseHelper method createNetworkServiceResponse.

@Override
public ServiceResponse createNetworkServiceResponse(Service service) {
    ServiceResponse response = new ServiceResponse();
    response.setName(service.getName());
    // set list of capabilities required for the service
    List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
    Capability[] capabilities = service.getCapabilities();
    for (Capability cap : capabilities) {
        CapabilityResponse capabilityResponse = new CapabilityResponse();
        capabilityResponse.setName(cap.getName());
        capabilityResponse.setObjectName("capability");
        if (cap.getName().equals(Capability.SupportedLBIsolation.getName()) || cap.getName().equals(Capability.SupportedSourceNatTypes.getName()) || cap.getName().equals(Capability.RedundantRouter.getName())) {
            capabilityResponse.setCanChoose(true);
        } else {
            capabilityResponse.setCanChoose(false);
        }
        capabilityResponses.add(capabilityResponse);
    }
    response.setCapabilities(capabilityResponses);
    // set list of providers providing this service
    List<? extends Network.Provider> serviceProviders = ApiDBUtils.getProvidersForService(service);
    List<ProviderResponse> serviceProvidersResponses = new ArrayList<ProviderResponse>();
    for (Network.Provider serviceProvider : serviceProviders) {
        // return only Virtual Router/JuniperSRX/CiscoVnmc as a provider for the firewall
        if (service == Service.Firewall && !(serviceProvider == Provider.VirtualRouter || serviceProvider == Provider.JuniperSRX || serviceProvider == Provider.CiscoVnmc || serviceProvider == Provider.PaloAlto || serviceProvider == Provider.NuageVsp || serviceProvider == Provider.BigSwitchBcf)) {
            continue;
        }
        ProviderResponse serviceProviderResponse = createServiceProviderResponse(serviceProvider);
        serviceProvidersResponses.add(serviceProviderResponse);
    }
    response.setProviders(serviceProvidersResponses);
    response.setObjectName("networkservice");
    return response;
}
Also used : ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) Capability(com.cloud.network.Network.Capability) Provider(com.cloud.network.Network.Provider) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse)

Example 27 with Provider

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

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) {
    NetworkOfferingResponse response = new NetworkOfferingResponse();
    response.setId(offering.getUuid());
    response.setName(offering.getName());
    response.setDisplayText(offering.getDisplayText());
    response.setTags(offering.getTags());
    response.setTrafficType(offering.getTrafficType().toString());
    response.setIsDefault(offering.isDefault());
    response.setSpecifyVlan(offering.getSpecifyVlan());
    response.setConserveMode(offering.isConserveMode());
    response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
    response.setAvailability(offering.getAvailability().toString());
    response.setIsPersistent(offering.getIsPersistent());
    response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
    response.setEgressDefaultPolicy(offering.getEgressDefaultPolicy());
    response.setConcurrentConnections(offering.getConcurrentConnections());
    response.setSupportsStrechedL2Subnet(offering.getSupportsStrechedL2());
    response.setSupportsPublicAccess(offering.getSupportsPublicAccess());
    Long so = null;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        ServiceOffering soffering = ApiDBUtils.findServiceOfferingById(so);
        if (soffering != null) {
            response.setServiceOfferingId(soffering.getUuid());
        }
    }
    if (offering.getGuestType() != null) {
        response.setGuestIpType(offering.getGuestType().toString());
    }
    response.setState(offering.getState().name());
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> srvc_providers = entry.getValue();
        ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
        for (Provider provider : srvc_providers) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            List<CapabilityResponse> lbCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.getElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            CapabilityResponse inline = new CapabilityResponse();
            inline.setName(Capability.InlineMode.getName());
            inline.setValue(offering.isInline() ? "true" : "false");
            lbCapResponse.add(inline);
            svcRsp.setCapabilities(lbCapResponse);
        } else if (Service.SourceNat == service) {
            List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();
            CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            CapabilityResponse redundantRouter = new CapabilityResponse();
            redundantRouter.setName(Capability.RedundantRouter.getName());
            redundantRouter.setValue(offering.getRedundantRouter() ? "true" : "false");
            capabilities.add(redundantRouter);
            svcRsp.setCapabilities(capabilities);
        } else if (service == Service.StaticNat) {
            List<CapabilityResponse> staticNatCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.getElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            CapabilityResponse associatePublicIp = new CapabilityResponse();
            associatePublicIp.setName(Capability.AssociatePublicIP.getName());
            associatePublicIp.setValue(offering.getAssociatePublicIP() ? "true" : "false");
            staticNatCapResponse.add(associatePublicIp);
            svcRsp.setCapabilities(staticNatCapResponse);
        }
        serviceResponses.add(svcRsp);
    }
    response.setForVpc(_configMgr.isOfferingForVpc(offering));
    response.setServices(serviceResponses);
    //set network offering details
    Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
    if (details != null && !details.isEmpty()) {
        response.setDetails(details);
    }
    response.setObjectName("networkoffering");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail)

Example 28 with Provider

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

the class NetworkServiceImpl method addProviderToPhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_CREATE, eventDescription = "Creating Physical Network ServiceProvider", create = true)
public PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, Long destinationPhysicalNetworkId, List<String> enabledServices) {
    // verify input parameters
    PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
    if (network == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
        ex.addProxyObject(physicalNetworkId.toString(), "physicalNetworkId");
        throw ex;
    }
    // verify input parameters
    if (destinationPhysicalNetworkId != null) {
        PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId);
        if (destNetwork == null) {
            InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system");
            ex.addProxyObject(destinationPhysicalNetworkId.toString(), "destinationPhysicalNetworkId");
            throw ex;
        }
    }
    if (providerName != null) {
        Provider provider = Network.Provider.getProvider(providerName);
        if (provider == null) {
            throw new InvalidParameterValueException("Invalid Network Service Provider=" + providerName);
        }
    }
    if (_pNSPDao.findByServiceProvider(physicalNetworkId, providerName) != null) {
        // TBD: send uuid instead of physicalNetworkId.
        throw new CloudRuntimeException("The '" + providerName + "' provider already exists on physical network : " + physicalNetworkId);
    }
    // check if services can be turned off
    NetworkElement element = _networkModel.getElementImplementingProvider(providerName);
    if (element == null) {
        throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + providerName + "'");
    }
    List<Service> services = new ArrayList<Service>();
    if (enabledServices != null) {
        if (!element.canEnableIndividualServices()) {
            if (enabledServices.size() != element.getCapabilities().keySet().size()) {
                throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services for this Service Provider '" + providerName + "'");
            }
        }
        // validate Services
        boolean addGatewayService = false;
        for (String serviceName : enabledServices) {
            Network.Service service = Network.Service.getService(serviceName);
            if (service == null || service == Service.Gateway) {
                throw new InvalidParameterValueException("Invalid Network Service specified=" + serviceName);
            } else if (service == Service.SourceNat) {
                addGatewayService = true;
            }
            // check if the service is provided by this Provider
            if (!element.getCapabilities().containsKey(service)) {
                throw new InvalidParameterValueException(providerName + " Provider cannot provide this Service specified=" + serviceName);
            }
            services.add(service);
        }
        if (addGatewayService) {
            services.add(Service.Gateway);
        }
    } else {
        // enable all the default services supported by this element.
        services = new ArrayList<Service>(element.getCapabilities().keySet());
    }
    try {
        // Create the new physical network in the database
        PhysicalNetworkServiceProviderVO nsp = new PhysicalNetworkServiceProviderVO(physicalNetworkId, providerName);
        // set enabled services
        nsp.setEnabledServices(services);
        if (destinationPhysicalNetworkId != null) {
            nsp.setDestinationPhysicalNetworkId(destinationPhysicalNetworkId);
        }
        nsp = _pNSPDao.persist(nsp);
        return nsp;
    } catch (Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new CloudRuntimeException("Fail to add a provider to physical network");
    }
}
Also used : ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) Service(com.cloud.network.Network.Service) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 29 with Provider

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

the class NetworkServiceImpl method canIpsUseOffering.

private boolean canIpsUseOffering(List<PublicIp> publicIps, long offeringId) {
    Map<PublicIp, Set<Service>> ipToServices = getIpToServices(publicIps, false, true);
    Map<Service, Set<Provider>> serviceToProviders = _networkModel.getNetworkOfferingServiceProvidersMap(offeringId);
    NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId);
    //For inline mode checking, using firewall provider for LB instead, because public ip would apply on firewall provider
    if (offering.isInline()) {
        Provider firewallProvider = null;
        if (serviceToProviders.containsKey(Service.Firewall)) {
            firewallProvider = (Provider) serviceToProviders.get(Service.Firewall).toArray()[0];
        }
        Set<Provider> p = new HashSet<Provider>();
        p.add(firewallProvider);
        serviceToProviders.remove(Service.Lb);
        serviceToProviders.put(Service.Lb, p);
    }
    for (PublicIp ip : ipToServices.keySet()) {
        Set<Service> services = ipToServices.get(ip);
        Provider provider = null;
        for (Service service : services) {
            Set<Provider> curProviders = serviceToProviders.get(service);
            if (curProviders == null || curProviders.isEmpty()) {
                continue;
            }
            Provider curProvider = (Provider) curProviders.toArray()[0];
            if (provider == null) {
                provider = curProvider;
                continue;
            }
            // We don't support multiple providers for one service now
            if (!provider.equals(curProvider)) {
                throw new InvalidParameterException("There would be multiple providers for IP " + ip.getAddress() + " with the new network offering!");
            }
        }
    }
    return true;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ResultSet(java.sql.ResultSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) PublicIp(com.cloud.network.addr.PublicIp) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet)

Example 30 with Provider

use of com.cloud.network.Network.Provider 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

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