blob: f09e39a66ad8b3f8f44722e3940e185c02797fa5 [file] [log] [blame]
tom6d2a43e2014-09-08 01:50:20 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.commands.Argument;
4import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.cli.AbstractShellCommand;
6import org.onlab.onos.net.Port;
7import org.onlab.onos.net.device.DeviceService;
8
9import static org.onlab.onos.net.DeviceId.deviceId;
10
11/**
12 * Lists all infrastructure links.
13 */
14@Command(scope = "onos", name = "ports",
15 description = "Lists all ports of a device")
16public class DevicePortsListCommand extends AbstractShellCommand {
17
18 private static final String FMT = "port=%s, state=%s";
19
20 @Argument(index = 0, name = "deviceId", description = "Device ID",
21 required = true, multiValued = false)
22 String deviceId = null;
23
24 @Override
25 protected Object doExecute() throws Exception {
26 DeviceService service = getService(DeviceService.class);
27 Iterable<Port> ports = service.getPorts(deviceId(deviceId));
28 for (Port port : ports) {
29 print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled");
30 }
31 return null;
32 }
33}