Skip to content

Commit

Permalink
VNF: add public ip to nic response and display public ip if nic is ma…
Browse files Browse the repository at this point in the history
…nagement interface
  • Loading branch information
weizhouapache committed Oct 13, 2023
1 parent 9a3dc8b commit f11a978
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ public class NicResponse extends BaseResponse {
@Param(description = "MTU configured on the NIC", since="4.18.0")
private Integer mtu;

@SerializedName(ApiConstants.PUBLIC_IP_ID)
@Param(description = "public IP address id associated with this nic via Static nat rule")
private String publicIpId;

@SerializedName(ApiConstants.PUBLIC_IP)
@Param(description = "public IP address associated with this nic via Static nat rule")
private String publicIp;

public void setVmId(String vmId) {
this.vmId = vmId;
}
Expand Down Expand Up @@ -400,4 +408,12 @@ public void setMtu(Integer mtu) {
public String getVpcId() {
return vpcId;
}

public void setPublicIpId(String publicIpId) {
this.publicIpId = publicIpId;
}

public void setPublicIp(String publicIp) {
this.publicIp = publicIp;
}
}
4 changes: 4 additions & 0 deletions server/src/main/java/com/cloud/api/ApiDBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,10 @@ public static IpAddress findIpByAssociatedVmId(long vmId) {
return s_ipAddressDao.findByAssociatedVmId(vmId);
}

public static IpAddress findIpByAssociatedVmIdAndNetworkId(long vmId, long networkId) {
return s_ipAddressDao.findByVmIdAndNetworkId(networkId, vmId);
}

public static String getHaTag() {
return s_haMgr.getHaTag();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.cloud.api.query.vo.UserVmJoinVO;
import com.cloud.gpu.GPU;
import com.cloud.host.ControlState;
import com.cloud.network.IpAddress;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.service.ServiceOfferingDetailsVO;
Expand Down Expand Up @@ -331,6 +332,12 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
}
nicResponse.setSecondaryIps(ipList);
}
IpAddress publicIp = ApiDBUtils.findIpByAssociatedVmIdAndNetworkId(userVm.getId(), userVm.getNetworkId());
if (publicIp != null) {
nicResponse.setPublicIpId(publicIp.getUuid());
nicResponse.setPublicIp(publicIp.getAddress().toString());
}

nicResponse.setObjectName("nic");

List<NicExtraDhcpOptionResponse> nicExtraDhcpOptionResponses = _nicExtraDhcpOptionDao.listByNicId(nic_id).stream()
Expand Down Expand Up @@ -546,6 +553,11 @@ public UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse userVm
}
nicResponse.setSecondaryIps(ipList);
}
IpAddress publicIp = ApiDBUtils.findIpByAssociatedVmIdAndNetworkId(uvo.getId(), uvo.getNetworkId());
if (publicIp != null) {
nicResponse.setPublicIpId(publicIp.getUuid());
nicResponse.setPublicIp(publicIp.getAddress().toString());
}

/* 18: extra dhcp options */
nicResponse.setObjectName("nic");
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/view/DetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ export default {
for (const nic of this.resource.nic) {
if (managementDeviceIds.includes(parseInt(nic.deviceid)) && nic.ipaddress) {
managementIps.push(nic.ipaddress)
if (nic.publicip) {
managementIps.push(nic.publicip)
}
}
}
if (this.resource.publicip && managementDeviceIds.includes(0)) {
managementIps.push(this.resource.publicip)
}
if (accessMethods) {
const accessMethodsArray = accessMethods.split(',')
Expand Down

0 comments on commit f11a978

Please sign in to comment.