CLOUDSTACK-7159 Added "state" parameter to the "listPublicIpAddresses" API call

Signed-off-by: Ilia Shakitko <i.shakitko@tech.leaseweb.com>
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Ilia Shakitko 2014-08-05 17:58:46 +02:00 committed by Rohit Yadav
parent 3433eb7c09
commit 07f916dfc6
2 changed files with 29 additions and 16 deletions

View File

@ -53,6 +53,9 @@ public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
@Parameter(name = ApiConstants.ALLOCATED_ONLY, type = CommandType.BOOLEAN, description = "limits search results to allocated public IP addresses")
private Boolean allocatedOnly;
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "lists all public IP addresses by state")
private String state;
@Parameter(name = ApiConstants.FOR_VIRTUAL_NETWORK, type = CommandType.BOOLEAN, description = "the virtual network for the IP address")
private Boolean forVirtualNetwork;
@ -150,6 +153,22 @@ public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
return super.getDisplay();
}
public Boolean isForLoadBalancing() {
return forLoadBalancing;
}
public Boolean getForVirtualNetwork() {
return forVirtualNetwork;
}
public Boolean getForLoadBalancing() {
return forLoadBalancing;
}
public String getState() {
return state;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -178,20 +197,4 @@ public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
public ApiCommandJobType getInstanceType() {
return ApiCommandJobType.IpAddress;
}
public Boolean isForLoadBalancing() {
return forLoadBalancing;
}
public Boolean getAllocatedOnly() {
return allocatedOnly;
}
public Boolean getForVirtualNetwork() {
return forVirtualNetwork;
}
public Boolean getForLoadBalancing() {
return forLoadBalancing;
}
}

View File

@ -1730,9 +1730,14 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
Boolean forDisplay = cmd.getDisplay();
Map<String, String> tags = cmd.getTags();
String state = cmd.getState();
Boolean isAllocated = cmd.isAllocatedOnly();
if (isAllocated == null) {
isAllocated = Boolean.TRUE;
if (state != null) {
isAllocated = Boolean.FALSE;
}
}
Filter searchFilter = new Filter(IPAddressVO.class, "address", false, cmd.getStartIndex(), cmd.getPageSizeVal());
@ -1763,6 +1768,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
sb.and("isSourceNat", sb.entity().isSourceNat(), SearchCriteria.Op.EQ);
sb.and("isStaticNat", sb.entity().isOneToOneNat(), SearchCriteria.Op.EQ);
sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ);
if (forLoadBalancing != null && forLoadBalancing) {
@ -1865,6 +1871,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
sc.setParameters("display", forDisplay);
}
if (state != null) {
sc.setParameters("state", state);
}
Pair<List<IPAddressVO>, Integer> result = _publicIpAddressDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends IpAddress>, Integer>(result.first(), result.second());
}