Search in sources :

Example 1 with ForwardingRule

use of com.cloud.legacymodel.network.rules.ForwardingRule 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 ForwardingRule

use of com.cloud.legacymodel.network.rules.ForwardingRule 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)

Aggregations

ForwardingRule (com.cloud.legacymodel.network.rules.ForwardingRule)2 ForwardingRules (com.cloud.legacymodel.network.rules.ForwardingRules)2 AbstractConfigItemFacade (com.cloud.common.virtualnetwork.facade.AbstractConfigItemFacade)1 SetPortForwardingRulesCommand (com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand)1 SetPortForwardingRulesVpcCommand (com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand)1 PortForwardingRuleTO (com.cloud.legacymodel.to.PortForwardingRuleTO)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1