Search in sources :

Example 1 with FirewallResponse

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

the class ListFirewallRulesCmd method execute.

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

Example 2 with FirewallResponse

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

the class CreateFirewallRuleCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    UserContext callerContext = UserContext.current();
    boolean success = false;
    FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId());
    try {
        UserContext.current().setEventDetails("Rule Id: " + getEntityId());
        success = _firewallService.applyFirewallRules(rule.getSourceIpAddressId(), callerContext.getCaller());
        // 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.revokeFirewallRule(getEntityId(), true);
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create firewall rule");
        }
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) UserContext(com.cloud.user.UserContext) FirewallRule(com.cloud.network.rules.FirewallRule) FirewallResponse(com.cloud.api.response.FirewallResponse)

Aggregations

FirewallResponse (com.cloud.api.response.FirewallResponse)2 FirewallRule (com.cloud.network.rules.FirewallRule)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