Search in sources :

Example 11 with OpenstackNetworkService

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

the class OpenstackDirectPortAddCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    DeviceService deviceService = get(DeviceService.class);
    Port port = osNetService.port(portId);
    if (port == null) {
        log.error("There's no port that matches the port ID {}", portId);
        return;
    }
    Optional<OpenstackNode> osNode = osNodeService.completeNodes(COMPUTE).stream().filter(node -> node.hostname().equals(port.getHostId())).findAny();
    if (!osNode.isPresent()) {
        log.error("There's no openstackNode that matches hostname {}", port.getHostId());
        return;
    }
    String intfName = getIntfNameFromPciAddress(port);
    if (intfName == null) {
        log.error("Failed to retrieve interface name from a port {}", portId);
        return;
    } else if (intfName.equals(UNSUPPORTED_VENDOR)) {
        return;
    }
    if (OpenstackNetworkingUtil.hasIntfAleadyInDevice(osNode.get().intgBridge(), intfName, deviceService)) {
        log.error("Interface {} is already added to the device {}", osNode.get().intgBridge());
        return;
    }
    log.info("Adding interface {} to the device {}..", intfName, osNode.get().intgBridge());
    osNodeService.addVfPort(osNode.get(), intfName);
}
Also used : UNSUPPORTED_VENDOR(org.onosproject.openstacknetworking.api.Constants.UNSUPPORTED_VENDOR) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) OpenstackNetworkingUtil.getIntfNameFromPciAddress(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) OpenstackNetworkingUtil(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil) DeviceService(org.onosproject.net.device.DeviceService) Argument(org.apache.karaf.shell.api.action.Argument) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) Port(org.openstack4j.model.network.Port) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Port(org.openstack4j.model.network.Port) DeviceService(org.onosproject.net.device.DeviceService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 12 with OpenstackNetworkService

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

the class OpenstackDirectPortListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService service = get(OpenstackNetworkService.class);
    List<Port> ports = service.ports().stream().filter(port -> port.getvNicType().equals(DIRECT)).collect(Collectors.toList());
    print(FORMAT, "ID", "Network", "MAC", "FIXED IPs", "PCI Slot", "Interface");
    for (Port port : ports) {
        List<String> fixedIps = port.getFixedIps().stream().map(IP::getIpAddress).collect(Collectors.toList());
        Network osNet = service.network(port.getNetworkId());
        if (port.getVifType().equals(UNBOUND)) {
            print(FORMAT, port.getId(), deriveResourceName(osNet), port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps, UNBOUND, UNBOUND);
        } else {
            print(FORMAT, port.getId(), deriveResourceName(osNet), port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps, port.getProfile().containsKey(PCISLOT) ? port.getProfile().get(PCISLOT).toString() : "", getIntfNameFromPciAddress(port));
        }
    }
}
Also used : Network(org.openstack4j.model.network.Network) OpenstackNetworkingUtil.getIntfNameFromPciAddress(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress) PCISLOT(org.onosproject.openstacknetworking.api.Constants.PCISLOT) Collectors(java.util.stream.Collectors) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) List(java.util.List) DIRECT(org.onosproject.openstacknetworking.api.Constants.DIRECT) Service(org.apache.karaf.shell.api.action.lifecycle.Service) IP(org.openstack4j.model.network.IP) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Port(org.openstack4j.model.network.Port) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Port(org.openstack4j.model.network.Port) Network(org.openstack4j.model.network.Network)

Example 13 with OpenstackNetworkService

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

the class OpenstackPortListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService service = get(OpenstackNetworkService.class);
    List<Port> ports = Lists.newArrayList(service.ports());
    ports.sort(Comparator.comparing(Port::getNetworkId));
    if (!Strings.isNullOrEmpty(networkId)) {
        ports.removeIf(port -> !port.getNetworkId().equals(networkId));
    }
    if (outputJson()) {
        print("%s", json(ports));
    } else {
        print(FORMAT, "ID", "Network", "MAC", "Fixed IPs");
        for (Port port : ports) {
            List<String> fixedIps = port.getFixedIps().stream().map(IP::getIpAddress).collect(Collectors.toList());
            Network osNet = service.network(port.getNetworkId());
            String netName = osNet == null ? "N/A" : deriveResourceName(osNet);
            print(FORMAT, port.getId(), netName, port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps);
        }
    }
}
Also used : OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) NeutronPort(org.openstack4j.openstack.networking.domain.NeutronPort) Port(org.openstack4j.model.network.Port) Network(org.openstack4j.model.network.Network)

Example 14 with OpenstackNetworkService

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

the class OpenstackRecoverPortsCommand method doExecute.

@Override
protected void doExecute() {
    OvsdbController controller = get(OvsdbController.class);
    OpenstackNodeService nodeService = get(OpenstackNodeService.class);
    OpenstackNetworkService networkService = get(OpenstackNetworkService.class);
    DeviceService deviceService = get(DeviceService.class);
    if (isAll) {
        hostnames = nodeService.completeNodes().stream().map(OpenstackNode::hostname).toArray(String[]::new);
    }
    if (hostnames == null) {
        print("Please specify one of hostname or --all options.");
        return;
    }
    for (String hostname : hostnames) {
        networkService.ports().forEach(p -> {
            if (hostname.equals(p.getHostId())) {
                OpenstackNode osNode = nodeService.node(p.getHostId());
                if (osNode != null) {
                    Set<String> recoveredPortNames = recoverOvsPort(controller, OVS_DB_PORT, osNode, p, deviceService.getPorts(osNode.intgBridge()));
                    recoveredPortNames.forEach(pn -> print(pn + " is recovered!"));
                }
            }
        });
    }
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) DeviceService(org.onosproject.net.device.DeviceService) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 15 with OpenstackNetworkService

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

the class OpenstackVmStatsCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    InstancePortService osInstanceService = get(InstancePortService.class);
    DeviceService deviceService = get(DeviceService.class);
    Set<Port> ports = osNetService.ports().stream().filter(port -> port.getDeviceId().equals(vmDeviceId)).collect(Collectors.toSet());
    if (ports.isEmpty()) {
        print(NO_PORTS);
        return;
    }
    Set<InstancePort> instancePorts = getInstancePortFromNeutronPortList(ports, osInstanceService);
    if (instancePorts.isEmpty()) {
        print(NO_INSTANCE_PORTS);
        return;
    }
    Set<PortNumber> portNumbers = instancePorts.stream().map(InstancePort::portNumber).collect(Collectors.toSet());
    instancePorts.stream().findAny().ifPresent(instancePort -> {
        DeviceId deviceId = instancePort.deviceId();
        if (delta) {
            printPortStatsDelta(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
            if (table) {
                printPortStatsDeltaTable(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
            }
        } else {
            printPortStats(vmDeviceId, deviceService.getPortStatistics(deviceId), portNumbers);
        }
    });
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Command(org.apache.karaf.shell.api.action.Command) TimeUnit(java.util.concurrent.TimeUnit) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Comparator(java.util.Comparator) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) Port(org.openstack4j.model.network.Port) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) DeviceId(org.onosproject.net.DeviceId) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.openstack4j.model.network.Port) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) DeviceService(org.onosproject.net.device.DeviceService) PortNumber(org.onosproject.net.PortNumber)

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