diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 7d90f6da4e2..aad267c4b5c 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -110,6 +110,7 @@ updatePortForwardingRule=com.cloud.api.commands.UpdatePortForwardingRuleCmd;15
#### NAT commands
createIpForwardingRule=com.cloud.api.commands.CreateIpForwardingRuleCmd;15
deleteIpForwardingRule=com.cloud.api.commands.DeleteIpForwardingRuleCmd;15
+listIpForwardingRules=com.cloud.api.commands.ListIpForwardingRulesCmd;15
#### load balancer commands
createLoadBalancerRule=com.cloud.api.commands.CreateLoadBalancerRuleCmd;15
diff --git a/server/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java b/server/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java
new file mode 100644
index 00000000000..9ba1cd6c092
--- /dev/null
+++ b/server/src/com/cloud/api/commands/ListIpForwardingRulesCmd.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
+ *
+ * This software is licensed under the GNU General Public License v3 or later.
+ *
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+package com.cloud.api.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.ApiResponseHelper;
+import com.cloud.api.BaseListCmd;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.response.FirewallRuleResponse;
+import com.cloud.api.response.ListResponse;
+import com.cloud.network.FirewallRuleVO;
+
+@Implementation(description="List the ip forwarding rules", responseObject=FirewallRuleResponse.class)
+public class ListIpForwardingRulesCmd extends BaseListCmd {
+ public static final Logger s_logger = Logger.getLogger(ListIpForwardingRulesCmd.class.getName());
+
+ private static final String s_name = "listipforwardingrulesresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list the rule belonging to this public ip address")
+ private String publicIpAddress;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+ @Override
+ public String getName() {
+ return s_name;
+ }
+
+ public String getPublicIpAddress() {
+ return publicIpAddress;
+ }
+
+ public void setPublicIpAddress(String publicIpAddress) {
+ this.publicIpAddress = publicIpAddress;
+ }
+
+ @Override
+ public void execute(){
+ List result = _mgr.searchForIpForwardingRules(this);
+ ListResponse response = new ListResponse();
+ List fwResponses = new ArrayList();
+ for (FirewallRuleVO rule : result) {
+ FirewallRuleResponse resp = ApiResponseHelper.createFirewallRuleResponse(rule);
+ if (resp != null) {
+ resp.setObjectName("firewallrule");
+ fwResponses.add(resp);
+ }
+ }
+ response.setResponses(fwResponses);
+ response.setResponseName(getName());
+ this.setResponseObject(response);
+ }
+
+}
diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java
index 9864c7ab792..0dc2c5657f4 100755
--- a/server/src/com/cloud/server/ManagementServer.java
+++ b/server/src/com/cloud/server/ManagementServer.java
@@ -46,6 +46,7 @@ import com.cloud.api.commands.ListGuestOsCategoriesCmd;
import com.cloud.api.commands.ListGuestOsCmd;
import com.cloud.api.commands.ListHostsCmd;
import com.cloud.api.commands.ListHypervisorsCmd;
+import com.cloud.api.commands.ListIpForwardingRulesCmd;
import com.cloud.api.commands.ListIsosCmd;
import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
@@ -1043,4 +1044,6 @@ public interface ManagementServer {
public List searchForVpnUsers(ListVpnUsersCmd cmd);
public String getHashKey();
+
+ List searchForIpForwardingRules(ListIpForwardingRulesCmd cmd);
}
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index aa2f0073f87..8e37a8825de 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -96,6 +96,7 @@ import com.cloud.api.commands.ListGuestOsCategoriesCmd;
import com.cloud.api.commands.ListGuestOsCmd;
import com.cloud.api.commands.ListHostsCmd;
import com.cloud.api.commands.ListHypervisorsCmd;
+import com.cloud.api.commands.ListIpForwardingRulesCmd;
import com.cloud.api.commands.ListIsosCmd;
import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
@@ -2402,6 +2403,22 @@ public class ManagementServerImpl implements ManagementServer {
return _templateDao.findById(templateId);
}
+ @Override
+ public List searchForIpForwardingRules(ListIpForwardingRulesCmd cmd){
+ String ipAddress = cmd.getPublicIpAddress();
+ Filter searchFilter = new Filter(FirewallRuleVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
+ SearchCriteria sc = _firewallRulesDao.createSearchCriteria();
+
+ if (ipAddress != null) {
+ sc.addAnd("publicIpAddress", SearchCriteria.Op.EQ, ipAddress);
+ }
+
+ //search for rules with protocol = nat
+ sc.addAnd("protocol", SearchCriteria.Op.EQ, NetUtils.NAT_PROTO);
+
+ return _firewallRulesDao.search(sc, searchFilter);
+ }
+
@Override
public List searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
Account account = UserContext.current().getAccount();