Skip to content

Commit 1b71696

Browse files
authored
api: Add vpc name and uuid to VMs list response (nics) and nics response (#6461)
1 parent bfe1697 commit 1b71696

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

api/src/main/java/org/apache/cloudstack/api/response/NicResponse.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ public void setExtraDhcpOptions(List<NicExtraDhcpOptionResponse> extraDhcpOption
210210
this.extraDhcpOptions = extraDhcpOptions;
211211
}
212212

213+
@SerializedName(ApiConstants.VPC_ID)
214+
@Param(description = "Id of the vpc to which the nic belongs")
215+
private String vpcId;
216+
217+
@SerializedName(ApiConstants.VPC_NAME)
218+
@Param(description = "name of the vpc to which the nic belongs")
219+
private String vpcName;
220+
213221
@Override
214222
public int hashCode() {
215223
final int prime = 31;
@@ -364,4 +372,20 @@ public List<String> getIpAddresses() {
364372
public void setIpAddresses(List<String> ipAddresses) {
365373
this.ipAddresses = ipAddresses;
366374
}
375+
376+
public String getVpcId() {
377+
return vpcId;
378+
}
379+
380+
public void setVpcId(String vpcId) {
381+
this.vpcId = vpcId;
382+
}
383+
384+
public String getVpcName() {
385+
return vpcName;
386+
}
387+
388+
public void setVpcName(String vpcName) {
389+
this.vpcName = vpcName;
390+
}
367391
}

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
import javax.inject.Inject;
3939

40+
import com.cloud.api.query.dao.UserVmJoinDao;
41+
import com.cloud.network.vpc.VpcVO;
4042
import org.apache.cloudstack.acl.ControlledEntity;
4143
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
4244
import org.apache.cloudstack.affinity.AffinityGroup;
@@ -442,6 +444,8 @@ public class ApiResponseHelper implements ResponseGenerator {
442444
NetworkOfferingDao networkOfferingDao;
443445
@Inject
444446
Ipv6Service ipv6Service;
447+
@Inject
448+
UserVmJoinDao userVmJoinDao;
445449

446450
@Override
447451
public UserResponse createUserResponse(User user) {
@@ -4318,6 +4322,13 @@ public NicResponse createNicResponse(Nic result) {
43184322
response.setNsxLogicalSwitchPort(((NicVO)result).getNsxLogicalSwitchPortUuid());
43194323
}
43204324
}
4325+
4326+
UserVmJoinVO userVm = userVmJoinDao.findById(vm.getId());
4327+
if (userVm != null && userVm.getVpcUuid() != null) {
4328+
response.setVpcId(userVm.getVpcUuid());
4329+
VpcVO vpc = _entityMgr.findByUuidIncludingRemoved(VpcVO.class, userVm.getVpcUuid());
4330+
response.setVpcName(vpc.getName());
4331+
}
43214332
return response;
43224333
}
43234334

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import javax.inject.Inject;
3030

31+
import com.cloud.network.vpc.VpcVO;
32+
import com.cloud.network.vpc.dao.VpcDao;
3133
import com.cloud.storage.DiskOfferingVO;
3234
import org.apache.cloudstack.affinity.AffinityGroupResponse;
3335
import org.apache.cloudstack.annotation.AnnotationService;
@@ -88,6 +90,8 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
8890
@Inject
8991
private AnnotationDao annotationDao;
9092
@Inject
93+
private VpcDao vpcDao;
94+
@Inject
9195
UserStatisticsDao userStatsDao;
9296

9397
private final SearchBuilder<UserVmJoinVO> VmDetailSearch;
@@ -291,6 +295,12 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
291295
if (userVm.getGuestType() != null) {
292296
nicResponse.setType(userVm.getGuestType().toString());
293297
}
298+
299+
if (userVm.getVpcUuid() != null) {
300+
nicResponse.setVpcId(userVm.getVpcUuid());
301+
VpcVO vpc = vpcDao.findByUuidIncludingRemoved(userVm.getVpcUuid());
302+
nicResponse.setVpcName(vpc.getName());
303+
}
294304
nicResponse.setIsDefault(userVm.isDefaultNic());
295305
nicResponse.setDeviceId(String.valueOf(userVm.getNicDeviceId()));
296306
List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(userVm.getNicId());

0 commit comments

Comments
 (0)