Search in sources :

Example 6 with FirewallRule

use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.

the class CreateFirewallRuleCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException {
    final 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(com.cloud.api.ServerApiException) CallContext(com.cloud.context.CallContext) FirewallRule(com.cloud.legacymodel.network.FirewallRule) FirewallResponse(com.cloud.api.response.FirewallResponse)

Example 7 with FirewallRule

use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.

the class CreateFirewallRuleCmd method create.

@Override
public void create() {
    if (getSourceCidrList() != null) {
        for (final String cidr : getSourceCidrList()) {
            if (!NetUtils.isValidIp4Cidr(cidr)) {
                throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Source CIDRs formatting error " + cidr);
            }
        }
    }
    try {
        final FirewallRule result = _firewallService.createIngressFirewallRule(this);
        if (result != null) {
            setEntityId(result.getId());
            setEntityUuid(result.getUuid());
        }
    } catch (final NetworkRuleConflictException ex) {
        s_logger.info("Network rule conflict: " + ex.getMessage());
        s_logger.trace("Network Rule Conflict: ", ex);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) FirewallRule(com.cloud.legacymodel.network.FirewallRule) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException)

Example 8 with FirewallRule

use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.

the class ListEgressFirewallRulesCmd method execute.

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

Example 9 with FirewallRule

use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.

the class ListFirewallRulesCmd method execute.

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

Example 10 with FirewallRule

use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.

the class UpdateEgressFirewallRuleCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    CallContext.current().setEventDetails("Rule Id: " + id);
    final 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.legacymodel.network.FirewallRule) FirewallResponse(com.cloud.api.response.FirewallResponse)

Aggregations

FirewallRule (com.cloud.legacymodel.network.FirewallRule)23 ArrayList (java.util.ArrayList)14 FirewallResponse (com.cloud.api.response.FirewallResponse)7 FirewallRuleVO (com.cloud.network.rules.FirewallRuleVO)7 ServerApiException (com.cloud.api.ServerApiException)5 NetworkRuleConflictException (com.cloud.legacymodel.exceptions.NetworkRuleConflictException)4 StaticNatRule (com.cloud.legacymodel.network.StaticNatRule)4 IpAddress (com.cloud.network.IpAddress)4 List (java.util.List)4 ListResponse (com.cloud.api.response.ListResponse)3 ActionEvent (com.cloud.event.ActionEvent)3 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)3 PublicIpAddress (com.cloud.network.PublicIpAddress)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)3 IpForwardingRuleResponse (com.cloud.api.response.IpForwardingRuleResponse)2 CallContext (com.cloud.context.CallContext)2 Zone (com.cloud.db.model.Zone)2 SetFirewallRulesCommand (com.cloud.legacymodel.communication.command.SetFirewallRulesCommand)2 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)2