blob: fd4c96c565b8c1f00f72fd5981795be7dbb2b46b [file] [log] [blame]
Thomas Vachuska5c2f8132015-04-08 23:09:08 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.driver.Driver;
22import org.onosproject.net.driver.DriverAdminService;
23
24/**
25 * Lists device drivers.
26 */
27@Command(scope = "onos", name = "drivers",
28 description = "Lists device drivers")
29public class DriversListCommand extends AbstractShellCommand {
30
31 private static final String FMT = "driver=%s, mfr=%s, hw=%s, sw=%s";
32 private static final String FMT_B = " %s via %s";
33 private static final String FMT_P = " %s=%s";
34
35 @Argument(index = 0, name = "driverName", description = "Driver name",
36 required = false, multiValued = false)
37 String driverName = null;
38
39 @Override
40 protected void execute() {
41 DriverAdminService service = get(DriverAdminService.class);
42
43 if (driverName != null) {
44 printDriver(service.getDriver(driverName));
45 } else {
46 service.getDrivers().forEach(this::printDriver);
47 }
48 }
49
50 private void printDriver(Driver driver) {
51 print(FMT, driver.name(), driver.manufacturer(),
52 driver.hwVersion(), driver.swVersion());
53 driver.behaviours().forEach(b -> print(FMT_B, b.getCanonicalName(),
54 driver.implementation(b).getCanonicalName()));
55 driver.properties().forEach((k, v) -> print(FMT_P, k, v));
56 }
57
58}