Search in sources :

Example 1 with SetPortForwardingRulesVpcCommand

use of com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand 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)

Example 2 with SetPortForwardingRulesVpcCommand

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

the class ConfigHelperTest method testSetPortForwardingRulesVpc.

@Test
public void testSetPortForwardingRulesVpc() {
    final SetPortForwardingRulesVpcCommand command = generateSetPortForwardingRulesVpcCommand();
    final AbstractConfigItemFacade configItemFacade = AbstractConfigItemFacade.getInstance(command.getClass());
    final List<ConfigItem> config = configItemFacade.generateConfig(command);
    assertTrue(config.size() > 0);
    final ConfigItem fileConfig = config.get(0);
    assertNotNull(fileConfig);
    assertTrue(fileConfig instanceof FileConfigItem);
    final String fileContents = ((FileConfigItem) fileConfig).getFileContents();
    assertNotNull(fileContents);
    final ForwardingRules jsonClass = gson.fromJson(fileContents, ForwardingRules.class);
    assertNotNull(jsonClass);
    assertEquals(jsonClass.getType(), "forwardrules");
    final ForwardingRule[] rules = jsonClass.getRules();
    assertNotNull(rules);
    assertTrue(rules.length == 2);
    assertEquals(rules[0].getSourceIpAddress(), "64.1.1.10");
    final ConfigItem scriptConfig = config.get(1);
    assertNotNull(scriptConfig);
    assertTrue(scriptConfig instanceof ScriptConfigItem);
}
Also used : ForwardingRule(com.cloud.legacymodel.network.rules.ForwardingRule) AbstractConfigItemFacade(com.cloud.common.virtualnetwork.facade.AbstractConfigItemFacade) SetPortForwardingRulesVpcCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand) ForwardingRules(com.cloud.legacymodel.network.rules.ForwardingRules) Test(org.junit.Test)

Example 3 with SetPortForwardingRulesVpcCommand

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

the class ConfigHelperTest method generateSetPortForwardingRulesVpcCommand.

protected SetPortForwardingRulesVpcCommand generateSetPortForwardingRulesVpcCommand() {
    final List<PortForwardingRuleTO> pfRules = new ArrayList<>();
    pfRules.add(new PortForwardingRuleTO(1, "64.1.1.10", 22, 80, "10.10.1.10", 22, 80, "TCP", false, false));
    pfRules.add(new PortForwardingRuleTO(2, "64.1.1.11", 8080, 8080, "10.10.1.11", 8080, 8080, "UDP", true, false));
    final SetPortForwardingRulesVpcCommand cmd = new SetPortForwardingRulesVpcCommand(pfRules);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, this.ROUTERNAME);
    assertEquals(cmd.getAnswersCount(), 2);
    return cmd;
}
Also used : PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) SetPortForwardingRulesVpcCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand) ArrayList(java.util.ArrayList)

Aggregations

SetPortForwardingRulesVpcCommand (com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand)3 PortForwardingRuleTO (com.cloud.legacymodel.to.PortForwardingRuleTO)2 ArrayList (java.util.ArrayList)2 AbstractConfigItemFacade (com.cloud.common.virtualnetwork.facade.AbstractConfigItemFacade)1 Zone (com.cloud.db.model.Zone)1 SetPortForwardingRulesCommand (com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand)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 Test (org.junit.Test)1