Search in sources :

Example 1 with FirewallRuleResponse

use of com.cloud.api.response.FirewallRuleResponse in project CloudStack-archive by CloudStack-extras.

the class CreatePortForwardingRuleCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    UserContext callerContext = UserContext.current();
    boolean success = true;
    PortForwardingRule rule = null;
    try {
        UserContext.current().setEventDetails("Rule Id: " + getEntityId());
        if (getOpenFirewall()) {
            success = success && _firewallService.applyFirewallRules(ipAddressId, callerContext.getCaller());
        }
        success = success && _rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCaller());
        // State is different after the rule is applied, so get new object here
        rule = _entityMgr.findById(PortForwardingRule.class, getEntityId());
        FirewallRuleResponse fwResponse = new FirewallRuleResponse();
        if (rule != null) {
            fwResponse = _responseGenerator.createPortForwardingRuleResponse(rule);
            setResponseObject(fwResponse);
        }
        fwResponse.setResponseName(getCommandName());
    } finally {
        if (!success || rule == null) {
            if (getOpenFirewall()) {
                _firewallService.revokeRelatedFirewallRule(getEntityId(), true);
            }
            _rulesService.revokePortForwardingRule(getEntityId(), true);
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to apply port forwarding rule");
        }
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) UserContext(com.cloud.user.UserContext) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) FirewallRuleResponse(com.cloud.api.response.FirewallRuleResponse)

Example 2 with FirewallRuleResponse

use of com.cloud.api.response.FirewallRuleResponse in project CloudStack-archive by CloudStack-extras.

the class ListPortForwardingRulesCmd method execute.

@Override
public void execute() {
    List<? extends PortForwardingRule> result = _rulesService.listPortForwardingRules(this);
    ListResponse<FirewallRuleResponse> response = new ListResponse<FirewallRuleResponse>();
    List<FirewallRuleResponse> fwResponses = new ArrayList<FirewallRuleResponse>();
    for (PortForwardingRule fwRule : result) {
        FirewallRuleResponse ruleData = _responseGenerator.createPortForwardingRuleResponse(fwRule);
        ruleData.setObjectName("portforwardingrule");
        fwResponses.add(ruleData);
    }
    response.setResponses(fwResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) FirewallRuleResponse(com.cloud.api.response.FirewallRuleResponse) PortForwardingRule(com.cloud.network.rules.PortForwardingRule)

Aggregations

FirewallRuleResponse (com.cloud.api.response.FirewallRuleResponse)2 PortForwardingRule (com.cloud.network.rules.PortForwardingRule)2 ServerApiException (com.cloud.api.ServerApiException)1 ListResponse (com.cloud.api.response.ListResponse)1 UserContext (com.cloud.user.UserContext)1 ArrayList (java.util.ArrayList)1