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);
}
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);
}
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);
}
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);
}
Aggregations