Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1371#discussion_r62756570
  
    --- Diff: 
api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java ---
    @@ -143,7 +149,17 @@ public Boolean getDisplayVpc() {
     
         @Override
         public void create() throws ResourceAllocationException {
    -        Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), 
getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr(), 
getNetworkDomain(), getDisplayVpc());
    +        Vpc vpc;
    +        if (_vpcService.isVpcOfferingDynamicallyRouted(getZoneId(), 
getVpcOffering())) {
    +            try {
    +                vpc = _vpcService.createDynamicVpc(getZoneId(), 
getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), 
getNetmask(), getNetworkDomain(),
    +                        getDisplayVpc());
    +            } catch (BadCIDRException e) {
    +                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, 
"Failed to create a VPC due to invalid CIDR");
    +            }
    +        } else {
    +            vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), 
getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr(), 
getNetworkDomain(), getDisplayVpc());
    +        }
    --- End diff --
    
    Why not perform this check in the ``vpcService.createVpc`` method?  This 
construct feels like a leak of the business rule.  It might make sense to 
create a VPC interface and factory that creates the appropriate type (static vs 
dynamic VPC).  The ``_vpcService`` could then provide polymorphic 
implementations of ``createVPC`` -- letting the compiler handle the variance 
for service clients.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to