blob: d477279d737a3ef7821568b7dc6a0bdb4a5ae874 [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska96d55b12015-05-11 08:52:03 -07003 *
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.cfg;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Command;
19import org.apache.karaf.shell.api.action.lifecycle.Service;
20import org.apache.karaf.shell.api.action.Option;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070021import org.onosproject.cli.AbstractShellCommand;
Ray Milkeya4122362015-08-18 15:19:08 -070022import org.onosproject.net.config.ConfigFactory;
23import org.onosproject.net.config.NetworkConfigRegistry;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070024
25/**
26 * Displays network configuration registry contents.
27 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070028@Service
Thomas Vachuska96d55b12015-05-11 08:52:03 -070029@Command(scope = "onos", name = "netcfg-registry",
30 description = "Displays network configuration registry contents")
31public 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 Milkeyd84f89b2018-08-17 14:54:17 -070041 protected void doExecute() {
Thomas Vachuska96d55b12015-05-11 08:52:03 -070042 get(NetworkConfigRegistry.class).getConfigFactories().forEach(this::print);
43 }
44
45 private void print(ConfigFactory configFactory) {
46 print(shortOnly ? SHORT_FMT : FMT,
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070047 configFactory.subjectFactory().subjectClassKey(),
Thomas Vachuska96d55b12015-05-11 08:52:03 -070048 configFactory.configKey(),
49 configFactory.subjectFactory().subjectClass().getName(),
50 configFactory.configClass().getName());
51 }
52
53}