Search in sources :

Example 1 with BigSwitchBcfDeviceVO

use of com.cloud.network.BigSwitchBcfDeviceVO in project cloudstack by apache.

the class BigSwitchBcfGuestNetworkGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    // Check if the isolation type of the physical network is BCF_SEGMENT, then delegate GuestNetworkGuru to design
    PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    if (physnet == null || physnet.getIsolationMethods() == null || !physnet.getIsolationMethods().contains("BCF_SEGMENT")) {
        s_logger.debug("Refusing to design this network, the physical isolation type is not BCF_SEGMENT");
        return null;
    }
    List<BigSwitchBcfDeviceVO> devices = _bigswitchBcfDao.listByPhysicalNetwork(physnet.getId());
    if (devices.isEmpty()) {
        s_logger.error("No BigSwitch Controller on physical network " + physnet.getName());
        return null;
    }
    for (BigSwitchBcfDeviceVO d : devices) {
        s_logger.debug("BigSwitch Controller " + d.getUuid() + " found on physical network " + physnet.getId());
    }
    s_logger.debug("Physical isolation type is BCF_SEGMENT, asking GuestNetworkGuru to design this network");
    NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, owner);
    if (networkObject == null) {
        return null;
    }
    // Override the broadcast domain type
    networkObject.setBroadcastDomainType(BroadcastDomainType.Vlan);
    return networkObject;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO)

Example 2 with BigSwitchBcfDeviceVO

use of com.cloud.network.BigSwitchBcfDeviceVO in project cloudstack by apache.

the class ListBigSwitchBcfDevicesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final List<BigSwitchBcfDeviceVO> bigswitchDevices = bigswitchBcfElementService.listBigSwitchBcfDevices(this);
        final ListResponse<BigSwitchBcfDeviceResponse> response = new ListResponse<BigSwitchBcfDeviceResponse>();
        final List<BigSwitchBcfDeviceResponse> bigswitchDevicesResponse = new ArrayList<BigSwitchBcfDeviceResponse>();
        if (bigswitchDevices != null && !bigswitchDevices.isEmpty()) {
            for (final BigSwitchBcfDeviceVO bigswitchDeviceVO : bigswitchDevices) {
                final BigSwitchBcfDeviceResponse bigswitchDeviceResponse = bigswitchBcfElementService.createBigSwitchBcfDeviceResponse(bigswitchDeviceVO);
                bigswitchDevicesResponse.add(bigswitchDeviceResponse);
            }
        }
        response.setResponses(bigswitchDevicesResponse);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage(), invalidParamExcp);
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage(), runtimeExcp);
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) BigSwitchBcfDeviceResponse(com.cloud.api.response.BigSwitchBcfDeviceResponse) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO)

Example 3 with BigSwitchBcfDeviceVO

use of com.cloud.network.BigSwitchBcfDeviceVO in project cloudstack by apache.

the class AddBigSwitchBcfDeviceCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final BigSwitchBcfDeviceVO bigswitchBcfDeviceVO = bcfElementService.addBigSwitchBcfDevice(this);
        if (bigswitchBcfDeviceVO == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add BigSwitch BCF Controller device due to internal error.");
        }
        final BigSwitchBcfDeviceResponse response = bcfElementService.createBigSwitchBcfDeviceResponse(bigswitchBcfDeviceVO);
        response.setObjectName("bigswitchbcfdevice");
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage(), invalidParamExcp);
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage(), runtimeExcp);
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BigSwitchBcfDeviceResponse(com.cloud.api.response.BigSwitchBcfDeviceResponse) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO)

Example 4 with BigSwitchBcfDeviceVO

use of com.cloud.network.BigSwitchBcfDeviceVO in project cloudstack by apache.

the class BigSwitchBcfElement method addBigSwitchBcfDevice.

@Override
@DB
public BigSwitchBcfDeviceVO addBigSwitchBcfDevice(AddBigSwitchBcfDeviceCmd cmd) {
    BigSwitchBcfDeviceVO newBcfDevice;
    bcfUtilsInit();
    ServerResource resource = new BigSwitchBcfResource();
    final String deviceName = BcfConstants.BIG_SWITCH_BCF.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final String hostname = cmd.getHost();
    final String username = cmd.getUsername();
    final String password = cmd.getPassword();
    final Boolean nat = cmd.getNat();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    ntwkSvcProvider.setFirewallServiceProvided(true);
    ntwkSvcProvider.setGatewayServiceProvided(true);
    ntwkSvcProvider.setNetworkAclServiceProvided(true);
    ntwkSvcProvider.setSourcenatServiceProvided(true);
    ntwkSvcProvider.setStaticnatServiceProvided(true);
    if (_bigswitchBcfDao.listByPhysicalNetwork(physicalNetworkId).size() > 1) {
        throw new CloudRuntimeException("At most two BCF controllers can be configured");
    }
    DataCenterVO zone = _zoneDao.findById(physicalNetwork.getDataCenterId());
    String zoneName;
    if (zone != null) {
        zoneName = zone.getName();
    } else {
        zoneName = String.valueOf(zoneId);
    }
    Boolean natNow = _bcfUtils.isNatEnabled();
    if (!nat && natNow) {
        throw new CloudRuntimeException("NAT is enabled in existing controller. Enable NAT for new controller or remove existing controller first.");
    } else if (nat && !natNow) {
        throw new CloudRuntimeException("NAT is disabled in existing controller. Disable NAT for new controller or remove existing controller first.");
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", zoneName);
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "BigSwitch Controller - " + cmd.getHost());
    params.put("hostname", cmd.getHost());
    params.put("username", username);
    params.put("password", password);
    params.put("nat", nat.toString());
    // FIXME What to do with multiple isolation types
    params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    try {
        resource.configure(cmd.getHost(), hostdetails);
        // store current topology in bcf resource
        TopologyData topo = _bcfUtils.getTopology(physicalNetwork.getId());
        ((BigSwitchBcfResource) resource).setTopology(topo);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
        if (host != null) {
            newBcfDevice = Transaction.execute(new TransactionCallback<BigSwitchBcfDeviceVO>() {

                @Override
                public BigSwitchBcfDeviceVO doInTransaction(TransactionStatus status) {
                    BigSwitchBcfDeviceVO bigswitchBcfDevice = new BigSwitchBcfDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName, hostname, username, password, nat, BigSwitchBcfApi.HASH_IGNORE);
                    _bigswitchBcfDao.persist(bigswitchBcfDevice);
                    DetailVO detail = new DetailVO(host.getId(), "bigswitchbcfdeviceid", String.valueOf(bigswitchBcfDevice.getId()));
                    _hostDetailsDao.persist(detail);
                    return bigswitchBcfDevice;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add BigSwitch BCF Controller Device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    // initial topology sync to newly added BCF controller
    HostVO bigswitchBcfHost = _hostDao.findById(newBcfDevice.getHostId());
    _bcfUtils.syncTopologyToBcfHost(bigswitchBcfHost, nat);
    return newBcfDevice;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) HostVO(com.cloud.host.HostVO) TransactionCallback(com.cloud.utils.db.TransactionCallback) BigSwitchBcfResource(com.cloud.network.resource.BigSwitchBcfResource) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) TopologyData(com.cloud.network.bigswitch.TopologyData) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO) DB(com.cloud.utils.db.DB)

Example 5 with BigSwitchBcfDeviceVO

use of com.cloud.network.BigSwitchBcfDeviceVO in project cloudstack by apache.

the class BigSwitchBcfElement method deleteBigSwitchBcfDevice.

@Override
public boolean deleteBigSwitchBcfDevice(DeleteBigSwitchBcfDeviceCmd cmd) {
    Long bigswitchBcfDeviceId = cmd.getBigSwitchBcfDeviceId();
    BigSwitchBcfDeviceVO bigswitchBcfDevice = _bigswitchBcfDao.findById(bigswitchBcfDeviceId);
    if (bigswitchBcfDevice == null) {
        throw new InvalidParameterValueException("Could not find a BigSwitch Controller with id " + bigswitchBcfDevice);
    }
    HostVO bigswitchHost = _hostDao.findById(bigswitchBcfDevice.getHostId());
    Long hostId = bigswitchHost.getId();
    bigswitchHost.setResourceState(ResourceState.Maintenance);
    _hostDao.update(hostId, bigswitchHost);
    _resourceMgr.deleteHost(hostId, false, false);
    _bigswitchBcfDao.remove(bigswitchBcfDeviceId);
    return true;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO) HostVO(com.cloud.host.HostVO)

Aggregations

BigSwitchBcfDeviceVO (com.cloud.network.BigSwitchBcfDeviceVO)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 HostVO (com.cloud.host.HostVO)3 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 BigSwitchBcfDeviceResponse (com.cloud.api.response.BigSwitchBcfDeviceResponse)2 ArrayList (java.util.ArrayList)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 GetControllerDataAnswer (com.cloud.agent.api.GetControllerDataAnswer)1 GetControllerDataCommand (com.cloud.agent.api.GetControllerDataCommand)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 DetailVO (com.cloud.host.DetailVO)1 Host (com.cloud.host.Host)1 TopologyData (com.cloud.network.bigswitch.TopologyData)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)1 BigSwitchBcfResource (com.cloud.network.resource.BigSwitchBcfResource)1 ServerResource (com.cloud.resource.ServerResource)1 DB (com.cloud.utils.db.DB)1 TransactionCallback (com.cloud.utils.db.TransactionCallback)1