2 * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.console.commands;
10 import com.google.common.annotations.VisibleForTesting;
12 import org.apache.karaf.shell.api.action.Action;
13 import org.apache.karaf.shell.api.action.Command;
14 import org.apache.karaf.shell.api.action.lifecycle.Reference;
15 import org.apache.karaf.shell.api.action.lifecycle.Service;
16 import org.apache.karaf.shell.support.table.ShellTable;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.netconf.console.api.NetconfCommands;
19 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
22 @Command(name = "list-devices", scope = "netconf", description = "List all netconf devices in the topology.")
23 public class NetconfListDevicesCommand implements Action {
26 private NetconfCommands service;
28 public NetconfListDevicesCommand() {
33 NetconfListDevicesCommand(final NetconfCommands service) {
34 this.service = service;
38 public Object execute() {
39 final Map<String, Map<String, String>> allDevices = service.listDevices();
40 printDevicesList(allDevices);
44 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
45 private static void printDevicesList(final @NonNull Map<String, Map<String, String>> allDevices) {
46 final ShellTable table = new ShellTable();
47 table.column(NetconfConsoleConstants.NETCONF_ID).alignLeft();
48 table.column(NetconfConsoleConstants.NETCONF_IP).alignLeft();
49 table.column(NetconfConsoleConstants.NETCONF_PORT).alignLeft();
50 table.column(NetconfConsoleConstants.STATUS).alignLeft();
52 for (final Map<String, String> attributes : allDevices.values()) {
53 table.addRow().addContent(attributes.get(NetconfConsoleConstants.NETCONF_ID),
54 attributes.get(NetconfConsoleConstants.NETCONF_IP),
55 attributes.get(NetconfConsoleConstants.NETCONF_PORT),
56 attributes.get(NetconfConsoleConstants.STATUS));
58 table.print(System.out);