adding a list command for ip forwarding rules for 1:1 nat, to be consumed by the ui

This commit is contained in:
abhishek 2010-11-18 10:45:46 -08:00
parent 3866926598
commit 020afa6e33
4 changed files with 106 additions and 0 deletions

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<FirewallRuleVO> result = _mgr.searchForIpForwardingRules(this);
ListResponse<FirewallRuleResponse> response = new ListResponse<FirewallRuleResponse>();
List<FirewallRuleResponse> fwResponses = new ArrayList<FirewallRuleResponse>();
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);
}
}

View File

@ -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<VpnUserVO> searchForVpnUsers(ListVpnUsersCmd cmd);
public String getHashKey();
List<FirewallRuleVO> searchForIpForwardingRules(ListIpForwardingRulesCmd cmd);
}

View File

@ -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<FirewallRuleVO> searchForIpForwardingRules(ListIpForwardingRulesCmd cmd){
String ipAddress = cmd.getPublicIpAddress();
Filter searchFilter = new Filter(FirewallRuleVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchCriteria<FirewallRuleVO> 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<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
Account account = UserContext.current().getAccount();