Search in sources :

Example 1 with FloatingIpData

use of com.cloud.network.bigswitch.FloatingIpData in project cloudstack by apache.

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(CreateBcfStaticNatCommand cmd, int numRetries) {
    FloatingIpData fip = new FloatingIpData();
    fip.setTenantId(cmd.getTenantId());
    fip.setNetworkId(cmd.getNetworkId());
    fip.setFixedIp(cmd.getPrivateIp());
    fip.setFloatingIpAndId(cmd.getPublicIp());
    fip.setMac(cmd.getMac());
    try {
        String hash = _bigswitchBcfApi.createFloatingIp(cmd.getTenantId(), fip);
        return new BcfAnswer(cmd, true, "floating ip " + cmd.getPublicIp() + ":" + cmd.getPrivateIp() + " created", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "floating ip " + cmd.getPublicIp() + ":" + cmd.getPrivateIp() + " created; topology sync required.");
        } else {
            if (numRetries > 0) {
                return retry(cmd, --numRetries);
            } else {
                return new BcfAnswer(cmd, e);
            }
        }
    }
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) FloatingIpData(com.cloud.network.bigswitch.FloatingIpData)

Example 2 with FloatingIpData

use of com.cloud.network.bigswitch.FloatingIpData 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)

Aggregations

BcfAnswer (com.cloud.agent.api.BcfAnswer)2 BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)2 FloatingIpData (com.cloud.network.bigswitch.FloatingIpData)2 CreateBcfStaticNatCommand (com.cloud.agent.api.CreateBcfStaticNatCommand)1 Test (org.junit.Test)1