Search in sources :

Example 1 with CreateBcfRouterInterfaceCommand

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

the class BigSwitchBcfGuestNetworkGuru method implement.

@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    bcfUtilsInit();
    long dcId = dest.getDataCenter().getId();
    long physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, false);
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    String vnetId = "";
    if (network.getBroadcastUri() == null) {
        vnetId = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), context.getReservationId(), UseSystemGuestVlans.valueIn(network.getAccountId()));
        if (vnetId == null) {
            throw new InsufficientVirtualNetworkCapacityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class, dcId);
        }
        implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnetId));
        ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnetId + " Network Id: " + network.getId(), 0);
    } else {
        implemented.setBroadcastUri(network.getBroadcastUri());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = ((NetworkVO) network).getUuid();
    }
    if (name.length() > 64) {
        // max length 64
        name = name.substring(0, 63);
    }
    // update fields in network object
    NetworkVO networkObject = (NetworkVO) network;
    // determine whether this is VPC network or stand-alone network
    Vpc vpc = null;
    if (network.getVpcId() != null) {
        vpc = _vpcDao.acquireInLockTable(network.getVpcId());
    }
    // use uuid of networkVO as network id in BSN
    String networkId = networkObject.getUuid();
    String tenantId;
    String tenantName;
    if (vpc != null) {
        tenantId = vpc.getUuid();
        tenantName = vpc.getName();
        _vpcDao.releaseFromLockTable(vpc.getId());
    } else {
        // use network in CS as tenant in BSN
        // for non-VPC networks, use network name and id as tenant name and id
        tenantId = networkId;
        tenantName = name;
    }
    // store tenantId in networkObject for NetworkOrchestrator implementNetwork use
    networkObject.setNetworkDomain(tenantId);
    // store tenant Id in implemented object for future actions (e.g., shutdown)
    implemented.setNetworkDomain(tenantId);
    String vlanStr = BroadcastDomainType.getValue(implemented.getBroadcastUri());
    // get public net info - needed to set up source nat gateway
    NetworkVO pubNet = _bcfUtils.getPublicNetwork(physicalNetworkId);
    // locate subnet info
    SearchCriteria<VlanVO> sc = _vlanDao.createSearchCriteria();
    sc.setParameters("network_id", pubNet.getId());
    VlanVO pubVlanVO = _vlanDao.findOneBy(sc);
    String pubVlanStr = pubVlanVO.getVlanTag();
    Integer vlan;
    if (StringUtils.isNumeric(vlanStr)) {
        vlan = Integer.valueOf(vlanStr);
    } else {
        vlan = 0;
    }
    CreateBcfSegmentCommand cmd1 = new CreateBcfSegmentCommand(tenantId, tenantName, networkId, name, vlan);
    _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd1, networkObject);
    if (_bcfUtils.isNatEnabled()) {
        Integer pvlan;
        if (StringUtils.isNumeric(pubVlanStr)) {
            pvlan = Integer.valueOf(pubVlanStr);
        } else {
            pvlan = 0;
        }
        CreateBcfSegmentCommand cmd2 = new CreateBcfSegmentCommand("external", "external", "external", "external", pvlan);
        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd2, networkObject);
        CreateBcfRouterCommand cmd3 = new CreateBcfRouterCommand(tenantId);
        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd3, network);
        CreateBcfRouterInterfaceCommand cmd5 = new CreateBcfRouterInterfaceCommand(tenantId, network.getUuid(), network.getCidr(), network.getGateway(), network.getName());
        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd5, network);
    }
    return implemented;
}
Also used : CreateBcfSegmentCommand(com.cloud.agent.api.CreateBcfSegmentCommand) CreateBcfRouterCommand(com.cloud.agent.api.CreateBcfRouterCommand) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CreateBcfRouterInterfaceCommand(com.cloud.agent.api.CreateBcfRouterInterfaceCommand) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) Vpc(com.cloud.network.vpc.Vpc) VlanVO(com.cloud.dc.VlanVO)

Aggregations

CreateBcfRouterCommand (com.cloud.agent.api.CreateBcfRouterCommand)1 CreateBcfRouterInterfaceCommand (com.cloud.agent.api.CreateBcfRouterInterfaceCommand)1 CreateBcfSegmentCommand (com.cloud.agent.api.CreateBcfSegmentCommand)1 VlanVO (com.cloud.dc.VlanVO)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 Vpc (com.cloud.network.vpc.Vpc)1