Copilot commented on code in PR #13325:
URL: https://github.com/apache/cloudstack/pull/13325#discussion_r4230094873
##########
server/src/main/java/com/cloud/api/ApiResponseHelper.java:
##########
@@ -2663,14 +2668,20 @@ public NetworkResponse
createNetworkResponse(ResponseView view, Network network)
response.setVlan(vlan);
}
- // return network details only to Root admin
+ int networkRate;
+ // return network details only to Root admin, and take the network
rate from them to save a lookup
if (view == ResponseView.Full) {
Map<String, String> details = new HashMap<>();
for (NetworkDetailVO detail:
networkDetailsDao.listDetails(network.getId())) {
details.put(detail.getName(),detail.getValue());
}
response.setDetails(details);
+ networkRate =
NumberUtils.toInt(details.get(ApiConstants.NETWORKRATE), -1);
+ } else {
+ NetworkDetailVO networkRateDetail =
networkDetailsDao.findDetail(network.getId(), ApiConstants.NETWORKRATE);
+ networkRate = networkRateDetail != null ?
NumberUtils.toInt(networkRateDetail.getValue(), -1) : -1;
}
+ response.setNetworkRate(networkRate > 0 ? networkRate : -1);
Review Comment:
When the `networkrate` detail is absent (e.g., older rows, partial
migrations, or any failure to persist details), the response defaults to `-1`,
which can incorrectly claim 'unlimited' even if the effective rate should be
limited by the offering/zone config. Consider falling back to computing the
effective rate (e.g., with the same precedence used elsewhere) when the detail
is missing or unparsable, instead of assuming unlimited.
##########
server/src/main/java/com/cloud/api/ApiResponseHelper.java:
##########
@@ -3602,6 +3613,9 @@ public VpcResponse createVpcResponse(ResponseView view,
Vpc vpc) {
response.setVpcOfferingName(voff.getName());
response.setVpcOfferingConserveMode(voff.isConserveMode());
}
+ VpcDetailVO publicNetworkRateDetail =
vpcDetailsDao.findDetail(vpc.getId(), ApiConstants.PUBLIC_NETWORK_RATE);
+ Integer publicNetworkRate = publicNetworkRateDetail != null ?
NumberUtils.toInt(publicNetworkRateDetail.getValue(), -1) : null;
+ response.setPublicNetworkRate((publicNetworkRate == null ||
publicNetworkRate <= 0) ? -1 : publicNetworkRate);
Review Comment:
If the `publicnetworkrate` VPC detail is missing, the response is forced to
`-1` (unlimited), which can misreport the effective limit for VPCs whose
offering/zone config implies a positive rate. A safer behavior is to fall back
to computing the effective rate from the VPC offering + zone config when the
detail is absent, and only use `-1` when that computed value indicates
unlimited.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]