Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Foundation |
| 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.Command; |
| 19 | import org.onosproject.cli.AbstractShellCommand; |
| 20 | import org.onosproject.net.driver.Driver; |
| 21 | import org.onosproject.net.driver.DriverAdminService; |
| 22 | import org.onosproject.net.driver.DriverProvider; |
| 23 | |
| 24 | import java.util.stream.Collectors; |
| 25 | |
| 26 | /** |
| 27 | * Lists device drivers. |
| 28 | */ |
| 29 | @Command(scope = "onos", name = "driver-providers", |
| 30 | description = "Lists device driver providers") |
| 31 | public class DriverProvidersListCommand extends AbstractShellCommand { |
| 32 | |
| 33 | private static final String FMT = "provider=%s, drivers=%s"; |
| 34 | |
| 35 | @Override |
| 36 | protected void execute() { |
| 37 | DriverAdminService service = get(DriverAdminService.class); |
| 38 | service.getProviders().forEach(this::printDriverProvider); |
| 39 | } |
| 40 | |
| 41 | private void printDriverProvider(DriverProvider provider) { |
| 42 | print(FMT, provider.getClass().getName(), |
| 43 | provider.getDrivers().stream() |
| 44 | .map(Driver::name) |
| 45 | .collect(Collectors.toSet())); |
| 46 | } |
| 47 | |
| 48 | } |