Search in sources :

Example 1 with ForwardingRules

use of com.cloud.agent.resource.virtualnetwork.model.ForwardingRules in project cloudstack by apache.

the class SetPortForwardingRulesConfigItem method generateConfig.

@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
    final SetPortForwardingRulesCommand command = (SetPortForwardingRulesCommand) cmd;
    final List<ForwardingRule> rules = new ArrayList<ForwardingRule>();
    for (final PortForwardingRuleTO rule : command.getRules()) {
        final ForwardingRule fwdRule = new ForwardingRule(rule.revoked(), rule.getProtocol().toLowerCase(), rule.getSrcIp(), rule.getStringSrcPortRange(), 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.agent.resource.virtualnetwork.model.ForwardingRule) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) ArrayList(java.util.ArrayList) ForwardingRules(com.cloud.agent.resource.virtualnetwork.model.ForwardingRules)

Example 2 with ForwardingRules

use of com.cloud.agent.resource.virtualnetwork.model.ForwardingRules 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.agent.resource.virtualnetwork.model.ForwardingRule) AbstractConfigItemFacade(com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) ForwardingRules(com.cloud.agent.resource.virtualnetwork.model.ForwardingRules) Test(org.junit.Test)

Example 3 with ForwardingRules

use of com.cloud.agent.resource.virtualnetwork.model.ForwardingRules in project cloudstack by apache.

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.agent.resource.virtualnetwork.model.ForwardingRule) AbstractConfigItemFacade(com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) ForwardingRules(com.cloud.agent.resource.virtualnetwork.model.ForwardingRules) Test(org.junit.Test)

Example 4 with ForwardingRules

use of com.cloud.agent.resource.virtualnetwork.model.ForwardingRules 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(), rule.getStringSrcPortRange(), 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.agent.resource.virtualnetwork.model.ForwardingRule) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) ArrayList(java.util.ArrayList) ForwardingRules(com.cloud.agent.resource.virtualnetwork.model.ForwardingRules)

Aggregations

ForwardingRule (com.cloud.agent.resource.virtualnetwork.model.ForwardingRule)4 ForwardingRules (com.cloud.agent.resource.virtualnetwork.model.ForwardingRules)4 SetPortForwardingRulesCommand (com.cloud.agent.api.routing.SetPortForwardingRulesCommand)2 SetPortForwardingRulesVpcCommand (com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand)2 PortForwardingRuleTO (com.cloud.agent.api.to.PortForwardingRuleTO)2 AbstractConfigItemFacade (com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2