Search in sources :

Example 1 with OpenstackNetworkService

use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.

the class DirectPortListCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    Set<String> set = osNetService.ports().stream().filter(port -> port.getvNicType().equals(DIRECT)).map(Port::getId).collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();
    Iterator<String> it = set.iterator();
    while (it.hasNext()) {
        strings.add(it.next());
    }
    return delegate.complete(session, commandLine, candidates);
}
Also used : OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter)

Example 2 with OpenstackNetworkService

use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.

the class MacAddressCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    Set<MacAddress> set = osNetService.externalPeerRouters().stream().map(ExternalPeerRouter::macAddress).collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();
    Iterator<MacAddress> it = set.iterator();
    while (it.hasNext()) {
        strings.add(it.next().toString());
    }
    return delegate.complete(session, commandLine, candidates);
}
Also used : OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) MacAddress(org.onlab.packet.MacAddress)

Example 3 with OpenstackNetworkService

use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.

the class IpAddressCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    Set<IpAddress> set = osNetService.externalPeerRouters().stream().map(ExternalPeerRouter::ipAddress).collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();
    Iterator<IpAddress> it = set.iterator();
    while (it.hasNext()) {
        strings.add(it.next().toString());
    }
    return delegate.complete(session, commandLine, candidates);
}
Also used : OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) IpAddress(org.onlab.packet.IpAddress)

Example 4 with OpenstackNetworkService

use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.

the class OpenstackNetworkListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService service = get(OpenstackNetworkService.class);
    List<Network> networks = Lists.newArrayList(service.networks());
    networks.sort(Comparator.comparing(Network::getId));
    if (outputJson()) {
        print("%s", json(networks));
    } else {
        print(FORMAT, "ID", "Name", "Type", "SegId", "Subnets", "HostRoutes");
        for (Network net : networks) {
            List<Subnet> subnets = service.subnets().stream().filter(subnet -> subnet.getNetworkId().equals(net.getId())).collect(Collectors.toList());
            List<String> subnetsString = subnets.stream().map(Subnet::getCidr).collect(Collectors.toList());
            List<String> hostRoutes = Lists.newArrayList();
            subnets.forEach(subnet -> {
                subnet.getHostRoutes().forEach(h -> hostRoutes.add(h.toString()));
            });
            print(FORMAT, net.getId(), deriveResourceName(net), service.networkType(net.getId()).toString(), net.getProviderSegID(), subnets.isEmpty() ? "" : subnetsString, hostRoutes.isEmpty() ? "" : hostRoutes);
        }
    }
}
Also used : Network(org.openstack4j.model.network.Network) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Subnet(org.openstack4j.model.network.Subnet) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) NeutronNetwork(org.openstack4j.openstack.networking.domain.NeutronNetwork) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.apache.karaf.shell.api.action.lifecycle.Service) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Comparator(java.util.Comparator) OpenstackNetworkingUtil.modelEntityToJson(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson) OpenstackNetworkingUtil.prettyJson(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Network(org.openstack4j.model.network.Network) NeutronNetwork(org.openstack4j.openstack.networking.domain.NeutronNetwork) Subnet(org.openstack4j.model.network.Subnet)

Example 5 with OpenstackNetworkService

use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.

the class OpenstackSubnetListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService service = get(OpenstackNetworkService.class);
    List<Subnet> subnets = Lists.newArrayList(service.subnets());
    subnets.sort(Comparator.comparing(Subnet::getId));
    if (outputJson()) {
        print("%s", json(subnets));
    } else {
        print(FORMAT, "ID", "Name", "CIDR", "GatewayIp", "NetworkId", "NetworkName", "HostRoutes");
        for (Subnet subnet : subnets) {
            Network osNet = service.network(subnet.getNetworkId());
            String netName = osNet == null ? "N/A" : deriveResourceName(osNet);
            print(FORMAT, subnet.getId(), deriveResourceName(subnet), subnet.getCidr(), subnet.getGateway(), subnet.getNetworkId(), netName, subnet.getHostRoutes());
        }
    }
}
Also used : OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Network(org.openstack4j.model.network.Network) Subnet(org.openstack4j.model.network.Subnet) NeutronSubnet(org.openstack4j.openstack.networking.domain.NeutronSubnet)

Aggregations

OpenstackNetworkService (org.onosproject.openstacknetworking.api.OpenstackNetworkService)17 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)5 Port (org.openstack4j.model.network.Port)5 Command (org.apache.karaf.shell.api.action.Command)4 Service (org.apache.karaf.shell.api.action.lifecycle.Service)4 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)4 DeviceService (org.onosproject.net.device.DeviceService)4 Network (org.openstack4j.model.network.Network)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)3 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)3 Lists (com.google.common.collect.Lists)2 Comparator (java.util.Comparator)2 Argument (org.apache.karaf.shell.api.action.Argument)2 Completion (org.apache.karaf.shell.api.action.Completion)2 Test (org.junit.Test)2 AbstractShellCommand.get (org.onosproject.cli.AbstractShellCommand.get)2 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)2 InstancePortService (org.onosproject.openstacknetworking.api.InstancePortService)2