diff --git a/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java b/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java index b1748b4f508..838ab9dc95e 100644 --- a/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java +++ b/api/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java @@ -42,7 +42,7 @@ public class ListIpForwardingRulesCmd extends BaseListCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.IP_ADDRESS, required=true, type=CommandType.STRING, description="list the rule belonging to this public ip address") + @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list the rule belonging to this public ip address") private String publicIpAddress; @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the ip forwarding rule. Must be used with the domainId parameter.") @@ -50,6 +50,12 @@ public class ListIpForwardingRulesCmd extends BaseListCmd { @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="Lists all rules for this id. If used with the account parameter, returns all rules for an account in the specified domain ID.") private Long domainId; + + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="Lists rule with the specified ID.") + private Long id; + + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="Lists all rules applied to the specified Vm.") + private Long vmId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -80,9 +86,21 @@ public class ListIpForwardingRulesCmd extends BaseListCmd { return domainId; } - @Override + public Long getId() { + return id; + } + + public Long getVmId() { + return vmId; + } + + @Override public void execute(){ - List result = _rulesService.searchForIpForwardingRules(new Ip(publicIpAddress), this.getStartIndex(), this.getPageSizeVal()); + Ip ip = null; + if(publicIpAddress != null){ + ip = new Ip(publicIpAddress); + } + List result = _rulesService.searchForIpForwardingRules(ip, id, vmId, this.getStartIndex(), this.getPageSizeVal()); ListResponse response = new ListResponse(); List ipForwardingResponses = new ArrayList(); for (PortForwardingRule rule : result) { diff --git a/api/src/com/cloud/network/rules/RulesService.java b/api/src/com/cloud/network/rules/RulesService.java index 5914c67af44..4420fdc9833 100644 --- a/api/src/com/cloud/network/rules/RulesService.java +++ b/api/src/com/cloud/network/rules/RulesService.java @@ -26,7 +26,7 @@ import com.cloud.user.Account; import com.cloud.utils.net.Ip; public interface RulesService { - List searchForIpForwardingRules(Ip ip, Long start, Long size); + List searchForIpForwardingRules(Ip ip, Long id, Long vmId, Long start, Long size); /** * Creates a port forwarding rule between two ip addresses or between diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 29e4fe2364d..b704a83c963 100644 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -404,8 +404,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } @Override - public List searchForIpForwardingRules(Ip ip, Long start, Long size) { - return _forwardingDao.searchNatRules(ip, start, size); + public List searchForIpForwardingRules(Ip ip, Long id, Long vmId, Long start, Long size) { + return _forwardingDao.searchNatRules(ip, id, vmId, start, size); } @Override diff --git a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java index a06959b2033..9308fb661c7 100644 --- a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java +++ b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDao.java @@ -36,7 +36,7 @@ public interface PortForwardingRulesDao extends GenericDao listByIp(Ip ip); - List searchNatRules(Ip ip, Long startIndex, Long pageSize); + List searchNatRules(Ip ip, Long id, Long vmId, Long startIndex, Long pageSize); List listByVm(Long vmId); diff --git a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java index 997410ea0db..b5b5f3c0c3b 100644 --- a/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java +++ b/server/src/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java @@ -48,6 +48,7 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase searchNatRules(Ip ip, Long startIndex, Long pageSize) { + public List searchNatRules(Ip ip, Long id, Long vmId, Long startIndex, Long pageSize) { Filter searchFilter = new Filter(PortForwardingRuleVO.class, "id", true, startIndex, pageSize); SearchCriteria sc = AllFieldsSearch.create(); @@ -111,6 +112,14 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase