listPublicIpAddresses api: return networkId (the id of the network ip belongs to) and associatedNetworkId.

This commit is contained in:
alena 2010-12-23 11:51:56 -08:00
parent eb1f1da035
commit b437b8b977
4 changed files with 31 additions and 3 deletions

View File

@ -62,6 +62,9 @@ public class IPAddressResponse extends BaseResponse {
@SerializedName("associatednetworkid") @Param(description="the ID of the Network associated with the IP address") @SerializedName("associatednetworkid") @Param(description="the ID of the Network associated with the IP address")
private Long associatedNetworkId; private Long associatedNetworkId;
@SerializedName("networkid") @Param(description="the ID of the Network where ip belongs to")
private Long networkId;
public String getIpAddress() { public String getIpAddress() {
return ipAddress; return ipAddress;
} }
@ -166,4 +169,11 @@ public class IPAddressResponse extends BaseResponse {
this.associatedNetworkId = networkId; this.associatedNetworkId = networkId;
} }
public Long getNetworkId() {
return networkId;
}
public void setNetworkId(Long networkId) {
this.networkId = networkId;
}
} }

View File

@ -26,6 +26,8 @@ import com.cloud.network.Networks.TrafficType;
*/ */
public interface NetworkOffering { public interface NetworkOffering {
public static final long PUBLIC_NETWORK_OFFERING_ID = 1;
public enum GuestIpType { public enum GuestIpType {
Virtual, Virtual,
Direct, Direct,

View File

@ -30,11 +30,11 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.IPAddressVO; import com.cloud.network.IPAddressVO;
import com.cloud.network.LoadBalancerVO; import com.cloud.network.LoadBalancerVO;
import com.cloud.network.Network; 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.NetworkManager;
import com.cloud.network.NetworkRuleConfigVO; import com.cloud.network.NetworkRuleConfigVO;
import com.cloud.network.NetworkVO; 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.IPAddressDao;
import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.NetworkDao; 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.SecurityGroup;
import com.cloud.network.security.SecurityGroupManager; import com.cloud.network.security.SecurityGroupManager;
import com.cloud.network.security.dao.SecurityGroupDao; import com.cloud.network.security.dao.SecurityGroupDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.offerings.dao.NetworkOfferingDao;
@ -515,4 +516,12 @@ public class ApiDBUtils {
return _networkMgr.getZoneCapabilities(zoneId); 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();
}
} }

View File

@ -594,13 +594,14 @@ public class ApiResponseHelper implements ResponseGenerator {
public IPAddressResponse createIPAddressResponse(IpAddress ipAddress) { public IPAddressResponse createIPAddressResponse(IpAddress ipAddress) {
VlanVO vlan = ApiDBUtils.findVlanById(ipAddress.getVlanId()); VlanVO vlan = ApiDBUtils.findVlanById(ipAddress.getVlanId());
boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork); boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
long zoneId = ipAddress.getDataCenterId();
IPAddressResponse ipResponse = new IPAddressResponse(); IPAddressResponse ipResponse = new IPAddressResponse();
ipResponse.setIpAddress(ipAddress.getAddress()); ipResponse.setIpAddress(ipAddress.getAddress());
if (ipAddress.getAllocatedTime() != null) { if (ipAddress.getAllocatedTime() != null) {
ipResponse.setAllocated(ipAddress.getAllocatedTime()); ipResponse.setAllocated(ipAddress.getAllocatedTime());
} }
ipResponse.setZoneId(ipAddress.getDataCenterId()); ipResponse.setZoneId(zoneId);
ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddress.getDataCenterId()).getName()); ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddress.getDataCenterId()).getName());
ipResponse.setSourceNat(ipAddress.isSourceNat()); ipResponse.setSourceNat(ipAddress.isSourceNat());
@ -615,8 +616,14 @@ public class ApiResponseHelper implements ResponseGenerator {
ipResponse.setForVirtualNetwork(forVirtualNetworks); ipResponse.setForVirtualNetwork(forVirtualNetworks);
ipResponse.setStaticNat(ipAddress.isOneToOneNat()); ipResponse.setStaticNat(ipAddress.isOneToOneNat());
//Network id the ip is associated with
ipResponse.setAssociatedNetworkId(ipAddress.getAssociatedNetworkId()); ipResponse.setAssociatedNetworkId(ipAddress.getAssociatedNetworkId());
//Network id the ip belongs to
long networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
ipResponse.setNetworkId(networkId);
// show this info to admin only // show this info to admin only
Account account = UserContext.current().getAccount(); Account account = UserContext.current().getAccount();
if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) { if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) {