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;
11 import com.google.common.annotations.VisibleForTesting;
13 import javax.annotation.Nonnull;
14 import org.apache.karaf.shell.api.action.Action;
15 import org.apache.karaf.shell.api.action.Command;
16 import org.apache.karaf.shell.api.action.lifecycle.Reference;
17 import org.apache.karaf.shell.api.action.lifecycle.Service;
18 import org.apache.karaf.shell.support.table.ShellTable;
19 import org.opendaylight.netconf.console.api.NetconfCommands;
20 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
23 @Command(name = "list-devices", scope = "netconf", description = "List all netconf devices in the topology.")
24 public class NetconfListDevicesCommand implements Action {
27 private NetconfCommands service;
29 public NetconfListDevicesCommand() {
34 NetconfListDevicesCommand(final NetconfCommands service) {
35 this.service = service;
39 public Object execute() {
40 final Map<String, Map<String, String>> allDevices = service.listDevices();
41 printDevicesList(allDevices);
45 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
46 private static void printDevicesList(@Nonnull final Map<String, Map<String, String>> allDevices) {
47 final ShellTable table = new ShellTable();
48 table.column(NetconfConsoleConstants.NETCONF_ID).alignLeft();
49 table.column(NetconfConsoleConstants.NETCONF_IP).alignLeft();
50 table.column(NetconfConsoleConstants.NETCONF_PORT).alignLeft();
51 table.column(NetconfConsoleConstants.STATUS).alignLeft();
53 for (final Map<String, String> attributes : allDevices.values()) {
54 table.addRow().addContent(attributes.get(NetconfConsoleConstants.NETCONF_ID),
55 attributes.get(NetconfConsoleConstants.NETCONF_IP),
56 attributes.get(NetconfConsoleConstants.NETCONF_PORT),
57 attributes.get(NetconfConsoleConstants.STATUS));
59 table.print(System.out);