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.commands.Command;
14 import org.apache.karaf.shell.console.AbstractAction;
15 import org.apache.karaf.shell.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 extends AbstractAction {
22 protected final NetconfCommands service;
24 public NetconfListDevicesCommand(final NetconfCommands service) {
25 this.service = service;
29 protected Object doExecute() throws Exception {
30 final Map<String, Map<String, String>> allDevices = service.listDevices();
31 printDevicesList(allDevices);
35 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
36 private 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 String nodeIds : allDevices.keySet()) {
44 final Map<String, String> attributes = allDevices.get(nodeIds);
45 table.addRow().addContent(attributes.get(NetconfConsoleConstants.NETCONF_ID),
46 attributes.get(NetconfConsoleConstants.NETCONF_IP),
47 attributes.get(NetconfConsoleConstants.NETCONF_PORT),
48 attributes.get(NetconfConsoleConstants.STATUS));
50 table.print(System.out);