Search in sources :

Example 16 with StaticNat

use of com.cloud.network.rules.StaticNat 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 17 with StaticNat

use of com.cloud.network.rules.StaticNat in project cloudstack by apache.

the class IpAddressManagerTest method testGetStaticNatSourceIps.

@Test
public void testGetStaticNatSourceIps() {
    String publicIpAddress = "192.168.1.3";
    IPAddressVO vo = mock(IPAddressVO.class);
    lenient().when(vo.getAddress()).thenReturn(new Ip(publicIpAddress));
    lenient().when(vo.getId()).thenReturn(1l);
    when(ipAddressDao.findById(anyLong())).thenReturn(vo);
    StaticNat snat = new StaticNatImpl(1, 1, 1, 1, publicIpAddress, false);
    List<IPAddressVO> ips = ipAddressManager.getStaticNatSourceIps(Collections.singletonList(snat));
    Assert.assertNotNull(ips);
    Assert.assertEquals(1, ips.size());
    IPAddressVO returnedVO = ips.get(0);
    Assert.assertEquals(vo, returnedVO);
}
Also used : StaticNatImpl(com.cloud.network.rules.StaticNatImpl) Ip(com.cloud.utils.net.Ip) IPAddressVO(com.cloud.network.dao.IPAddressVO) StaticNat(com.cloud.network.rules.StaticNat) Test(org.junit.Test)

Aggregations

StaticNat (com.cloud.network.rules.StaticNat)17 ArrayList (java.util.ArrayList)14 PublicIpAddress (com.cloud.network.PublicIpAddress)9 IpAddress (com.cloud.network.IpAddress)8 StaticNatRuleTO (com.cloud.agent.api.to.StaticNatRuleTO)7 HostVO (com.cloud.host.HostVO)6 SetStaticNatRulesCommand (com.cloud.agent.api.routing.SetStaticNatRulesCommand)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 PublicIp (com.cloud.network.addr.PublicIp)5 IPAddressVO (com.cloud.network.dao.IPAddressVO)4 StaticNatImpl (com.cloud.network.rules.StaticNatImpl)4 Ip (com.cloud.utils.net.Ip)4 Answer (com.cloud.agent.api.Answer)3 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)3 ConfigureStaticNatRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer)2 ConfigureStaticNatRulesOnLogicalRouterCommand (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 VlanVO (com.cloud.dc.VlanVO)2 Network (com.cloud.network.Network)2 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)2