Search in sources :

Example 1 with CreateBcfStaticNatCommand

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

the class BigSwitchBcfElement method applyStaticNats.

@Override
public boolean applyStaticNats(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException {
    bcfUtilsInit();
    _bcfUtils.listACLbyNetwork(network);
    Vpc vpc = null;
    if (network.getVpcId() != null) {
        vpc = _vpcDao.acquireInLockTable(network.getVpcId());
    }
    String tenantId;
    if (vpc != null) {
        tenantId = vpc.getUuid();
        _vpcDao.releaseFromLockTable(vpc.getId());
    } else {
        // use account in CS as tenant in BSN
        // use network uuid as tenantId for non-VPC networks
        tenantId = network.getUuid();
    }
    for (StaticNat rule : rules) {
        String srcIp = _ipAddressDao.findById(rule.getSourceIpAddressId()).getAddress().addr();
        String dstIp = rule.getDestIpAddress();
        String mac = rule.getSourceMacAddress();
        if (!rule.isForRevoke()) {
            s_logger.debug("BCF enables static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac);
            CreateBcfStaticNatCommand cmd = new CreateBcfStaticNatCommand(tenantId, network.getUuid(), dstIp, srcIp, mac);
            _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
        } else {
            s_logger.debug("BCF removes static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac);
            DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand(tenantId, srcIp);
            _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
        }
    }
    return true;
}
Also used : DeleteBcfStaticNatCommand(com.cloud.agent.api.DeleteBcfStaticNatCommand) CreateBcfStaticNatCommand(com.cloud.agent.api.CreateBcfStaticNatCommand) Vpc(com.cloud.network.vpc.Vpc) StaticNat(com.cloud.network.rules.StaticNat)

Example 2 with CreateBcfStaticNatCommand

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

the class BigSwitchBcfResourceTest method testCreateStaticNatRetryOnce.

@Test
public void testCreateStaticNatRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    when(_bigswitchBcfApi.createFloatingIp((String) any(), (FloatingIpData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    CreateBcfStaticNatCommand cmd = new CreateBcfStaticNatCommand("tenantid", "networkid", "192.168.0.10", "10.4.4.100", "90:b1:1c:49:d8:56");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertTrue(ans.getResult());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) FloatingIpData(com.cloud.network.bigswitch.FloatingIpData) CreateBcfStaticNatCommand(com.cloud.agent.api.CreateBcfStaticNatCommand) Test(org.junit.Test)

Example 3 with CreateBcfStaticNatCommand

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

the class BigSwitchBcfResourceTest method testCreateStaticNatApiException.

@Test
public void testCreateStaticNatApiException() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).createFloatingIp((String) any(), (FloatingIpData) any());
    CreateBcfStaticNatCommand cmd = new CreateBcfStaticNatCommand("tenantid", "networkid", "192.168.0.10", "10.4.4.100", "90:b1:1c:49:d8:56");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertFalse(ans.getResult());
    verify(_bigswitchBcfApi, times(3)).createFloatingIp((String) any(), (FloatingIpData) any());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) CreateBcfStaticNatCommand(com.cloud.agent.api.CreateBcfStaticNatCommand) Test(org.junit.Test)

Aggregations

CreateBcfStaticNatCommand (com.cloud.agent.api.CreateBcfStaticNatCommand)3 BcfAnswer (com.cloud.agent.api.BcfAnswer)2 BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)2 Test (org.junit.Test)2 DeleteBcfStaticNatCommand (com.cloud.agent.api.DeleteBcfStaticNatCommand)1 FloatingIpData (com.cloud.network.bigswitch.FloatingIpData)1 StaticNat (com.cloud.network.rules.StaticNat)1 Vpc (com.cloud.network.vpc.Vpc)1