blob: 24503902aa7ebc8f71d8daa667254d1f44b158a1 [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
Thomas Vachuska635c2d72015-05-08 14:32:13 -070031 private static final String FMT = "driver=%s, extends=%s, mfr=%s, hw=%s, sw=%s";
Thomas Vachuska5c2f8132015-04-08 23:09:08 -070032 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) {
Thomas Vachuska635c2d72015-05-08 14:32:13 -070051 Driver parent = driver.parent();
52 print(FMT, driver.name(), parent != null ? parent.name() : "none",
53 driver.manufacturer(), driver.hwVersion(), driver.swVersion());
Thomas Vachuska5c2f8132015-04-08 23:09:08 -070054 driver.behaviours().forEach(b -> print(FMT_B, b.getCanonicalName(),
55 driver.implementation(b).getCanonicalName()));
56 driver.properties().forEach((k, v) -> print(FMT_P, k, v));
57 }
58
59}