Search in sources :

Example 6 with OpenDaylightControllerVO

use of org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO in project cloudstack by apache.

the class OpendaylightGuestNetworkGuru method shutdown.

@Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
    NetworkVO networkObject = networkDao.findById(profile.getId());
    if (networkObject.getBroadcastDomainType() != BroadcastDomainType.OpenDaylight || networkObject.getBroadcastUri() == null) {
        s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText());
        return;
    }
    List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Controller on physical network " + networkObject.getPhysicalNetworkId());
        return;
    }
    OpenDaylightControllerVO controller = devices.get(0);
    DestroyNetworkCommand cmd = new DestroyNetworkCommand(BroadcastDomainType.getValue(networkObject.getBroadcastUri()));
    DestroyNetworkAnswer answer = (DestroyNetworkAnswer) agentManager.easySend(controller.getHostId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("DestroyNetworkCommand failed");
    }
    super.shutdown(profile, offering);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DestroyNetworkAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.DestroyNetworkAnswer) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO) DestroyNetworkCommand(org.apache.cloudstack.network.opendaylight.agent.commands.DestroyNetworkCommand)

Example 7 with OpenDaylightControllerVO

use of org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO in project cloudstack by apache.

the class OpendaylightGuestNetworkGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        s_logger.debug("Refusing to design this network");
        return null;
    }
    List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physnet.getId());
    if (devices.isEmpty()) {
        s_logger.error("No Controller on physical network " + physnet.getName());
        return null;
    }
    s_logger.debug("Controller " + devices.get(0).getUuid() + " found on physical network " + physnet.getId());
    s_logger.debug("Physical isolation type is ODL, 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.OpenDaylight);
    return networkObject;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 8 with OpenDaylightControllerVO

use of org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO in project cloudstack by apache.

the class ListOpenDaylightControllersCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    List<OpenDaylightControllerVO> controllers = resourceManager.listControllers(this);
    List<OpenDaylightControllerResponse> controllerList = new ArrayList<OpenDaylightControllerResponse>();
    for (OpenDaylightControllerVO controller : controllers) {
        OpenDaylightControllerResponse responseObject = resourceManager.createResponseFromVO(controller);
        controllerList.add(responseObject);
    }
    ListResponse<OpenDaylightControllerResponse> responseList = new ListResponse<OpenDaylightControllerResponse>();
    responseList.setResponseName(getCommandName());
    responseList.setResponses(controllerList);
    setResponseObject(responseList);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) OpenDaylightControllerResponse(org.apache.cloudstack.network.opendaylight.api.responses.OpenDaylightControllerResponse) ArrayList(java.util.ArrayList) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 9 with OpenDaylightControllerVO

use of org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO in project cloudstack by apache.

the class OpenDaylightControllerResourceManagerImpl method addController.

@Override
public OpenDaylightControllerVO addController(AddOpenDaylightControllerCmd cmd) {
    ServerResource odlController = new OpenDaylightControllerResource();
    final String deviceName = NetworkDevice.OpenDaylightController.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    if (networkDevice == null) {
        throw new CloudRuntimeException("No network device found for name " + deviceName);
    }
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    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");
    }
    final Map<String, String> hostParams = new HashMap<String, String>();
    hostParams.put("guid", UUID.randomUUID().toString());
    hostParams.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    hostParams.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    hostParams.put("name", "ODL Controller - " + hostParams.get("guid"));
    hostParams.put("url", cmd.getUrl());
    hostParams.put("username", cmd.getUsername());
    hostParams.put("password", cmd.getPassword());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(hostParams);
    try {
        odlController.configure(hostParams.get("name"), hostdetails);
        final Host host = resourceManager.addHost(zoneId, odlController, Host.Type.L2Networking, hostParams);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<OpenDaylightControllerVO>() {

                @Override
                public OpenDaylightControllerVO doInTransaction(TransactionStatus status) {
                    OpenDaylightControllerVO controller = new OpenDaylightControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), hostParams.get("name"));
                    openDaylightControllerMappingDao.persist(controller);
                    return controller;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to create host object for ODL Controller");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Failed to add ODL Controller as a resource", e);
    }
}
Also used : 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) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Aggregations

OpenDaylightControllerVO (org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)6 NetworkVO (com.cloud.network.dao.NetworkVO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 ArrayList (java.util.ArrayList)2 DataCenter (com.cloud.dc.DataCenter)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 Host (com.cloud.host.Host)1 HostVO (com.cloud.host.HostVO)1 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)1 ServerResource (com.cloud.resource.ServerResource)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 HashMap (java.util.HashMap)1 ConfigurationException (javax.naming.ConfigurationException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 NetworkDevice (org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice)1 AddHypervisorCommand (org.apache.cloudstack.network.opendaylight.agent.commands.AddHypervisorCommand)1 ConfigureNetworkCommand (org.apache.cloudstack.network.opendaylight.agent.commands.ConfigureNetworkCommand)1 ConfigurePortCommand (org.apache.cloudstack.network.opendaylight.agent.commands.ConfigurePortCommand)1