From 31a3b878a3f6d31685fd409537fe730d356a5d61 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 17 Feb 2012 15:39:52 -0800 Subject: [PATCH] bug 13864: for elastic IP address return the purpose (staticNat or Lb) in listPublicIpAddresses api response Reviewed-by: Frank --- api/src/com/cloud/api/ApiConstants.java | 1 + .../com/cloud/api/response/IPAddressResponse.java | 13 ++++++++----- api/src/com/cloud/network/IpAddress.java | 5 +++++ server/src/com/cloud/api/ApiResponseHelper.java | 9 +++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index ad986c67350..4ed625c40f7 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -331,6 +331,7 @@ public class ApiConstants { public static final String IS_STATIC_NAT = "isstaticnat"; public static final String SORT_BY = "sortby"; public static final String CHANGE_CIDR = "changecidr"; + public static final String PURPOSE = "purpose"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/response/IPAddressResponse.java b/api/src/com/cloud/api/response/IPAddressResponse.java index 40def18c650..0617aef844a 100644 --- a/api/src/com/cloud/api/response/IPAddressResponse.java +++ b/api/src/com/cloud/api/response/IPAddressResponse.java @@ -93,7 +93,10 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR private String state; @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network this belongs to") - private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + + @SerializedName(ApiConstants.PURPOSE) @Param(description="purpose of the IP address. In Acton this value is not null for Elastic IPs only, and can have either StaticNat or LB value") + private String purpose; /* @SerializedName(ApiConstants.JOB_ID) @Param(description="shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the volume") @@ -207,11 +210,11 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR this.physicalNetworkId.setValue(physicalNetworkId); } - public long getphysicalNetworkId() { - return physicalNetworkId.getValue(); - } - public void setIsElastic(Boolean isElastic) { this.isElastic = isElastic; } + + public void setPurpose(String purpose) { + this.purpose = purpose; + } } diff --git a/api/src/com/cloud/network/IpAddress.java b/api/src/com/cloud/network/IpAddress.java index 7b1d06fd709..e4eefe89d6b 100644 --- a/api/src/com/cloud/network/IpAddress.java +++ b/api/src/com/cloud/network/IpAddress.java @@ -44,6 +44,11 @@ public interface IpAddress extends ControlledEntity { Releasing, // The IP address is being released for other network elements and is not ready for allocation. Free // The IP address is ready to be allocated. } + + enum Purpose { + StaticNat, + Lb + } long getDataCenterId(); diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index abf5d5364ee..ebf29e715d5 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -759,6 +759,15 @@ public class ApiResponseHelper implements ResponseGenerator { ipResponse.setVlanId(ipAddress.getVlanId()); ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanId()).getVlanTag()); } + + if (ipAddress.getElastic()) { + if (ipAddress.isOneToOneNat()) { + ipResponse.setPurpose(IpAddress.Purpose.StaticNat.toString()); + } else { + ipResponse.setPurpose(IpAddress.Purpose.Lb.toString()); + } + } + ipResponse.setObjectName("ipaddress"); return ipResponse; }