|
65 | 65 | import com.cloud.exception.ResourceAllocationException; |
66 | 66 | import com.cloud.exception.ResourceUnavailableException; |
67 | 67 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
| 68 | +import com.cloud.network.element.NetworkElement; |
68 | 69 | import com.cloud.network.IpAddress; |
69 | 70 | import com.cloud.network.IpAddressManager; |
70 | 71 | import com.cloud.network.Network; |
@@ -376,6 +377,7 @@ public VpcOffering createVpcOffering(String name, String displayText, List<Strin |
376 | 377 | } |
377 | 378 | } |
378 | 379 |
|
| 380 | + validateConnectivtyServiceCapablitlies(svcProviderMap.get(Service.Connectivity), serviceCapabilitystList); |
379 | 381 | boolean supportsDistributedRouter = isVpcOfferingSupportsDistributedRouter(serviceCapabilitystList); |
380 | 382 |
|
381 | 383 | VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null, |
@@ -460,6 +462,56 @@ private boolean isVpcOfferingSupportsDistributedRouter(Map serviceCapabilitystLi |
460 | 462 | return supportsDistributedRouter; |
461 | 463 | } |
462 | 464 |
|
| 465 | + private void validateConnectivtyServiceCapablitlies(Set<Provider> providers, Map serviceCapabilitystList) { |
| 466 | + |
| 467 | + if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) { |
| 468 | + Collection serviceCapabilityCollection = serviceCapabilitystList.values(); |
| 469 | + Iterator iter = serviceCapabilityCollection.iterator(); |
| 470 | + Map<Network.Capability, String> capabilityMap = null; |
| 471 | + |
| 472 | + while (iter.hasNext()) { |
| 473 | + HashMap<String, String> svcCapabilityMap = (HashMap<String, String>)iter.next(); |
| 474 | + Network.Capability capability = null; |
| 475 | + String svc = svcCapabilityMap.get("service"); |
| 476 | + String capabilityName = svcCapabilityMap.get("capabilitytype"); |
| 477 | + String capabilityValue = svcCapabilityMap.get("capabilityvalue"); |
| 478 | + if (capabilityName != null) { |
| 479 | + capability = Network.Capability.getCapability(capabilityName); |
| 480 | + } |
| 481 | + |
| 482 | + if ((capability == null) || (capabilityName == null) || (capabilityValue == null)) { |
| 483 | + throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue); |
| 484 | + } |
| 485 | + |
| 486 | + if (!svc.equalsIgnoreCase(Service.Connectivity.getName())) { |
| 487 | + throw new InvalidParameterValueException("Invalid Service:" + svc + " specified. Only for 'Connectivity' service capabilities can be specified"); |
| 488 | + } |
| 489 | + |
| 490 | + if (!capabilityName.equalsIgnoreCase("DistributedRouter")) { |
| 491 | + throw new InvalidParameterValueException("Invalid Capability:" + capabilityName + " specified. Only 'DistributedRouter' capability can be specified."); |
| 492 | + } |
| 493 | + |
| 494 | + if (!capabilityValue.equalsIgnoreCase("true") && capabilityValue.equalsIgnoreCase("false")) { |
| 495 | + throw new InvalidParameterValueException("Invalid Capability value:" + capabilityValue + " specified."); |
| 496 | + } |
| 497 | + } |
| 498 | + |
| 499 | + if (providers != null && !providers.isEmpty()) { |
| 500 | + for (Provider provider: providers) { |
| 501 | + NetworkElement element = _ntwkModel.getElementImplementingProvider(provider.getName()); |
| 502 | + Map<Service, Map<Network.Capability, String>> capabilities = element.getCapabilities(); |
| 503 | + if (capabilities != null && !capabilities.isEmpty()) { |
| 504 | + Map<Network.Capability, String> connectivityCapabilities = capabilities.get(Service.Connectivity); |
| 505 | + if (connectivityCapabilities == null || (connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(Network.Capability.DistributedRouter))) { |
| 506 | + throw new InvalidParameterValueException("Provider: " + provider.getName() + " does not support " |
| 507 | + + Network.Capability.DistributedRouter.getName() + " capability."); |
| 508 | + } |
| 509 | + } |
| 510 | + } |
| 511 | + } |
| 512 | + } |
| 513 | + } |
| 514 | + |
463 | 515 | @Override |
464 | 516 | public Vpc getActiveVpc(long vpcId) { |
465 | 517 | return _vpcDao.getActiveVpcById(vpcId); |
|
0 commit comments