Search in sources :

Example 16 with StaticNatRule

use of com.cloud.network.rules.StaticNatRule in project cloudstack by apache.

the class CommandSetupHelper method createApplyStaticNatRulesCommands.

public void createApplyStaticNatRulesCommands(final List<? extends StaticNatRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
    if (rules != null) {
        for (final StaticNatRule rule : rules) {
            final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            final StaticNatRuleTO ruleTO = new StaticNatRuleTO(rule, null, sourceIp.getAddress().addr(), rule.getDestIpAddress());
            rulesTO.add(ruleTO);
        }
    }
    final SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) DataCenterVO(com.cloud.dc.DataCenterVO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) StaticNatRule(com.cloud.network.rules.StaticNatRule)

Example 17 with StaticNatRule

use of com.cloud.network.rules.StaticNatRule in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@SuppressWarnings("unchecked")
@Override
public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
    final Network network = firewall.getNetwork();
    final VirtualRouter router = 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);
    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.network.lb.LoadBalancingRule) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) Purpose(com.cloud.network.rules.FirewallRule.Purpose) List(java.util.List) ArrayList(java.util.ArrayList) StaticNatRule(com.cloud.network.rules.StaticNatRule) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) VirtualRouter(com.cloud.network.router.VirtualRouter)

Aggregations

StaticNatRule (com.cloud.network.rules.StaticNatRule)17 ArrayList (java.util.ArrayList)10 FirewallRule (com.cloud.network.rules.FirewallRule)8 Network (com.cloud.network.Network)5 ServerApiException (com.cloud.api.ServerApiException)4 IpForwardingRuleResponse (com.cloud.api.response.IpForwardingRuleResponse)4 IpAddress (com.cloud.network.IpAddress)4 PublicIpAddress (com.cloud.network.PublicIpAddress)4 PublicIp (com.cloud.network.addr.PublicIp)4 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)4 PortForwardingRule (com.cloud.network.rules.PortForwardingRule)4 List (java.util.List)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)3 SetStaticNatRulesCommand (com.cloud.agent.api.routing.SetStaticNatRulesCommand)2 StaticNatRuleTO (com.cloud.agent.api.to.StaticNatRuleTO)2 Commands (com.cloud.agent.manager.Commands)2 ListResponse (com.cloud.api.response.ListResponse)2 Zone (com.cloud.db.model.Zone)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2