Search in sources :

Example 16 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method checkCapabilityForProvider.

@Override
public void checkCapabilityForProvider(final Set<Provider> providers, final Service service, final Capability cap, final String capValue) {
    for (final Provider provider : providers) {
        final NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element != null) {
            final Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
            if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
                throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            final Map<Capability, String> serviceCapabilities = elementCapabilities.get(service);
            if (serviceCapabilities == null || serviceCapabilities.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capabilities for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            final String value = serviceCapabilities.get(cap);
            if (value == null || value.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            if (!value.toLowerCase().contains(capValue.toLowerCase())) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't support value " + capValue + " for capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
        } else {
            throw new UnsupportedServiceException("Unable to find network element for provider " + provider.getName());
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) Service(com.cloud.legacymodel.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 17 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method validateConnectivityServiceCapablities.

void validateConnectivityServiceCapablities(final Set<Provider> providers, final Map<Capability, String> connectivityServiceCapabilityMap) {
    if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
        for (final Map.Entry<Capability, String> entry : connectivityServiceCapabilityMap.entrySet()) {
            final Capability capability = entry.getKey();
            if (capability == Capability.StretchedL2Subnet) {
                final String value = entry.getValue().toLowerCase();
                if (!(value.contains("true") ^ value.contains("false"))) {
                    throw new InvalidParameterValueException("Invalid value (" + value + ") for " + capability + " should be true/false");
                }
            } else {
                throw new InvalidParameterValueException("Capability " + capability.getName() + " can not be " + " specified with connectivity service.");
            }
        }
        // validate connectivity service provider actually supports specified capabilities
        if (providers != null && !providers.isEmpty()) {
            for (final Provider provider : providers) {
                final NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
                final Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
                if (capabilities != null && !capabilities.isEmpty()) {
                    final Map<Capability, String> connectivityCapabilities = capabilities.get(Service.Connectivity);
                    if (connectivityCapabilities == null || connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(Capability.StretchedL2Subnet)) {
                        throw new InvalidParameterValueException("Provider: " + provider.getName() + " does not support " + Capability.StretchedL2Subnet.getName());
                    }
                }
            }
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(com.cloud.affinity.AffinityGroupService) Map(java.util.Map) HashMap(java.util.HashMap) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 18 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method createNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_CREATE, eventDescription = "creating network offering")
public NetworkOffering createNetworkOffering(final CreateNetworkOfferingCmd cmd) {
    final String name = cmd.getNetworkOfferingName();
    final String displayText = cmd.getDisplayText();
    final String tags = cmd.getTags();
    final String trafficTypeString = cmd.getTraffictype();
    final boolean specifyVlan = cmd.getSpecifyVlan();
    final boolean conserveMode = cmd.getConserveMode();
    final String availabilityStr = cmd.getAvailability();
    Integer networkRate = cmd.getNetworkRate();
    TrafficType trafficType = null;
    Availability availability = null;
    GuestType guestType = null;
    final boolean specifyIpRanges = cmd.getSpecifyIpRanges();
    final boolean isPersistent = cmd.getIsPersistent();
    final Map<String, String> detailsStr = cmd.getDetails();
    final Boolean egressDefaultPolicy = cmd.getEgressDefaultPolicy();
    Integer maxconn = null;
    boolean enableKeepAlive = false;
    // Verify traffic type
    for (final TrafficType tType : TrafficType.values()) {
        if (tType.name().equalsIgnoreCase(trafficTypeString)) {
            trafficType = tType;
            break;
        }
    }
    if (trafficType == null) {
        throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage");
    }
    // Only GUEST traffic type is supported in Acton
    if (trafficType != TrafficType.Guest) {
        throw new InvalidParameterValueException("Only traffic type " + TrafficType.Guest + " is supported in the current release");
    }
    // Verify offering type
    for (final GuestType offType : GuestType.values()) {
        if (offType.name().equalsIgnoreCase(cmd.getGuestIpType())) {
            guestType = offType;
            break;
        }
    }
    if (guestType == null) {
        throw new InvalidParameterValueException("Invalid \"type\" parameter is given; can have Shared and Isolated values");
    }
    // Verify availability
    for (final Availability avlb : Availability.values()) {
        if (avlb.name().equalsIgnoreCase(availabilityStr)) {
            availability = avlb;
        }
    }
    if (availability == null) {
        throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional);
    }
    if (networkRate != null && networkRate < 0) {
        networkRate = 0;
    }
    final Long serviceOfferingId = cmd.getServiceOfferingId();
    final Long secondaryServiceOfferingId = cmd.getSecondaryServiceOfferingId();
    if (serviceOfferingId != null) {
        checkServiceOffering(serviceOfferingId);
    }
    if (secondaryServiceOfferingId != null) {
        checkServiceOffering(secondaryServiceOfferingId);
    }
    // configure service provider map
    final Map<Network.Service, Set<Network.Provider>> serviceProviderMap = new HashMap<>();
    final Set<Network.Provider> defaultProviders = new HashSet<>();
    // populate the services first
    for (final String serviceName : cmd.getSupportedServices()) {
        // validate if the service is supported
        final Service service = Network.Service.getService(serviceName);
        if (service == null || service == Service.Gateway) {
            throw new InvalidParameterValueException("Invalid service " + serviceName);
        }
        serviceProviderMap.put(service, defaultProviders);
    }
    // add gateway provider (if sourceNat provider is enabled)
    final Set<Provider> sourceNatServiceProviders = serviceProviderMap.get(Service.SourceNat);
    if (sourceNatServiceProviders != null && !sourceNatServiceProviders.isEmpty()) {
        serviceProviderMap.put(Service.Gateway, sourceNatServiceProviders);
    }
    // populate providers
    final Map<Provider, Set<Service>> providerCombinationToVerify = new HashMap<>();
    final Map<String, List<String>> svcPrv = cmd.getServiceProviders();
    Provider firewallProvider = null;
    Provider dhcpProvider = null;
    Boolean IsVrUserdataProvider = false;
    if (svcPrv != null) {
        for (final String serviceStr : svcPrv.keySet()) {
            final Network.Service service = Network.Service.getService(serviceStr);
            if (serviceProviderMap.containsKey(service)) {
                final Set<Provider> providers = new HashSet<>();
                // the service is LB
                if (!serviceStr.equalsIgnoreCase(Service.Lb.getName()) && svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) {
                    throw new InvalidParameterValueException("In the current release only one provider can be " + "specified for the service if the service is not LB");
                }
                for (final String prvNameStr : svcPrv.get(serviceStr)) {
                    // check if provider is supported
                    final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
                    if (provider == null) {
                        throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
                    }
                    if ((service == Service.PortForwarding || service == Service.StaticNat) && provider == Provider.VirtualRouter) {
                        firewallProvider = Provider.VirtualRouter;
                    }
                    if (service == Service.Dhcp) {
                        dhcpProvider = provider;
                    }
                    if (service == Service.UserData && provider == Provider.VirtualRouter) {
                        IsVrUserdataProvider = true;
                    }
                    providers.add(provider);
                    final Set<Service> serviceSet;
                    if (providerCombinationToVerify.get(provider) == null) {
                        serviceSet = new HashSet<>();
                    } else {
                        serviceSet = providerCombinationToVerify.get(provider);
                    }
                    serviceSet.add(service);
                    providerCombinationToVerify.put(provider, serviceSet);
                }
                serviceProviderMap.put(service, providers);
            } else {
                throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network " + "offering, can't add a provider to it");
            }
        }
    }
    // dhcp provider and userdata provider should be same because vm will be contacting dhcp server for user data.
    if (dhcpProvider == null && IsVrUserdataProvider) {
        s_logger.debug("User data provider VR can't be selected without VR as dhcp provider. In this case VM fails to contact the DHCP server for userdata");
        throw new InvalidParameterValueException("Without VR as dhcp provider, User data can't selected for VR. Please select VR as DHCP provider ");
    }
    // validate providers combination here
    _networkModel.canProviderSupportServices(providerCombinationToVerify);
    // validate the LB service capabilities specified in the network
    // offering
    final Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb);
    if (!serviceProviderMap.containsKey(Service.Lb) && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering.");
    }
    validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap);
    if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
        maxconn = cmd.getMaxconnections();
        if (maxconn == null) {
            maxconn = Integer.parseInt(_configDao.getValue(Config.NetworkLBHaproxyMaxConn.key()));
        }
    }
    if (cmd.getKeepAliveEnabled() != null && cmd.getKeepAliveEnabled()) {
        enableKeepAlive = true;
    }
    // validate the Source NAT service capabilities specified in the network
    // offering
    final Map<Capability, String> sourceNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.SourceNat);
    if (!serviceProviderMap.containsKey(Service.SourceNat) && sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for source NAT service can be specifed only when source NAT service is enabled for network offering.");
    }
    validateSourceNatServiceCapablities(sourceNatServiceCapabilityMap);
    // validate the Static Nat service capabilities specified in the network
    // offering
    final Map<Capability, String> staticNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.StaticNat);
    if (!serviceProviderMap.containsKey(Service.StaticNat) && sourceNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for static NAT service can be specifed only when static NAT service is enabled for network offering.");
    }
    validateStaticNatServiceCapablities(staticNatServiceCapabilityMap);
    // validate the 'Connectivity' service capabilities specified in the network offering, if 'Connectivity' service
    // is in the supported services of network offering
    final Map<Capability, String> connectivityServiceCapabilityMap = cmd.getServiceCapabilities(Service.Connectivity);
    if (!serviceProviderMap.containsKey(Service.Connectivity) && connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for 'Connectivity' service can be specified " + "only when Connectivity service is enabled for network offering.");
    }
    validateConnectivityServiceCapablities(serviceProviderMap.get(Service.Connectivity), connectivityServiceCapabilityMap);
    final Map<Service, Map<Capability, String>> serviceCapabilityMap = new HashMap<>();
    serviceCapabilityMap.put(Service.Lb, lbServiceCapabilityMap);
    serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap);
    serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap);
    serviceCapabilityMap.put(Service.Connectivity, connectivityServiceCapabilityMap);
    // combination
    if (firewallProvider != null) {
        s_logger.debug("Adding Firewall service with provider " + firewallProvider.getName());
        final Set<Provider> firewallProviderSet = new HashSet<>();
        firewallProviderSet.add(firewallProvider);
        serviceProviderMap.put(Service.Firewall, firewallProviderSet);
        if (!firewallProvider.getName().equals(Provider.VirtualRouter.getName()) && !egressDefaultPolicy) {
            throw new InvalidParameterValueException("Firewall egress with default policy " + egressDefaultPolicy + " is not supported by the provider " + firewallProvider.getName());
        }
    }
    final Map<NetworkOffering.Detail, String> details = new HashMap<>();
    if (detailsStr != null) {
        for (final String detailStr : detailsStr.keySet()) {
            NetworkOffering.Detail offDetail = null;
            for (final NetworkOffering.Detail supportedDetail : NetworkOffering.Detail.values()) {
                if (detailStr.equalsIgnoreCase(supportedDetail.toString())) {
                    offDetail = supportedDetail;
                    break;
                }
            }
            if (offDetail == null) {
                throw new InvalidParameterValueException("Unsupported detail " + detailStr);
            }
            details.put(offDetail, detailsStr.get(detailStr));
        }
    }
    final NetworkOffering offering = createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId, secondaryServiceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent, details, egressDefaultPolicy, maxconn, enableKeepAlive);
    CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
    return offering;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.legacymodel.network.Network.Service) GuestType(com.cloud.model.enumeration.GuestType) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) TrafficType(com.cloud.model.enumeration.TrafficType) HashSet(java.util.HashSet) Availability(com.cloud.offering.NetworkOffering.Availability) Capability(com.cloud.legacymodel.network.Network.Capability) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(com.cloud.affinity.AffinityGroupService) Detail(com.cloud.offering.NetworkOffering.Detail) Provider(com.cloud.legacymodel.network.Network.Provider) Provider(com.cloud.legacymodel.network.Network.Provider) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail) ActionEvent(com.cloud.event.ActionEvent)

Example 19 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method validateLoadBalancerServiceCapabilities.

void validateLoadBalancerServiceCapabilities(final Map<Capability, String> lbServiceCapabilityMap) {
    if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
        if (lbServiceCapabilityMap.keySet().size() > 3 || !lbServiceCapabilityMap.containsKey(Capability.SupportedLBIsolation)) {
            throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + ", " + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() + " capabilities can be sepcified for LB service");
        }
        for (final Capability cap : lbServiceCapabilityMap.keySet()) {
            final String value = lbServiceCapabilityMap.get(cap);
            if (cap == Capability.SupportedLBIsolation) {
                final boolean dedicatedLb = value.contains("dedicated");
                final boolean sharedLB = value.contains("shared");
                if (dedicatedLb && sharedLB || !dedicatedLb && !sharedLB) {
                    throw new InvalidParameterValueException("Either dedicated or shared isolation can be specified for " + Capability.SupportedLBIsolation.getName());
                }
            } else if (cap == Capability.ElasticLb) {
                final boolean enabled = value.contains("true");
                final boolean disabled = value.contains("false");
                if (!enabled && !disabled) {
                    throw new InvalidParameterValueException("Unknown specified value for " + Capability.ElasticLb.getName());
                }
            } else if (cap == Capability.InlineMode) {
                final boolean enabled = value.contains("true");
                final boolean disabled = value.contains("false");
                if (!enabled && !disabled) {
                    throw new InvalidParameterValueException("Unknown specified value for " + Capability.InlineMode.getName());
                }
            } else if (cap == Capability.LbSchemes) {
                final boolean publicLb = value.contains("public");
                if (!publicLb) {
                    throw new InvalidParameterValueException("Unknown specified value for " + Capability.LbSchemes.getName());
                }
            } else {
                throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + ", " + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() + ", " + Capability.LbSchemes.getName() + " capabilities can be sepcified for LB service");
            }
        }
    }
}
Also used : Capability(com.cloud.legacymodel.network.Network.Capability) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

Example 20 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method validateStaticNatServiceCapablities.

void validateStaticNatServiceCapablities(final Map<Capability, String> staticNatServiceCapabilityMap) {
    if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
        boolean eipEnabled = false;
        boolean associatePublicIP = true;
        for (final Capability capability : staticNatServiceCapabilityMap.keySet()) {
            final String value = staticNatServiceCapabilityMap.get(capability).toLowerCase();
            if (!(value.contains("true") ^ value.contains("false"))) {
                throw new InvalidParameterValueException("Unknown specified value (" + value + ") for " + capability);
            }
            if (capability == Capability.ElasticIp) {
                eipEnabled = value.contains("true");
            } else if (capability == Capability.AssociatePublicIP) {
                associatePublicIP = value.contains("true");
            } else {
                throw new InvalidParameterValueException("Only " + Capability.ElasticIp.getName() + " and " + Capability.AssociatePublicIP.getName() + " capabilitiy can be sepcified for static nat service");
            }
        }
        if (!eipEnabled && associatePublicIP) {
            throw new InvalidParameterValueException("Capability " + Capability.AssociatePublicIP.getName() + " can only be set when capability " + Capability.ElasticIp.getName() + " is true");
        }
    }
}
Also used : Capability(com.cloud.legacymodel.network.Network.Capability) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

Aggregations

Capability (com.cloud.legacymodel.network.Network.Capability)20 HashMap (java.util.HashMap)12 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)11 Service (com.cloud.legacymodel.network.Network.Service)11 Map (java.util.Map)10 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)7 Provider (com.cloud.legacymodel.network.Network.Provider)6 NetworkElement (com.cloud.network.element.NetworkElement)6 ResourceLimitService (com.cloud.user.ResourceLimitService)6 NetworkService (com.cloud.network.NetworkService)5 UnsupportedServiceException (com.cloud.legacymodel.exceptions.UnsupportedServiceException)4 Vpc (com.cloud.legacymodel.network.vpc.Vpc)4 ArrayList (java.util.ArrayList)4 AffinityGroupService (com.cloud.affinity.AffinityGroupService)3 ServiceResponse (com.cloud.api.response.ServiceResponse)3 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)3 IpAddress (com.cloud.network.IpAddress)3 PublicIpAddress (com.cloud.network.PublicIpAddress)3 Site2SiteVpnGateway (com.cloud.network.Site2SiteVpnGateway)3 ManagementService (com.cloud.server.ManagementService)3