blob: 21bb892c9a915ca5579f3ad359dc4c367fac7008 [file] [log] [blame]
tom6d2a43e2014-09-08 01:50:20 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.commands.Command;
4import org.onlab.onos.cli.AbstractShellCommand;
5import org.onlab.onos.net.Device;
6import 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")
13public class DevicesListCommand extends AbstractShellCommand {
14
15 private static final String FMT =
tomff7eb7c2014-09-08 12:49:03 -070016 "id=%s, available=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s";
tom6d2a43e2014-09-08 01:50:20 -070017
18 @Override
19 protected Object doExecute() throws Exception {
tomff7eb7c2014-09-08 12:49:03 -070020 DeviceService service = getService(DeviceService.class);
21 for (Device device : service.getDevices()) {
22 printDevice(device, service.isAvailable(device.id()));
tom6d2a43e2014-09-08 01:50:20 -070023 }
24 return null;
25 }
tomff7eb7c2014-09-08 12:49:03 -070026
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
tom6d2a43e2014-09-08 01:50:20 -070039}