Search in sources :

Example 11 with SetStaticNatRulesCommand

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

the class CommandSetupHelper method createApplyStaticNatRulesCommands.

public void createApplyStaticNatRulesCommands(final List<? extends StaticNatRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
    if (rules != null) {
        for (final StaticNatRule rule : rules) {
            final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            final StaticNatRuleTO ruleTO = new StaticNatRuleTO(rule, null, sourceIp.getAddress().addr(), rule.getDestIpAddress());
            rulesTO.add(ruleTO);
        }
    }
    final SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
    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 : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) DataCenterVO(com.cloud.dc.DataCenterVO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) StaticNatRule(com.cloud.network.rules.StaticNatRule)

Example 12 with SetStaticNatRulesCommand

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

the class CommandSetupHelper method createApplyStaticNatCommands.

public void createApplyStaticNatCommands(final List<? extends StaticNat> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
    if (rules != null) {
        for (final StaticNat rule : rules) {
            final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            final StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
            rulesTO.add(ruleTO);
        }
    }
    final SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
    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 : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) DataCenterVO(com.cloud.dc.DataCenterVO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) StaticNat(com.cloud.network.rules.StaticNat)

Example 13 with SetStaticNatRulesCommand

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

the class PaloAltoResourceTest method removeStaticNatRule.

@Test
public void removeStaticNatRule() throws ConfigurationException, Exception {
    if (_context.containsKey("enable_console_output") && _context.get("enable_console_output").equals("true")) {
        System.out.println("\nTEST: removeStaticNatRule");
        System.out.println("---------------------------------------------------");
    }
    _context.put("has_public_interface", "true");
    _context.put("has_private_interface", "true");
    _context.put("has_src_nat_rule", "true");
    _context.put("has_isolation_fw_rule", "true");
    _context.put("has_service_tcp_80", "true");
    _context.put("has_stc_nat_rule", "true");
    _resource.setMockContext(_context);
    _resource.configure("PaloAltoResource", _resourceParams);
    long vlanId = 3954;
    List<StaticNatRuleTO> rules = new ArrayList<StaticNatRuleTO>();
    StaticNatRuleTO revoked = new StaticNatRuleTO(0, "192.168.80.103", null, null, "10.3.97.158", null, null, null, true, false);
    rules.add(revoked);
    SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rules, null);
    cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, Long.toString(vlanId));
    cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, "10.3.96.1/20");
    Answer answer = _resource.executeRequest(cmd);
    assertTrue(answer.getResult());
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) Answer(com.cloud.agent.api.Answer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with SetStaticNatRulesCommand

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

the class PaloAltoResourceTest method addStaticNatRule.

@Test
public void addStaticNatRule() throws ConfigurationException, Exception {
    if (_context.containsKey("enable_console_output") && _context.get("enable_console_output").equals("true")) {
        System.out.println("\nTEST: addStaticNatRule");
        System.out.println("---------------------------------------------------");
    }
    _context.put("has_public_interface", "true");
    _context.put("has_private_interface", "true");
    _context.put("has_src_nat_rule", "true");
    _context.put("has_isolation_fw_rule", "true");
    _context.put("has_service_tcp_80", "true");
    _resource.setMockContext(_context);
    _resource.configure("PaloAltoResource", _resourceParams);
    long vlanId = 3954;
    List<StaticNatRuleTO> rules = new ArrayList<StaticNatRuleTO>();
    StaticNatRuleTO active = new StaticNatRuleTO(0, "192.168.80.103", null, null, "10.3.97.158", null, null, null, false, false);
    rules.add(active);
    SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rules, null);
    cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, Long.toString(vlanId));
    cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, "10.3.96.1/20");
    Answer answer = _resource.executeRequest(cmd);
    assertTrue(answer.getResult());
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) Answer(com.cloud.agent.api.Answer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SetStaticNatRulesCommand (com.cloud.agent.api.routing.SetStaticNatRulesCommand)14 StaticNatRuleTO (com.cloud.agent.api.to.StaticNatRuleTO)11 ArrayList (java.util.ArrayList)9 Answer (com.cloud.agent.api.Answer)7 IpAddress (com.cloud.network.IpAddress)6 PublicIpAddress (com.cloud.network.PublicIpAddress)6 StaticNat (com.cloud.network.rules.StaticNat)3 Test (org.junit.Test)3 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)2 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)2 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)2 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)2 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)2 ComputeChecksumCommand (com.cloud.agent.api.ComputeChecksumCommand)2 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)2 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)2 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)2 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)2 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)2 GetDomRVersionCmd (com.cloud.agent.api.GetDomRVersionCmd)2