Search in sources :

Example 6 with Purpose

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

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
    final Network network = firewall.getNetwork();
    final DomainRouterVO router = (DomainRouterVO) firewall.getRouter();
    final List<? extends FirewallRule> rules = firewall.getRules();
    final List<LoadBalancingRule> loadbalancingRules = firewall.getLoadbalancingRules();
    final Purpose purpose = firewall.getPurpose();
    final Commands cmds = new Commands(Command.OnError.Continue);
    _commandSetupHelper.createPublicIpACLsCommands(router, cmds);
    if (purpose == Purpose.LoadBalancing) {
        _commandSetupHelper.createApplyLoadBalancingRulesCommands(loadbalancingRules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.PortForwarding) {
        _commandSetupHelper.createApplyPortForwardingRulesCommands((List<? extends PortForwardingRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.StaticNat) {
        _commandSetupHelper.createApplyStaticNatRulesCommands((List<StaticNatRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.Firewall) {
        _commandSetupHelper.createApplyFirewallRulesCommands(rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    }
    s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose());
    return false;
}
Also used : LoadBalancingRule(com.cloud.legacymodel.network.LoadBalancingRule) Network(com.cloud.legacymodel.network.Network) Commands(com.cloud.agent.manager.Commands) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) List(java.util.List) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) PortForwardingRule(com.cloud.legacymodel.network.PortForwardingRule) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 7 with Purpose

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

the class FirewallManagerImpl method applyRules.

@Override
public boolean applyRules(final List<? extends FirewallRule> rules, final boolean continueOnError, final boolean updateRulesInDB) throws ResourceUnavailableException {
    boolean success = true;
    if (rules == null || rules.size() == 0) {
        s_logger.debug("There are no rules to forward to the network elements");
        return true;
    }
    final Purpose purpose = rules.get(0).getPurpose();
    if (!_ipAddrMgr.applyRules(rules, purpose, this, continueOnError)) {
        s_logger.warn("Rules are not completely applied");
        return false;
    } else {
        if (updateRulesInDB) {
            for (final FirewallRule rule : rules) {
                if (rule.getState() == FirewallRule.State.Revoke) {
                    final FirewallRuleVO relatedRule = _firewallDao.findByRelatedId(rule.getId());
                    if (relatedRule != null) {
                        s_logger.warn("Can't remove the firewall rule id=" + rule.getId() + " as it has related firewall rule id=" + relatedRule.getId() + "; leaving it in Revoke state");
                        success = false;
                    } else {
                        removeRule(rule);
                        if (rule.getSourceIpAddressId() != null) {
                            // if the rule is the last one for the ip address assigned to VPC, unassign it from the network
                            final IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId());
                            _vpcMgr.unassignIPFromVpcNetwork(ip.getId(), rule.getNetworkId());
                        }
                    }
                } else if (rule.getState() == FirewallRule.State.Add) {
                    final FirewallRuleVO ruleVO = _firewallDao.findById(rule.getId());
                    ruleVO.setState(FirewallRule.State.Active);
                    _firewallDao.update(ruleVO.getId(), ruleVO);
                }
            }
        }
    }
    return success;
}
Also used : Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) IpAddress(com.cloud.network.IpAddress) FirewallRule(com.cloud.legacymodel.network.FirewallRule) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO)

Aggregations

Purpose (com.cloud.legacymodel.network.FirewallRule.Purpose)7 HashSet (java.util.HashSet)4 FirewallRuleVO (com.cloud.network.rules.FirewallRuleVO)3 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)2 Network (com.cloud.legacymodel.network.Network)2 Service (com.cloud.legacymodel.network.Network.Service)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 Commands (com.cloud.agent.manager.Commands)1 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)1 FirewallRule (com.cloud.legacymodel.network.FirewallRule)1 LoadBalancingRule (com.cloud.legacymodel.network.LoadBalancingRule)1 PortForwardingRule (com.cloud.legacymodel.network.PortForwardingRule)1 StaticNatRule (com.cloud.legacymodel.network.StaticNatRule)1 IpAddress (com.cloud.network.IpAddress)1 PublicIp (com.cloud.network.addr.PublicIp)1 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)1 LoadBalancingRulesService (com.cloud.network.lb.LoadBalancingRulesService)1