blob: 992c93a22b459310a74065ea263bb44686ba49c5 [file] [log] [blame]
Jian Li69600e02018-12-24 13:21:18 +09001/*
2 * Copyright 2018-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 */
16package org.onosproject.openstacktelemetry.cli;
17
18import org.apache.karaf.shell.api.action.Command;
19import org.apache.karaf.shell.api.action.lifecycle.Service;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.openstacktelemetry.api.TelemetryConfigService;
22import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
23
24import java.util.Comparator;
25import java.util.List;
26import java.util.stream.Collectors;
27
28/**
29 * Lists Telemetry configurations.
30 */
31@Service
32@Command(scope = "onos", name = "telemetry-configs",
33 description = "Lists all Telemetry configurations")
34public class TelemetryConfigListCommand extends AbstractShellCommand {
35
36 private static final String FORMAT = "%-30s%-15s%-15s%-30s%-15s";
37 private static final String MASTER = "master";
38
39 @Override
40 protected void doExecute() {
41 TelemetryConfigService service = get(TelemetryConfigService.class);
42 List<TelemetryConfig> configs = service.getConfigs().stream()
43 .filter(c -> !c.swVersion().equals(MASTER))
44 .sorted(Comparator.comparing(TelemetryConfig::type))
45 .collect(Collectors.toList());
46
47 print(FORMAT, "Name", "Type", "Enabled", "Manufacturer", "swVersion");
48 for (TelemetryConfig config : configs) {
49 print(FORMAT, config.name(),
50 config.type(),
51 config.enabled() ? "ENABLED" : "DISABLED",
52 config.manufacturer(),
53 config.swVersion());
54 }
55 }
56}