mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 13866: return publicIp info in listVms api response when vm is linked to public ip via static nat
Reviewed-by: Frank
This commit is contained in:
parent
da484225f7
commit
4d27f3c44b
@ -147,6 +147,11 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
@SerializedName("hypervisor") @Param(description="the hypervisor on which the template runs")
|
||||
private String hypervisor;
|
||||
|
||||
@SerializedName(ApiConstants.PUBLIC_IP_ID) @Param(description="public IP address id associated with vm via Static nat rule")
|
||||
private IdentityProxy publicIpId = new IdentityProxy("user_ip_address");
|
||||
|
||||
@SerializedName(ApiConstants.PUBLIC_IP) @Param(description="public IP address id associated with vm via Static nat rule")
|
||||
private String publicIp;
|
||||
|
||||
public void setHypervisor(String hypervisor) {
|
||||
this.hypervisor = hypervisor;
|
||||
@ -322,4 +327,12 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public void setPublicIpId(Long publicIpId) {
|
||||
this.publicIpId.setValue(publicIpId);
|
||||
}
|
||||
|
||||
public void setPublicIp(String publicIp) {
|
||||
this.publicIp = publicIp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.IPAddressVO;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.LoadBalancerVO;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Provider;
|
||||
@ -730,4 +731,8 @@ public class ApiDBUtils {
|
||||
ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName("Cloud.Com-SoftwareRouter");
|
||||
return serviceOffering.getId();
|
||||
}
|
||||
|
||||
public static IpAddress findIpByAssociatedVmId(long vmId) {
|
||||
return _ipAddressDao.findByAssociatedVmId(vmId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1442,6 +1442,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
userVmResponse.setNics(nicResponses);
|
||||
}
|
||||
|
||||
IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(userVm.getId());
|
||||
if (ip != null) {
|
||||
userVmResponse.setPublicIpId(ip.getId());
|
||||
userVmResponse.setPublicIp(ip.getAddress().addr());
|
||||
}
|
||||
|
||||
userVmResponse.setObjectName(objectName);
|
||||
vmResponses.add(userVmResponse);
|
||||
@ -2869,6 +2875,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
if (userVm.getDisplayName() != null) {
|
||||
userVmData.setDisplayName(userVm.getDisplayName());
|
||||
} else {
|
||||
userVmData.setDisplayName(userVm.getHostName());
|
||||
}
|
||||
userVmData.setDomainId(userVm.getDomainId());
|
||||
|
||||
@ -2891,6 +2899,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setHypervisor(userVmData.getHypervisor());
|
||||
userVmResponse.setId(userVmData.getId());
|
||||
userVmResponse.setName(userVmData.getName());
|
||||
|
||||
userVmResponse.setDisplayName(userVmData.getDisplayName());
|
||||
|
||||
populateAccount(userVmResponse, userVmData.getAccountId());
|
||||
@ -2968,6 +2977,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
nicResponses.add(nr);
|
||||
}
|
||||
userVmResponse.setNics(new ArrayList<NicResponse>(nicResponses));
|
||||
userVmResponse.setPublicIpId(userVmData.getPublicIpId());
|
||||
userVmResponse.setPublicIp(userVmData.getPublicIp());
|
||||
|
||||
return userVmResponse;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
||||
"vm_template.enable_password, service_offering.id, disk_offering.name, storage_pool.id, storage_pool.pool_type, " +
|
||||
"service_offering.cpu, service_offering.speed, service_offering.ram_size, volumes.id, volumes.device_id, volumes.volume_type, security_group.id, security_group.name, " +
|
||||
"security_group.description, nics.id, nics.ip4_address, nics.default_nic, nics.gateway, nics.network_id, nics.netmask, nics.mac_address, nics.broadcast_uri, nics.isolation_uri, " +
|
||||
"networks.traffic_type, networks.guest_type from vm_instance " +
|
||||
"networks.traffic_type, networks.guest_type, user_ip_address.id, user_ip_address.public_ip_address from vm_instance " +
|
||||
"left join account on vm_instance.account_id=account.id " +
|
||||
"left join domain on vm_instance.domain_id=domain.id " +
|
||||
"left join instance_group_vm_map on vm_instance.id=instance_group_vm_map.instance_id " +
|
||||
@ -99,6 +99,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
||||
"left join security_group on security_group_vm_map.security_group_id=security_group.id " +
|
||||
"left join nics on vm_instance.id=nics.instance_id " +
|
||||
"left join networks on nics.network_id=networks.id " +
|
||||
"left join user_ip_address on user_ip_address.vm_id=vm_instance.id " +
|
||||
"where vm_instance.id in (";
|
||||
|
||||
private static final int VM_DETAILS_BATCH_SIZE=100;
|
||||
@ -516,6 +517,13 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
||||
nicResponse.setObjectName("nic");
|
||||
userVmData.addNic(nicResponse);
|
||||
}
|
||||
|
||||
long publicIpId = rs.getLong("user_ip_address.id");
|
||||
if (publicIpId > 0){
|
||||
userVmData.setPublicIpId(publicIpId);
|
||||
userVmData.setPublicIp(rs.getString("user_ip_address.public_ip_address"));
|
||||
}
|
||||
|
||||
return userVmData;
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +68,8 @@ public class UserVmData {
|
||||
private Set<NicData> nics;
|
||||
private String hypervisor;
|
||||
private long accountId;
|
||||
private Long publicIpId;
|
||||
private String publicIp;
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
@ -684,10 +686,21 @@ public class UserVmData {
|
||||
public void setAccountId(long accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Long getPublicIpId() {
|
||||
return publicIpId;
|
||||
}
|
||||
|
||||
public void setPublicIpId(Long publicIpId) {
|
||||
this.publicIpId = publicIpId;
|
||||
}
|
||||
|
||||
public String getPublicIp() {
|
||||
return publicIp;
|
||||
}
|
||||
|
||||
public void setPublicIp(String publicIp) {
|
||||
this.publicIp = publicIp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user