tom | 6d2a43e | 2014-09-08 01:50:20 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onlab.onos.cli.AbstractShellCommand; |
| 6 | import org.onlab.onos.net.Port; |
| 7 | import org.onlab.onos.net.device.DeviceService; |
| 8 | |
| 9 | import 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") |
| 16 | public 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 | } |