Thomas Vachuska | 5c2f813 | 2015-04-08 23:09:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.cli.net; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.driver.Driver; |
| 22 | import org.onosproject.net.driver.DriverAdminService; |
| 23 | |
| 24 | /** |
| 25 | * Lists device drivers. |
| 26 | */ |
| 27 | @Command(scope = "onos", name = "drivers", |
| 28 | description = "Lists device drivers") |
| 29 | public class DriversListCommand extends AbstractShellCommand { |
| 30 | |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 31 | private static final String FMT = "driver=%s, extends=%s, mfr=%s, hw=%s, sw=%s"; |
Thomas Vachuska | 5c2f813 | 2015-04-08 23:09:08 -0700 | [diff] [blame] | 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) { |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 51 | Driver parent = driver.parent(); |
| 52 | print(FMT, driver.name(), parent != null ? parent.name() : "none", |
| 53 | driver.manufacturer(), driver.hwVersion(), driver.swVersion()); |
Thomas Vachuska | 5c2f813 | 2015-04-08 23:09:08 -0700 | [diff] [blame] | 54 | 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 | } |