Search in sources :

Example 1 with ConfigureNetworkAnswer

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

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

the class OpenDaylightControllerResource method executeRequest.

private Answer executeRequest(ConfigureNetworkCommand cmd) {
    NeutronNetworksNorthboundAction configureNetwork = new NeutronNetworksNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
    // Find free gre key
    int gre_key = -1;
    Random keyGenerator = new Random(System.currentTimeMillis());
    try {
        NeutronNetworksList<NeutronNetwork> networks = configureNetwork.listAllNetworks();
        while (true) {
            int i = keyGenerator.nextInt();
            for (NeutronNetwork network : networks.getNetworks()) {
                if (network.getSegmentationId() == i) {
                    continue;
                }
            }
            gre_key = i;
            break;
        }
    } catch (NeutronRestApiException e) {
        s_logger.error("Failed to list existing networks on the ODL Controller", e);
        return new ConfigureNetworkAnswer(cmd, e);
    }
    NeutronNetwork newNetwork = new NeutronNetwork();
    // Configuration from the command
    newNetwork.setName(cmd.getName());
    newNetwork.setTenantId(cmd.getTenantId());
    // Static configuation
    newNetwork.setNetworkType("gre");
    newNetwork.setShared(false);
    newNetwork.setSegmentationId(gre_key);
    newNetwork.setId(UUID.randomUUID());
    NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper();
    wrapper.setNetwork(newNetwork);
    try {
        wrapper = configureNetwork.createNeutronNetwork(wrapper);
    } catch (NeutronRestApiException e) {
        s_logger.error("createNeutronNetwork failed", e);
        return new ConfigureNetworkAnswer(cmd, e);
    }
    return new ConfigureNetworkAnswer(cmd, true, null, wrapper.getNetwork().getId().toString());
}
Also used : NeutronNetwork(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork) Random(java.util.Random) ConfigureNetworkAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper) NeutronNetworksNorthboundAction(org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction)

Aggregations

ConfigureNetworkAnswer (org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer)2 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 Random (java.util.Random)1 ConfigureNetworkCommand (org.apache.cloudstack.network.opendaylight.agent.commands.ConfigureNetworkCommand)1 NeutronRestApiException (org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)1 NeutronNetwork (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork)1 NeutronNetworkWrapper (org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)1 NeutronNetworksNorthboundAction (org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction)1 OpenDaylightControllerVO (org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)1