Search in sources :

Example 1 with BigSwitchBcfApiException

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

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(UpdateBcfRouterCommand cmd, int numRetries) {
    RouterData routerData = new RouterData(cmd.getTenantId());
    List<AclData> acls = new ArrayList<AclData>();
    acls.addAll(cmd.getAcls());
    routerData.getRouter().getAcls().addAll(acls);
    routerData.getRouter().addExternalGateway(cmd.getPublicIp());
    try {
        String hash = _bigswitchBcfApi.modifyRouter(cmd.getTenantId(), routerData);
        return new BcfAnswer(cmd, true, "tenant " + cmd.getTenantId() + " router updated", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "tenant " + cmd.getTenantId() + " router updated but topology sync required.");
        } else {
            if (numRetries > 0) {
                return retry(cmd, --numRetries);
            } else {
                return new BcfAnswer(cmd, e);
            }
        }
    } catch (IllegalArgumentException e1) {
        return new BcfAnswer(cmd, false, "Illegal argument in BCF router update");
    }
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) AclData(com.cloud.network.bigswitch.AclData) ArrayList(java.util.ArrayList) RouterData(com.cloud.network.bigswitch.RouterData)

Example 2 with BigSwitchBcfApiException

use of com.cloud.network.bigswitch.BigSwitchBcfApiException 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 3 with BigSwitchBcfApiException

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

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(UpdateBcfAttachmentCommand cmd, int numRetries) {
    AttachmentData attachment = new AttachmentData();
    attachment.getAttachment().setId(cmd.getAttachmentId());
    attachment.getAttachment().setTenantName(cmd.getTenantId());
    try {
        String hash = _bigswitchBcfApi.modifyAttachment(cmd.getTenantId(), cmd.getNetworkId(), attachment);
        return new BcfAnswer(cmd, true, "Network attachment  " + cmd.getAttachmentId() + " updated", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "Network attachment  " + cmd.getAttachmentId() + " updated; 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) AttachmentData(com.cloud.network.bigswitch.AttachmentData)

Example 4 with BigSwitchBcfApiException

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

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(CreateBcfSegmentCommand cmd, int numRetries) {
    NetworkData network = new NetworkData();
    network.getNetwork().setTenantId(cmd.getTenantId());
    network.getNetwork().setTenantName(cmd.getTenantName());
    network.getNetwork().setId(cmd.getNetworkId());
    network.getNetwork().setName(truncate("segment-cloudstack-" + cmd.getNetworkName(), 64));
    network.getNetwork().setVlan(cmd.getVlan());
    try {
        String hash = _bigswitchBcfApi.createNetwork(network);
        return new BcfAnswer(cmd, true, "Segment " + network.getNetwork().getId() + " created", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "Segment " + network.getNetwork().getId() + " 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) NetworkData(com.cloud.network.bigswitch.NetworkData)

Example 5 with BigSwitchBcfApiException

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

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(CreateBcfAttachmentCommand cmd, int numRetries) {
    AttachmentData attachment = new AttachmentData();
    attachment.getAttachment().setId(cmd.getNicId());
    attachment.getAttachment().setHostId(cmd.getPortId());
    attachment.getAttachment().setTenantName(cmd.getTenantName());
    attachment.getAttachment().setVlan(cmd.getVlan());
    attachment.getAttachment().addIpv4(cmd.getIpv4());
    attachment.getAttachment().setMac(cmd.getMac());
    try {
        String hash = _bigswitchBcfApi.createAttachment(cmd.getTenantId(), cmd.getNetworkId(), attachment);
        return new BcfAnswer(cmd, true, "network attachment " + cmd.getPortId() + " created", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "network attachment " + cmd.getPortId() + " 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) AttachmentData(com.cloud.network.bigswitch.AttachmentData)

Aggregations

BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)30 BcfAnswer (com.cloud.agent.api.BcfAnswer)29 Test (org.junit.Test)22 AttachmentData (com.cloud.network.bigswitch.AttachmentData)5 RouterData (com.cloud.network.bigswitch.RouterData)5 UpdateBcfRouterCommand (com.cloud.agent.api.UpdateBcfRouterCommand)4 NetworkData (com.cloud.network.bigswitch.NetworkData)3 CreateBcfAttachmentCommand (com.cloud.agent.api.CreateBcfAttachmentCommand)2 CreateBcfRouterCommand (com.cloud.agent.api.CreateBcfRouterCommand)2 CreateBcfSegmentCommand (com.cloud.agent.api.CreateBcfSegmentCommand)2 CreateBcfStaticNatCommand (com.cloud.agent.api.CreateBcfStaticNatCommand)2 DeleteBcfAttachmentCommand (com.cloud.agent.api.DeleteBcfAttachmentCommand)2 DeleteBcfSegmentCommand (com.cloud.agent.api.DeleteBcfSegmentCommand)2 DeleteBcfStaticNatCommand (com.cloud.agent.api.DeleteBcfStaticNatCommand)2 UpdateBcfAttachmentCommand (com.cloud.agent.api.UpdateBcfAttachmentCommand)2 FloatingIpData (com.cloud.network.bigswitch.FloatingIpData)2 TopologyData (com.cloud.network.bigswitch.TopologyData)2 PingCommand (com.cloud.agent.api.PingCommand)1 SyncBcfTopologyCommand (com.cloud.agent.api.SyncBcfTopologyCommand)1 AclData (com.cloud.network.bigswitch.AclData)1