Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 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.cfg; |
| 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Command; |
| 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 20 | import org.apache.karaf.shell.api.action.Option; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 22 | import org.onosproject.net.config.ConfigFactory; |
| 23 | import org.onosproject.net.config.NetworkConfigRegistry; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Displays network configuration registry contents. |
| 27 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 28 | @Service |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 29 | @Command(scope = "onos", name = "netcfg-registry", |
| 30 | description = "Displays network configuration registry contents") |
| 31 | public class NetworkConfigRegistryCommand extends AbstractShellCommand { |
| 32 | |
| 33 | private static final String FMT = "subjectKey=%s, configKey=%s, subjectClass=%s, configClass=%s"; |
| 34 | private static final String SHORT_FMT = "%-12s %-12s %-40s %s"; |
| 35 | |
| 36 | @Option(name = "-s", aliases = "--short", description = "Show short output only", |
| 37 | required = false, multiValued = false) |
| 38 | private boolean shortOnly = false; |
| 39 | |
| 40 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 41 | protected void doExecute() { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 42 | get(NetworkConfigRegistry.class).getConfigFactories().forEach(this::print); |
| 43 | } |
| 44 | |
| 45 | private void print(ConfigFactory configFactory) { |
| 46 | print(shortOnly ? SHORT_FMT : FMT, |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame] | 47 | configFactory.subjectFactory().subjectClassKey(), |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 48 | configFactory.configKey(), |
| 49 | configFactory.subjectFactory().subjectClass().getName(), |
| 50 | configFactory.configClass().getName()); |
| 51 | } |
| 52 | |
| 53 | } |