api: Add vpcid in usage network response (#4361)

* Add vpcid in usage network response

Currently vpcid is displayed in listUsageNetworks response.
Add the vpcid so that we can see to which vpc, the network belongs

* use new function to get removed
This commit is contained in:
Rakesh 2020-11-23 09:32:25 +01:00 committed by GitHub
parent aa67f9c6e2
commit beb1edcdbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -144,6 +144,10 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen
@Param(description = "True if the resource is default")
private Boolean isDefault;
@SerializedName("vpcid")
@Param(description = "id of the vpc")
private String vpcId;
public UsageRecordResponse() {
tags = new LinkedHashSet<ResourceTagResponse>();
}
@ -276,4 +280,8 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen
public String getDomainName(){
return domainName;
}
public void setVpcId(String vpcId) {
this.vpcId = vpcId;
}
}

View File

@ -1571,6 +1571,10 @@ public class ApiDBUtils {
return s_vpcDao.findById(vpcId);
}
public static VpcVO findVpcByIdIncludingRemoved(long vpcId) {
return s_vpcDao.findByIdIncludingRemoved(vpcId);
}
public static SnapshotPolicy findSnapshotPolicyById(long policyId) {
return s_snapshotPolicyDao.findById(policyId);
}

View File

@ -3471,8 +3471,15 @@ public class ApiResponseHelper implements ResponseGenerator {
network = _entityMgr.findByIdIncludingRemoved(NetworkVO.class, usageRecord.getNetworkId().toString());
if (network != null) {
resourceType = ResourceObjectType.Network;
resourceId = network.getId();
usageRecResponse.setNetworkId(network.getUuid());
if (network.getTrafficType() == TrafficType.Public) {
VirtualRouter router = ApiDBUtils.findDomainRouterById(usageRecord.getUsageId());
Vpc vpc = ApiDBUtils.findVpcByIdIncludingRemoved(router.getVpcId());
usageRecResponse.setVpcId(vpc.getUuid());
resourceId = vpc.getId();
} else {
usageRecResponse.setNetworkId(network.getUuid());
resourceId = network.getId();
}
usageRecResponse.setResourceName(network.getName());
}
}