Move shaded components to third-party/
[netconf.git] / netconf / netconf-console / src / main / java / org / opendaylight / netconf / console / commands / NetconfListDevicesCommand.java
1 /*
2  * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.console.commands;
9
10 import com.google.common.annotations.VisibleForTesting;
11 import java.util.Map;
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;
20
21 @Service
22 @Command(name = "list-devices", scope = "netconf", description = "List all netconf devices in the topology.")
23 public class NetconfListDevicesCommand implements Action {
24
25     @Reference
26     private NetconfCommands service;
27
28     public NetconfListDevicesCommand() {
29
30     }
31
32     @VisibleForTesting
33     NetconfListDevicesCommand(final NetconfCommands service) {
34         this.service = service;
35     }
36
37     @Override
38     public Object execute() {
39         final Map<String, Map<String, String>> allDevices = service.listDevices();
40         printDevicesList(allDevices);
41         return null;
42     }
43
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();
51
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));
57         }
58         table.print(System.out);
59     }
60 }