GabrielBrascher commented on a change in pull request #3804:
URL: https://github.com/apache/cloudstack/pull/3804#discussion_r640009777



##########
File path: server/src/main/java/com/cloud/api/ApiResponseHelper.java
##########
@@ -2213,13 +2214,75 @@ public NetworkResponse 
createNetworkResponse(ResponseView view, Network network)
                         CapabilityResponse capabilityResponse = new 
CapabilityResponse();
                         String capabilityValue = ser_cap_entries.getValue();
                         capabilityResponse.setName(capability.getName());
-                        capabilityResponse.setValue(capabilityValue);
+                        if (Service.Lb == service && 
capability.getName().equals(Capability.SupportedLBIsolation.getName())) {
+                             
capabilityResponse.setValue(networkOffering.isDedicatedLB() ? "dedicated" : 
"shared");
+                        } else {
+                            capabilityResponse.setValue(capabilityValue);
+                        }
+                        if 
(capability.getName().equals(Capability.SupportedLBIsolation.getName()) || 
capability.getName().equals(Capability.SupportedSourceNatTypes.getName())

Review comment:
       Maybe an alternative would be creating a variable in this class defining 
a Set of Strings that fit in this conditional.
   This would look something similar to:
   ```
   private final Set<String> <insertNameHere> = new 
HashSet<>(Arrays.asList(Capability.SupportedLBIsolation.getName(),
                                                                             
Capability.SupportedSourceNatTypes.getName(),
                                                                             
Capability.RedundantRouter.getName()));
   ...
   ...
   ...
        if (<insertNameHere>.contains(capability.getName())) {
             capabilityResponse.setCanChoose(true);
        }
   ...
   ...
   ```

##########
File path: server/src/main/java/com/cloud/api/ApiResponseHelper.java
##########
@@ -2213,13 +2214,75 @@ public NetworkResponse 
createNetworkResponse(ResponseView view, Network network)
                         CapabilityResponse capabilityResponse = new 
CapabilityResponse();
                         String capabilityValue = ser_cap_entries.getValue();
                         capabilityResponse.setName(capability.getName());
-                        capabilityResponse.setValue(capabilityValue);
+                        if (Service.Lb == service && 
capability.getName().equals(Capability.SupportedLBIsolation.getName())) {
+                             
capabilityResponse.setValue(networkOffering.isDedicatedLB() ? "dedicated" : 
"shared");
+                        } else {
+                            capabilityResponse.setValue(capabilityValue);
+                        }
+                        if 
(capability.getName().equals(Capability.SupportedLBIsolation.getName()) || 
capability.getName().equals(Capability.SupportedSourceNatTypes.getName())
+                                || 
capability.getName().equals(Capability.RedundantRouter.getName())) {
+                            capabilityResponse.setCanChoose(true);
+                        } else {
+                            capabilityResponse.setCanChoose(false);
+                        }
                         capabilityResponse.setObjectName("capability");
                         capabilityResponses.add(capabilityResponse);
                     }
-                    serviceResponse.setCapabilities(capabilityResponses);
                 }
 
+                if (Service.SourceNat == service) {
+                    // overwrite
+                    capabilityResponses = new ArrayList<CapabilityResponse>();
+                    CapabilityResponse sharedSourceNat = new 
CapabilityResponse();
+                    
sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
+                    
sharedSourceNat.setValue(networkOffering.isSharedSourceNat() ? "perzone" : 
"peraccount");
+                    sharedSourceNat.setCanChoose(true);
+                    capabilityResponses.add(sharedSourceNat);
+
+                    CapabilityResponse redundantRouter = new 
CapabilityResponse();
+                    
redundantRouter.setName(Capability.RedundantRouter.getName());
+                    
redundantRouter.setValue(networkOffering.isRedundantRouter() ? "true" : 
"false");
+                    redundantRouter.setCanChoose(true);
+                    capabilityResponses.add(redundantRouter);
+
+                } else if (service == Service.StaticNat) {
+                    CapabilityResponse eIp = new CapabilityResponse();
+                    eIp.setName(Capability.ElasticIp.getName());
+                    eIp.setValue(networkOffering.isElasticIp() ? "true" : 
"false");
+                    eIp.setCanChoose(false);
+                    capabilityResponses.add(eIp);
+
+                    CapabilityResponse associatePublicIp = new 
CapabilityResponse();
+                    
associatePublicIp.setName(Capability.AssociatePublicIP.getName());
+                    
associatePublicIp.setValue(networkOffering.isAssociatePublicIP() ? "true" : 
"false");
+                    associatePublicIp.setCanChoose(false);
+                    capabilityResponses.add(associatePublicIp);
+
+                } else if (Service.Lb == service) {
+                    CapabilityResponse eLb = new CapabilityResponse();
+                    eLb.setName(Capability.ElasticLb.getName());
+                    eLb.setValue(networkOffering.isElasticLb() ? "true" : 
"false");
+                    eLb.setCanChoose(false);
+                    capabilityResponses.add(eLb);
+
+                    CapabilityResponse inline = new CapabilityResponse();
+                    inline.setName(Capability.InlineMode.getName());
+                    inline.setValue(networkOffering.isInline() ? "true" : 
"false");
+                    inline.setCanChoose(false);
+                    capabilityResponses.add(inline);

Review comment:
       I think that it is possible to extract most of the "duplicated" lines by 
creating a method that returns a CapabilityResponse based on `name`, `value`, 
and `canChoose`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to