Search in sources :

Example 1 with SetPortForwardingRulesVpcCommand

use of com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand in project cloudstack by apache.

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<PortForwardingRuleTO>();
    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);
        }
    }
    SetPortForwardingRulesCommand cmd = null;
    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_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) ArrayList(java.util.ArrayList) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) PortForwardingRule(com.cloud.network.rules.PortForwardingRule)

Example 2 with SetPortForwardingRulesVpcCommand

use of com.cloud.agent.api.routing.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.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 SetPortForwardingRulesVpcCommand

use of com.cloud.agent.api.routing.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, ROUTERNAME);
    assertEquals(cmd.getAnswersCount(), 2);
    return cmd;
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) ArrayList(java.util.ArrayList)

Example 4 with SetPortForwardingRulesVpcCommand

use of com.cloud.agent.api.routing.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.findOne(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, zone.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) Zone(com.cloud.db.model.Zone) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) PortForwardingRule(com.cloud.network.rules.PortForwardingRule)

Example 5 with SetPortForwardingRulesVpcCommand

use of com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand 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)

Aggregations

SetPortForwardingRulesVpcCommand (com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand)9 PortForwardingRuleTO (com.cloud.agent.api.to.PortForwardingRuleTO)4 ArrayList (java.util.ArrayList)4 Answer (com.cloud.agent.api.Answer)2 SetPortForwardingRulesCommand (com.cloud.agent.api.routing.SetPortForwardingRulesCommand)2 AbstractConfigItemFacade (com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade)2 ForwardingRule (com.cloud.agent.resource.virtualnetwork.model.ForwardingRule)2 ForwardingRules (com.cloud.agent.resource.virtualnetwork.model.ForwardingRules)2 IpAddress (com.cloud.network.IpAddress)2 PublicIpAddress (com.cloud.network.PublicIpAddress)2 PortForwardingRule (com.cloud.network.rules.PortForwardingRule)2 Test (org.junit.Test)2 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)1 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)1 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)1 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)1 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)1 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)1