mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
listPublicIpAddresses api: return networkId (the id of the network ip belongs to) and associatedNetworkId.
This commit is contained in:
parent
eb1f1da035
commit
b437b8b977
@ -62,6 +62,9 @@ public class IPAddressResponse extends BaseResponse {
|
||||
@SerializedName("associatednetworkid") @Param(description="the ID of the Network associated with the IP address")
|
||||
private Long associatedNetworkId;
|
||||
|
||||
@SerializedName("networkid") @Param(description="the ID of the Network where ip belongs to")
|
||||
private Long networkId;
|
||||
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
@ -166,4 +169,11 @@ public class IPAddressResponse extends BaseResponse {
|
||||
this.associatedNetworkId = networkId;
|
||||
}
|
||||
|
||||
public Long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
public void setNetworkId(Long networkId) {
|
||||
this.networkId = networkId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,8 @@ import com.cloud.network.Networks.TrafficType;
|
||||
*/
|
||||
public interface NetworkOffering {
|
||||
|
||||
public static final long PUBLIC_NETWORK_OFFERING_ID = 1;
|
||||
|
||||
public enum GuestIpType {
|
||||
Virtual,
|
||||
Direct,
|
||||
|
||||
@ -30,11 +30,11 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.IPAddressVO;
|
||||
import com.cloud.network.LoadBalancerVO;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkRuleConfigVO;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
@ -42,6 +42,7 @@ import com.cloud.network.dao.NetworkRuleConfigDao;
|
||||
import com.cloud.network.security.SecurityGroup;
|
||||
import com.cloud.network.security.SecurityGroupManager;
|
||||
import com.cloud.network.security.dao.SecurityGroupDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
@ -515,4 +516,12 @@ public class ApiDBUtils {
|
||||
return _networkMgr.getZoneCapabilities(zoneId);
|
||||
}
|
||||
|
||||
public static long getPublicNetworkIdByZone(long zoneId) {
|
||||
List<NetworkVO> networks = _networkDao.listBy(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.PUBLIC_NETWORK_OFFERING_ID, zoneId);
|
||||
if (networks == null) {
|
||||
throw new InvalidParameterValueException("Unable to find public network in zone " + zoneId);
|
||||
}
|
||||
return networks.get(0).getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -594,13 +594,14 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
public IPAddressResponse createIPAddressResponse(IpAddress ipAddress) {
|
||||
VlanVO vlan = ApiDBUtils.findVlanById(ipAddress.getVlanId());
|
||||
boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
|
||||
long zoneId = ipAddress.getDataCenterId();
|
||||
|
||||
IPAddressResponse ipResponse = new IPAddressResponse();
|
||||
ipResponse.setIpAddress(ipAddress.getAddress());
|
||||
if (ipAddress.getAllocatedTime() != null) {
|
||||
ipResponse.setAllocated(ipAddress.getAllocatedTime());
|
||||
}
|
||||
ipResponse.setZoneId(ipAddress.getDataCenterId());
|
||||
ipResponse.setZoneId(zoneId);
|
||||
ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddress.getDataCenterId()).getName());
|
||||
ipResponse.setSourceNat(ipAddress.isSourceNat());
|
||||
|
||||
@ -615,8 +616,14 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
ipResponse.setForVirtualNetwork(forVirtualNetworks);
|
||||
ipResponse.setStaticNat(ipAddress.isOneToOneNat());
|
||||
|
||||
//Network id the ip is associated with
|
||||
ipResponse.setAssociatedNetworkId(ipAddress.getAssociatedNetworkId());
|
||||
|
||||
//Network id the ip belongs to
|
||||
long networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
|
||||
ipResponse.setNetworkId(networkId);
|
||||
|
||||
|
||||
// show this info to admin only
|
||||
Account account = UserContext.current().getAccount();
|
||||
if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user