Search in sources :

Example 1 with DeleteBcfStaticNatCommand

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

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

the class BigSwitchBcfResourceTest method testDeleteStaticNatRetryOnce.

@Test
public void testDeleteStaticNatRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    when(_bigswitchBcfApi.deleteFloatingIp((String) any(), (String) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand("tenantid", "10.4.4.100");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertTrue(ans.getResult());
}
Also used : DeleteBcfStaticNatCommand(com.cloud.agent.api.DeleteBcfStaticNatCommand) BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) Test(org.junit.Test)

Example 3 with DeleteBcfStaticNatCommand

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

the class BigSwitchBcfResourceTest method testDeleteStaticNatApiException.

@Test
public void testDeleteStaticNatApiException() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).deleteFloatingIp((String) any(), (String) any());
    DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand("tenantid", "10.4.4.100");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertFalse(ans.getResult());
    verify(_bigswitchBcfApi, times(3)).deleteFloatingIp((String) any(), (String) any());
}
Also used : DeleteBcfStaticNatCommand(com.cloud.agent.api.DeleteBcfStaticNatCommand) BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) Test(org.junit.Test)

Aggregations

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