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.Command; |
| 4 | import org.onlab.onos.cli.AbstractShellCommand; |
| 5 | import org.onlab.onos.net.Device; |
| 6 | import org.onlab.onos.net.device.DeviceService; |
| 7 | |
| 8 | /** |
| 9 | * Lists all infrastructure devices. |
| 10 | */ |
| 11 | @Command(scope = "onos", name = "devices", |
| 12 | description = "Lists all infrastructure devices") |
| 13 | public class DevicesListCommand extends AbstractShellCommand { |
| 14 | |
| 15 | private static final String FMT = |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame^] | 16 | "id=%s, available=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"; |
tom | 6d2a43e | 2014-09-08 01:50:20 -0700 | [diff] [blame] | 17 | |
| 18 | @Override |
| 19 | protected Object doExecute() throws Exception { |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame^] | 20 | DeviceService service = getService(DeviceService.class); |
| 21 | for (Device device : service.getDevices()) { |
| 22 | printDevice(device, service.isAvailable(device.id())); |
tom | 6d2a43e | 2014-09-08 01:50:20 -0700 | [diff] [blame] | 23 | } |
| 24 | return null; |
| 25 | } |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame^] | 26 | |
| 27 | /** |
| 28 | * Prints information about the specified device. |
| 29 | * |
| 30 | * @param device infrastructure device |
| 31 | * @param isAvailable true of device is available |
| 32 | */ |
| 33 | protected void printDevice(Device device, boolean isAvailable) { |
| 34 | print(FMT, device.id(), isAvailable, device.type(), |
| 35 | device.manufacturer(), device.hwVersion(), device.swVersion(), |
| 36 | device.serialNumber()); |
| 37 | } |
| 38 | |
tom | 6d2a43e | 2014-09-08 01:50:20 -0700 | [diff] [blame] | 39 | } |