Uni Add cmd CLI implmentation
[unimgr.git] / cli / src / main / java / org / opendaylight / unimgr / cli / UniListShellCommand.java
1 /*
2  * Copyright (c) 2015 Inocybe 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
9 package org.opendaylight.unimgr.cli;
10
11 import java.util.List;
12
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.commands.Option;
15 import org.apache.karaf.shell.console.OsgiCommandSupport;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
19
20 @Command(name = "list", scope = "uni", description = "Lists all uni in the controller.")
21 public class UniListShellCommand extends OsgiCommandSupport {
22
23     protected IUnimgrConsoleProvider provider;
24
25     @Option(name = "-c",
26             aliases = { "--config" },
27             description = "List Configuration Data (optional).\n-c / --config <ENTER>",
28             required = false,
29             multiValued = false)
30     Boolean isConfigurationData = false;
31
32     public UniListShellCommand(IUnimgrConsoleProvider provider) {
33         this.provider = provider;
34     }
35
36     @Override
37     protected Object doExecute() throws Exception {
38
39         List<Uni> listUnis = provider.listUnis(isConfigurationData);
40
41         if (listUnis.size() > 0) {
42             StringBuilder sb = new StringBuilder();
43             Integer counter = 1;
44             for (Uni uni : listUnis) {
45                 // TODO
46                 sb.append(String.format("#%d - id: %s\n", counter, uni.getIpAddress().getIpv4Address()));
47                 counter++;
48             }
49             return sb.toString();
50         } else {
51             return String.format("No uni found. Check the logs for more details.");
52         }
53     }
54 }