Search in sources :

Example 1 with ConfigurePortAnswer

use of org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer 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 2 with ConfigurePortAnswer

use of org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer in project cloudstack by apache.

the class OpenDaylightControllerResource method executeRequest.

private Answer executeRequest(ConfigurePortCommand cmd) {
    NeutronPortsNorthboundAction configurePort = new NeutronPortsNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
    NeutronPort newPort = new NeutronPort();
    // Configuration from the command
    newPort.setId(cmd.getPortId());
    newPort.setTenantId(cmd.getTennantId());
    newPort.setAdminStateUp(true);
    newPort.setName(cmd.getPortId().toString());
    newPort.setNetworkId(cmd.getNetworkId());
    newPort.setMacAddress(cmd.getMacAddress());
    newPort.setDeviceId(UUID.randomUUID());
    // Static valus
    newPort.setStatus("ACTIVE");
    newPort.setFixedIps(Collections.<String>emptyList());
    NeutronPortWrapper portWrapper = new NeutronPortWrapper();
    portWrapper.setPort(newPort);
    try {
        portWrapper = configurePort.createNeutronPort(portWrapper);
    } catch (NeutronRestApiException e) {
        s_logger.error("createPortCommand failed", e);
        return new ConfigurePortAnswer(cmd, e);
    }
    return new ConfigurePortAnswer(cmd, true, "Port " + portWrapper.getPort().getId().toString() + " created");
}
Also used : NeutronPort(org.apache.cloudstack.network.opendaylight.api.model.NeutronPort) NeutronPortsNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) ConfigurePortAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer) NeutronPortWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper)

Aggregations

ConfigurePortAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.ConfigurePortAnswer)2 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 AddHypervisorCommand (org.apache.cloudstack.network.opendaylight.agent.commands.AddHypervisorCommand)1 ConfigurePortCommand (org.apache.cloudstack.network.opendaylight.agent.commands.ConfigurePortCommand)1 AddHypervisorAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.AddHypervisorAnswer)1 NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)1 NeutronPort (org.apache.cloudstack.network.opendaylight.api.model.NeutronPort)1 NeutronPortWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper)1 NeutronPortsNorthboundAction (org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction)1 OpenDaylightControllerVO (org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)1