Search in sources :

Example 1 with FirewallResponse

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

the class CreateFirewallRuleCmd 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.applyIngressFwRules(rule.getSourceIpAddressId(), 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.revokeIngressFwRule(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)

Example 2 with FirewallResponse

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

the class UpdateEgressFirewallRuleCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    CallContext.current().setEventDetails("Rule Id: " + id);
    FirewallRule rule = _firewallService.updateEgressFirewallRule(id, this.getCustomId(), getDisplay());
    FirewallResponse fwResponse = new FirewallResponse();
    if (rule != null) {
        fwResponse = _responseGenerator.createFirewallResponse(rule);
        setResponseObject(fwResponse);
    }
    fwResponse.setResponseName(getCommandName());
}
Also used : FirewallRule(com.cloud.network.rules.FirewallRule) FirewallResponse(org.apache.cloudstack.api.response.FirewallResponse)

Example 3 with FirewallResponse

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

the class UpdateFirewallRuleCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    CallContext.current().setEventDetails("Rule ID: " + id);
    FirewallRule rule = _firewallService.updateIngressFirewallRule(id, this.getCustomId(), getDisplay());
    FirewallResponse fwResponse = new FirewallResponse();
    if (rule != null) {
        fwResponse = _responseGenerator.createFirewallResponse(rule);
        setResponseObject(fwResponse);
    }
    fwResponse.setResponseName(getCommandName());
}
Also used : FirewallRule(com.cloud.network.rules.FirewallRule) FirewallResponse(org.apache.cloudstack.api.response.FirewallResponse)

Example 4 with FirewallResponse

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

the class ListEgressFirewallRulesCmd 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>();
    if (result != null) {
        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 5 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)

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