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
9 package org.opendaylight.netconf.console.commands;
12 import javax.annotation.Nonnull;
13 import org.apache.karaf.shell.api.action.Action;
14 import org.apache.karaf.shell.api.action.Command;
15 import org.apache.karaf.shell.support.table.ShellTable;
16 import org.opendaylight.netconf.console.api.NetconfCommands;
17 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
19 @Command(name = "netconf:list-devices", scope = "netconf", description = "List all netconf devices in the topology.")
20 public class NetconfListDevicesCommand implements Action {
22 protected final NetconfCommands service;
24 public NetconfListDevicesCommand(final NetconfCommands service) {
25 this.service = service;
29 public Object execute() {
30 final Map<String, Map<String, String>> allDevices = service.listDevices();
31 printDevicesList(allDevices);
35 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
36 private static void printDevicesList(@Nonnull final Map<String, Map<String, String>> allDevices) {
37 final ShellTable table = new ShellTable();
38 table.column(NetconfConsoleConstants.NETCONF_ID).alignLeft();
39 table.column(NetconfConsoleConstants.NETCONF_IP).alignLeft();
40 table.column(NetconfConsoleConstants.NETCONF_PORT).alignLeft();
41 table.column(NetconfConsoleConstants.STATUS).alignLeft();
43 for (final Map<String, String> attributes : allDevices.values()) {
44 table.addRow().addContent(attributes.get(NetconfConsoleConstants.NETCONF_ID),
45 attributes.get(NetconfConsoleConstants.NETCONF_IP),
46 attributes.get(NetconfConsoleConstants.NETCONF_PORT),
47 attributes.get(NetconfConsoleConstants.STATUS));
49 table.print(System.out);