|
96 | 96 | import com.cloud.host.dao.HostDetailsDao; |
97 | 97 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
98 | 98 | import com.cloud.network.Network; |
| 99 | +import com.cloud.network.Network.Capability; |
99 | 100 | import com.cloud.network.Network.GuestType; |
100 | 101 | import com.cloud.network.Network.Provider; |
101 | 102 | import com.cloud.network.Network.Service; |
@@ -2968,19 +2969,73 @@ public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) { |
2968 | 2969 | } |
2969 | 2970 | } |
2970 | 2971 |
|
2971 | | - return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId); |
| 2972 | + // verify the LB service capabilities specified in the network offering |
| 2973 | + Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb); |
| 2974 | + if (!cmd.getLbService() && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) { |
| 2975 | + throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering."); |
| 2976 | + } |
| 2977 | + validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap); |
| 2978 | + |
| 2979 | + // verify the Firewall service capabilities specified in the network offering |
| 2980 | + Map<Capability, String> fwServiceCapabilityMap = cmd.getServiceCapabilities(Service.Firewall); |
| 2981 | + if (!cmd.getFirewallService() && fwServiceCapabilityMap != null && !fwServiceCapabilityMap.isEmpty()) { |
| 2982 | + throw new InvalidParameterValueException("Capabilities for Firewall service can be specifed only when Firewall service is enabled for network offering."); |
| 2983 | + } |
| 2984 | + validateFirewallServiceCapablities(fwServiceCapabilityMap); |
| 2985 | + |
| 2986 | + return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false, |
| 2987 | + guestType, false, serviceOfferingId, lbServiceCapabilityMap, fwServiceCapabilityMap); |
| 2988 | + } |
| 2989 | + |
| 2990 | + void validateLoadBalancerServiceCapabilities(Map<Capability, String> lbServiceCapabilityMap) { |
| 2991 | + if ((lbServiceCapabilityMap != null) && (lbServiceCapabilityMap.keySet().size() > 1 || !lbServiceCapabilityMap.containsKey(Capability.SupportedLBIsolation.getName()))) { |
| 2992 | + throw new InvalidParameterValueException("Only Load balancer isolation capability can be sepcified for LB service"); |
| 2993 | + } else { |
| 2994 | + String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation.getName()); |
| 2995 | + boolean dedicatedLb = isolationCapability.contains("dedicated"); |
| 2996 | + boolean sharedLB = isolationCapability.contains("shared"); |
| 2997 | + if ((dedicatedLb && sharedLB) || (!dedicatedLb && !sharedLB)){ |
| 2998 | + throw new InvalidParameterValueException("Either dedicated or shared isolation can be specified for " + Capability.SupportedLBIsolation.getName()); |
| 2999 | + } |
| 3000 | + } |
2972 | 3001 | } |
2973 | 3002 |
|
| 3003 | + void validateFirewallServiceCapablities(Map<Capability, String> fwServiceCapabilityMap) { |
| 3004 | + if ((fwServiceCapabilityMap != null) && (fwServiceCapabilityMap.keySet().size() > 1) || !fwServiceCapabilityMap.containsKey(Capability.SupportedSourceNatTypes.getName())) { |
| 3005 | + throw new InvalidParameterValueException("Only Supported Source NAT type capability can be sepcified for firewall service"); |
| 3006 | + } else { |
| 3007 | + String sourceNatType = fwServiceCapabilityMap.get(Capability.SupportedSourceNatTypes.getName()); |
| 3008 | + boolean perAccount = sourceNatType.contains("peraccount"); |
| 3009 | + boolean perZone = sourceNatType.contains("perzone"); |
| 3010 | + if ((perAccount && perZone) || (!perAccount && !perZone)) { |
| 3011 | + throw new InvalidParameterValueException("Either perAccount or perZone source NAT type can be specified for " + Capability.SupportedSourceNatTypes.getName()); |
| 3012 | + } |
| 3013 | + } |
| 3014 | + } |
| 3015 | + |
2974 | 3016 | @Override |
2975 | 3017 | @DB |
2976 | 3018 | public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, |
2977 | | - Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId) { |
| 3019 | + Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, |
| 3020 | + boolean systemOnly, Long serviceOfferingId, Map<Capability, String> lbServiceCapabilityMap, Map<Capability, String> fwServiceCapabilityMap) { |
2978 | 3021 |
|
2979 | 3022 | String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); |
2980 | 3023 | int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); |
2981 | 3024 | tags = cleanupTags(tags); |
2982 | 3025 |
|
2983 | | - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type); |
| 3026 | + boolean dedicatedLb = true; |
| 3027 | + if ((lbServiceCapabilityMap != null) && (!lbServiceCapabilityMap.isEmpty())) { |
| 3028 | + String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation); |
| 3029 | + dedicatedLb = isolationCapability.contains("dedicated"); |
| 3030 | + } |
| 3031 | + |
| 3032 | + boolean sharedSourceNat = false; |
| 3033 | + if ((fwServiceCapabilityMap != null) && (!fwServiceCapabilityMap.isEmpty())) { |
| 3034 | + String sourceNatType = fwServiceCapabilityMap.get(Capability.SupportedSourceNatTypes.getName()); |
| 3035 | + sharedSourceNat = sourceNatType.contains("perzone"); |
| 3036 | + } |
| 3037 | + |
| 3038 | + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type, dedicatedLb, sharedSourceNat); |
2984 | 3039 |
|
2985 | 3040 | if (serviceOfferingId != null) { |
2986 | 3041 | offering.setServiceOfferingId(serviceOfferingId); |
@@ -3318,6 +3373,35 @@ public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd) { |
3318 | 3373 | } |
3319 | 3374 | } |
3320 | 3375 |
|
| 3376 | + // verify and update the LB service capabilities specified in the network offering |
| 3377 | + Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb); |
| 3378 | + boolean dedicatedLb = true; |
| 3379 | + if (!cmd.getLbService() && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) { |
| 3380 | + throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering."); |
| 3381 | + } |
| 3382 | + validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap); |
| 3383 | + |
| 3384 | + if ((lbServiceCapabilityMap != null) && (!lbServiceCapabilityMap.isEmpty())) { |
| 3385 | + String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation); |
| 3386 | + dedicatedLb = isolationCapability.contains("dedicated"); |
| 3387 | + } |
| 3388 | + offering.setDedicatedLb(dedicatedLb); |
| 3389 | + |
| 3390 | + // verify the Firewall service capabilities specified in the network offering |
| 3391 | + Map<Capability, String> fwServiceCapabilityMap = cmd.getServiceCapabilities(Service.Firewall); |
| 3392 | + boolean sharedSourceNat = false; |
| 3393 | + |
| 3394 | + if (!cmd.getFirewallService() && fwServiceCapabilityMap != null && !fwServiceCapabilityMap.isEmpty()) { |
| 3395 | + throw new InvalidParameterValueException("Capabilities for Firewall service can be specifed only when Firewall service is enabled for network offering."); |
| 3396 | + } |
| 3397 | + validateFirewallServiceCapablities(fwServiceCapabilityMap); |
| 3398 | + |
| 3399 | + if ((fwServiceCapabilityMap != null) && (!fwServiceCapabilityMap.isEmpty())) { |
| 3400 | + String sourceNatType = fwServiceCapabilityMap.get(Capability.SupportedSourceNatTypes.getName()); |
| 3401 | + sharedSourceNat = sourceNatType.contains("perzone"); |
| 3402 | + } |
| 3403 | + offering.setSharedSourceNat(sharedSourceNat); |
| 3404 | + |
3321 | 3405 | if (svcPrv != null && !svcPrv.isEmpty()) { |
3322 | 3406 | if (networksExist) { |
3323 | 3407 | throw new InvalidParameterValueException("Unable to reset service providers as there are existing networks using this network offering"); |
|
0 commit comments