570b6a102dad7f690102da06bd29c8fffd4e600e
[unimgr.git] / cli / src / main / java / org / opendaylight / vcpe / 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.vcpe.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.vcpe.api.IVcpeConsoleProvider;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vcpe.rev150622.unis.Uni;
18
19 @Command(name = "list", scope = "uni", description = "Lists all uni in the controller.")
20 public class UniListShellCommand extends OsgiCommandSupport {
21
22     protected IVcpeConsoleProvider provider;
23
24     @Option(name = "-c",
25             aliases = { "--config" },
26             description = "List Configuration Data (optional).\n-c / --config <ENTER>",
27             required = false,
28             multiValued = false)
29     Boolean isConfigurationData = false;
30
31     public UniListShellCommand(IVcpeConsoleProvider provider) {
32         this.provider = provider;
33     }
34
35     @Override
36     protected Object doExecute() throws Exception {
37
38         List<Uni> listUnis = provider.listUnis(isConfigurationData);
39
40         if (listUnis.size() > 0) {
41             StringBuilder sb = new StringBuilder();
42             Integer counter = 1;
43             for (Uni uni : listUnis) {
44                 sb.append(String.format("#%d - id: %s\n", counter, uni.getId()));
45                 counter++;
46             }
47             return sb.toString();
48         } else {
49             return String.format("No uni found. Check the logs for more details.");
50         }
51     }
52 }