Search in sources :

Example 1 with SetPortForwardingRulesCommand

use of com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand in project cosmic by MissionCriticalCloud.

the class SetPortForwardingRulesConfigItem method generateConfig.

@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
    final SetPortForwardingRulesCommand command = (SetPortForwardingRulesCommand) cmd;
    final List<ForwardingRule> rules = new ArrayList<>();
    for (final PortForwardingRuleTO rule : command.getRules()) {
        final ForwardingRule fwdRule = new ForwardingRule(rule.revoked(), rule.getProtocol().toLowerCase(), rule.getSrcIp(), getStringSrcPortRange(rule), rule.getDstIp(), rule.getStringDstPortRange());
        rules.add(fwdRule);
    }
    final ForwardingRules ruleSet = new ForwardingRules(rules.toArray(new ForwardingRule[rules.size()]));
    return generateConfigItems(ruleSet);
}
Also used : ForwardingRule(com.cloud.legacymodel.network.rules.ForwardingRule) SetPortForwardingRulesCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand) PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) ArrayList(java.util.ArrayList) ForwardingRules(com.cloud.legacymodel.network.rules.ForwardingRules)

Example 2 with SetPortForwardingRulesCommand

use of com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand in project cosmic by MissionCriticalCloud.

the class CommandSetupHelper method createApplyPortForwardingRulesCommands.

public void createApplyPortForwardingRulesCommands(final List<? extends PortForwardingRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final List<PortForwardingRuleTO> rulesTO = new ArrayList<>();
    if (rules != null) {
        for (final PortForwardingRule rule : rules) {
            final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            final PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, null, sourceIp.getAddress().addr());
            rulesTO.add(ruleTO);
        }
    }
    final SetPortForwardingRulesCommand cmd;
    if (router.getVpcId() != null) {
        cmd = new SetPortForwardingRulesVpcCommand(rulesTO);
    } else {
        cmd = new SetPortForwardingRulesCommand(rulesTO);
    }
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final Zone zone = zoneRepository.findById(router.getDataCenterId()).orElse(null);
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, zone.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand) Zone(com.cloud.db.model.Zone) SetPortForwardingRulesVpcCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) PortForwardingRule(com.cloud.legacymodel.network.PortForwardingRule)

Aggregations

SetPortForwardingRulesCommand (com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand)2 PortForwardingRuleTO (com.cloud.legacymodel.to.PortForwardingRuleTO)2 ArrayList (java.util.ArrayList)2 Zone (com.cloud.db.model.Zone)1 SetPortForwardingRulesVpcCommand (com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand)1 PortForwardingRule (com.cloud.legacymodel.network.PortForwardingRule)1 ForwardingRule (com.cloud.legacymodel.network.rules.ForwardingRule)1 ForwardingRules (com.cloud.legacymodel.network.rules.ForwardingRules)1 IpAddress (com.cloud.network.IpAddress)1 PublicIpAddress (com.cloud.network.PublicIpAddress)1