Search in sources :

Example 1 with OpenDaylightControllerVO

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

the class OpendaylightGuestNetworkGuru method release.

@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
    boolean success = super.release(nic, vm, reservationId);
    if (success) {
        //get physical network id
        NetworkVO network = _networkDao.findById(nic.getNetworkId());
        Long physicalNetworkId = network.getPhysicalNetworkId();
        List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
        if (devices.isEmpty()) {
            s_logger.error("No Controller on physical network " + physicalNetworkId);
            throw new CloudRuntimeException("No OpenDaylight controller on this physical network");
        }
        OpenDaylightControllerVO controller = devices.get(0);
        DestroyPortCommand cmd = new DestroyPortCommand(UUID.fromString(nic.getUuid()));
        DestroyPortAnswer answer = (DestroyPortAnswer) agentManager.easySend(controller.getHostId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("DestroyPortCommand failed");
            success = false;
        }
    }
    return success;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DestroyPortCommand(org.apache.cloudstack.network.opendaylight.agent.commands.DestroyPortCommand) DestroyPortAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.DestroyPortAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 2 with OpenDaylightControllerVO

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

the class OpendaylightGuestNetworkGuru method reserve.

@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    super.reserve(nic, network, vm, dest, context);
    //get physical network id
    Long physicalNetworkId = network.getPhysicalNetworkId();
    List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No Controller on physical network " + physicalNetworkId);
        throw new InsufficientVirtualNetworkCapacityException("No OpenDaylight Controller configured for this network", dest.getPod().getId());
    }
    OpenDaylightControllerVO controller = devices.get(0);
    AddHypervisorCommand addCmd = new AddHypervisorCommand(dest.getHost().getUuid(), dest.getHost().getPrivateIpAddress());
    AddHypervisorAnswer addAnswer = (AddHypervisorAnswer) agentManager.easySend(controller.getHostId(), addCmd);
    if (addAnswer == null || !addAnswer.getResult()) {
        s_logger.error("Failed to add " + dest.getHost().getName() + " as a node to the controller");
        throw new InsufficientVirtualNetworkCapacityException("Failed to add destination hypervisor to the OpenDaylight Controller", dest.getPod().getId());
    }
    ConfigurePortCommand cmd = new ConfigurePortCommand(UUID.fromString(nic.getUuid()), UUID.fromString(BroadcastDomainType.getValue(network.getBroadcastUri())), context.getAccount().getAccountName(), nic.getMacAddress());
    ConfigurePortAnswer answer = (ConfigurePortAnswer) agentManager.easySend(controller.getHostId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ConfigureNetworkCommand failed");
        throw new InsufficientVirtualNetworkCapacityException("Failed to configure the port on the OpenDaylight Controller", dest.getPod().getId());
    }
}
Also used : AddHypervisorCommand(org.apache.cloudstack.network.opendaylight.agent.commands.AddHypervisorCommand) ConfigurePortCommand(org.apache.cloudstack.network.opendaylight.agent.commands.ConfigurePortCommand) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ConfigurePortAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer) AddHypervisorAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.AddHypervisorAnswer) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 3 with OpenDaylightControllerVO

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

the class OpendaylightGuestNetworkGuru 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;
    long dcId = dest.getDataCenter().getId();
    //get physical network id
    Long physicalNetworkId = network.getPhysicalNetworkId();
    // physical network id can be null in Guest Network in Basic zone, so locate the physical network
    if (physicalNetworkId == null) {
        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, offering.getRedundantRouter());
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = ((NetworkVO) network).getUuid();
    }
    List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No Controller on physical network " + physicalNetworkId);
        return null;
    }
    OpenDaylightControllerVO controller = devices.get(0);
    ConfigureNetworkCommand cmd = new ConfigureNetworkCommand(name, context.getAccount().getAccountName());
    ConfigureNetworkAnswer answer = (ConfigureNetworkAnswer) agentManager.easySend(controller.getHostId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ConfigureNetworkCommand failed");
        return null;
    }
    implemented.setBroadcastUri(BroadcastDomainType.OpenDaylight.toUri(answer.getNetworkUuid()));
    implemented.setBroadcastDomainType(BroadcastDomainType.OpenDaylight);
    s_logger.info("Implemented OK, network linked to  = " + implemented.getBroadcastUri().toString());
    return implemented;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ConfigureNetworkAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer) ConfigureNetworkCommand(org.apache.cloudstack.network.opendaylight.agent.commands.ConfigureNetworkCommand) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 4 with OpenDaylightControllerVO

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

the class OpenDaylightControllerResourceManagerImpl method deleteController.

@Override
public void deleteController(DeleteOpenDaylightControllerCmd cmd) throws InvalidParameterValueException {
    OpenDaylightControllerVO controller = openDaylightControllerMappingDao.findById(cmd.getId());
    if (controller == null) {
        throw new InvalidParameterValueException("No ODL Controller with id " + cmd.getId());
    }
    // Find the physical network we work for
    Long physicalNetworkId = controller.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork != null) {
        // Lets see if there are networks that use us
        List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
        if (networkList != null) {
            // Networks with broadcast type lswitch are ours
            for (NetworkVO network : networkList) {
                if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.OpenDaylight) {
                    if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
                        throw new CloudRuntimeException("This Controller can not be deleted as there are one or more logical networks provisioned by cloudstack.");
                    }
                }
            }
        }
    }
    HostVO host = hostDao.findById(controller.getHostId());
    Long hostId = host.getId();
    host.setResourceState(ResourceState.Maintenance);
    hostDao.update(hostId, host);
    resourceManager.deleteHost(hostId, false, false);
    openDaylightControllerMappingDao.remove(cmd.getId());
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO) HostVO(com.cloud.host.HostVO)

Example 5 with OpenDaylightControllerVO

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

the class OpenDaylightControllerResourceManagerImpl method listControllers.

@Override
public List<OpenDaylightControllerVO> listControllers(ListOpenDaylightControllersCmd cmd) {
    if (cmd.getId() != null) {
        List<OpenDaylightControllerVO> foundControllers = new ArrayList<OpenDaylightControllerVO>();
        OpenDaylightControllerVO controller = openDaylightControllerMappingDao.findById(cmd.getId());
        if (controller != null) {
            foundControllers.add(controller);
        }
        return foundControllers;
    } else if (cmd.getPhysicalNetworkId() != null) {
        return openDaylightControllerMappingDao.listByPhysicalNetwork(cmd.getPhysicalNetworkId());
    }
    return openDaylightControllerMappingDao.listAll();
}
Also used : ArrayList(java.util.ArrayList) 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