Search in sources :

Example 6 with FirewallResponse

use of org.apache.cloudstack.api.response.FirewallResponse in project cloudstack by apache.

the class ListFirewallRulesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends FirewallRule>, Integer> result = _firewallService.listFirewallRules(this);
    ListResponse<FirewallResponse> response = new ListResponse<FirewallResponse>();
    List<FirewallResponse> fwResponses = new ArrayList<FirewallResponse>();
    for (FirewallRule fwRule : result.first()) {
        FirewallResponse ruleData = _responseGenerator.createFirewallResponse(fwRule);
        ruleData.setObjectName("firewallrule");
        fwResponses.add(ruleData);
    }
    response.setResponses(fwResponses, result.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FirewallRule(com.cloud.network.rules.FirewallRule) FirewallResponse(org.apache.cloudstack.api.response.FirewallResponse)

Example 7 with FirewallResponse

use of org.apache.cloudstack.api.response.FirewallResponse in project cloudstack by apache.

the class CreateEgressFirewallRuleCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    CallContext callerContext = CallContext.current();
    boolean success = false;
    FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId());
    try {
        CallContext.current().setEventDetails("Rule Id: " + getEntityId());
        success = _firewallService.applyEgressFirewallRules(rule, callerContext.getCallingAccount());
        // State is different after the rule is applied, so get new object here
        rule = _entityMgr.findById(FirewallRule.class, getEntityId());
        FirewallResponse fwResponse = new FirewallResponse();
        if (rule != null) {
            fwResponse = _responseGenerator.createFirewallResponse(rule);
            setResponseObject(fwResponse);
        }
        fwResponse.setResponseName(getCommandName());
    } finally {
        if (!success || rule == null) {
            _firewallService.revokeEgressFirewallRule(getEntityId(), true);
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create firewall rule");
        }
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) CallContext(org.apache.cloudstack.context.CallContext) FirewallRule(com.cloud.network.rules.FirewallRule) FirewallResponse(org.apache.cloudstack.api.response.FirewallResponse)

Aggregations

FirewallRule (com.cloud.network.rules.FirewallRule)7 FirewallResponse (org.apache.cloudstack.api.response.FirewallResponse)7 ArrayList (java.util.ArrayList)3 List (java.util.List)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 CallContext (org.apache.cloudstack.context.CallContext)2 IpAddress (com.cloud.network.IpAddress)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 ResourceTag (com.cloud.server.ResourceTag)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1