Search in sources :

Example 1 with BcfAnswer

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

the class BigSwitchBcfUtils method syncTopologyToBcfHost.

public String syncTopologyToBcfHost(HostVO bigswitchBcfHost) {
    SyncBcfTopologyCommand syncCmd;
    if (isNatEnabled()) {
        syncCmd = new SyncBcfTopologyCommand(true, true);
    } else {
        syncCmd = new SyncBcfTopologyCommand(true, false);
    }
    BcfAnswer syncAnswer = (BcfAnswer) _agentMgr.easySend(bigswitchBcfHost.getId(), syncCmd);
    if (syncAnswer == null || !syncAnswer.getResult()) {
        s_logger.error("SyncBcfTopologyCommand failed");
        return null;
    }
    return syncAnswer.getHash();
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) SyncBcfTopologyCommand(com.cloud.agent.api.SyncBcfTopologyCommand)

Example 2 with BcfAnswer

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

the class BigSwitchBcfUtils method syncTopologyToBcfHost.

public String syncTopologyToBcfHost(HostVO bigswitchBcfHost, boolean natEnabled) {
    SyncBcfTopologyCommand syncCmd;
    if (natEnabled) {
        syncCmd = new SyncBcfTopologyCommand(true, true);
    } else {
        syncCmd = new SyncBcfTopologyCommand(true, false);
    }
    BcfAnswer syncAnswer = (BcfAnswer) _agentMgr.easySend(bigswitchBcfHost.getId(), syncCmd);
    if (syncAnswer == null || !syncAnswer.getResult()) {
        s_logger.error("SyncBcfTopologyCommand failed");
        return null;
    }
    return syncAnswer.getHash();
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) SyncBcfTopologyCommand(com.cloud.agent.api.SyncBcfTopologyCommand)

Example 3 with BcfAnswer

use of com.cloud.agent.api.BcfAnswer 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 4 with BcfAnswer

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

the class BigSwitchBcfElement method updateBcfRouter.

private void updateBcfRouter(Network network) throws IllegalArgumentException {
    bcfUtilsInit();
    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 {
        tenantId = network.getUuid();
    }
    UpdateBcfRouterCommand cmd = new UpdateBcfRouterCommand(tenantId);
    List<AclData> aclList = _bcfUtils.listACLbyNetwork(network);
    for (AclData acl : aclList) {
        cmd.addAcl(acl);
    }
    if (vpc != null) {
        cmd.setPublicIp(_bcfUtils.getPublicIpByVpc(vpc));
    } else {
        cmd.setPublicIp(_bcfUtils.getPublicIpByNetwork(network));
    }
    BcfAnswer answer = _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
    if (answer != null && !answer.getResult()) {
        throw new IllegalArgumentException("Illegal router update arguments");
    }
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) AclData(com.cloud.network.bigswitch.AclData) Vpc(com.cloud.network.vpc.Vpc) UpdateBcfRouterCommand(com.cloud.agent.api.UpdateBcfRouterCommand)

Example 5 with BcfAnswer

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

Aggregations

BcfAnswer (com.cloud.agent.api.BcfAnswer)33 BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)29 Test (org.junit.Test)21 UpdateBcfRouterCommand (com.cloud.agent.api.UpdateBcfRouterCommand)5 AttachmentData (com.cloud.network.bigswitch.AttachmentData)5 RouterData (com.cloud.network.bigswitch.RouterData)5 SyncBcfTopologyCommand (com.cloud.agent.api.SyncBcfTopologyCommand)3 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 AclData (com.cloud.network.bigswitch.AclData)2 FloatingIpData (com.cloud.network.bigswitch.FloatingIpData)2 TopologyData (com.cloud.network.bigswitch.TopologyData)2 CacheBcfTopologyCommand (com.cloud.agent.api.CacheBcfTopologyCommand)1