Search in sources :

Example 26 with Capability

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

the class ConfigurationManagerImpl method validateSourceNatServiceCapablities.

void validateSourceNatServiceCapablities(final Map<Capability, String> sourceNatServiceCapabilityMap) {
    if (sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
        if (sourceNatServiceCapabilityMap.keySet().size() > 2) {
            throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + " and " + Capability.RedundantRouter + " capabilities can be sepcified for source nat service");
        }
        for (final Map.Entry<Capability, String> srcNatPair : sourceNatServiceCapabilityMap.entrySet()) {
            final Capability capability = srcNatPair.getKey();
            final String value = srcNatPair.getValue();
            if (capability == Capability.SupportedSourceNatTypes) {
                final boolean perAccount = value.contains("peraccount");
                final boolean perZone = value.contains("perzone");
                if (perAccount && perZone || !perAccount && !perZone) {
                    throw new InvalidParameterValueException("Either peraccount or perzone source NAT type can be specified for " + Capability.SupportedSourceNatTypes.getName());
                }
            } else if (capability == Capability.RedundantRouter) {
                final boolean enabled = value.contains("true");
                final boolean disabled = value.contains("false");
                if (!enabled && !disabled) {
                    throw new InvalidParameterValueException("Unknown specified value for " + Capability.RedundantRouter.getName());
                }
            } else {
                throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + " and " + Capability.RedundantRouter + " capabilities can be sepcified for source nat service");
            }
        }
    }
}
Also used : Capability(com.cloud.network.Network.Capability) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 27 with Capability

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

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.network.Network.Capability) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 28 with Capability

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

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 internalLb = value.contains("internal");
                final boolean publicLb = value.contains("public");
                if (!internalLb && !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.network.Network.Capability) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Aggregations

Capability (com.cloud.network.Network.Capability)28 HashMap (java.util.HashMap)19 Service (com.cloud.network.Network.Service)17 Map (java.util.Map)16 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 Provider (com.cloud.network.Network.Provider)8 NetworkElement (com.cloud.network.element.NetworkElement)8 ArrayList (java.util.ArrayList)7 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)7 ResourceLimitService (com.cloud.user.ResourceLimitService)6 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)5 Network (com.cloud.network.Network)5 NetworkService (com.cloud.network.NetworkService)4 PhysicalNetwork (com.cloud.network.PhysicalNetwork)4 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)4 HashSet (java.util.HashSet)4 Vpc (com.cloud.network.vpc.Vpc)3 Collection (java.util.Collection)3 Iterator (java.util.Iterator)3 Set (java.util.Set)3