2 * Copyright (c) 2015 Inocybe 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.unimgr.cli;
11 import java.util.List;
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 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
21 @Command(name = "uni-list", scope = "uni", description = "Lists all uni in the controller.")
22 public class UniListShellCommand extends OsgiCommandSupport {
24 protected IUnimgrConsoleProvider provider;
27 aliases = { "--config" },
28 description = "List Configuration Data (optional).\n-c / --config <ENTER>",
31 Boolean isConfigurationData = false;
33 public UniListShellCommand(IUnimgrConsoleProvider provider) {
34 this.provider = provider;
38 protected Object doExecute() throws Exception {
40 LogicalDatastoreType storeType = isConfigurationData ? LogicalDatastoreType.CONFIGURATION : LogicalDatastoreType.OPERATIONAL;
41 List<UniAugmentation> listUnis = provider.listUnis(storeType);
43 if (listUnis.size() > 0) {
44 StringBuilder sb = new StringBuilder();
46 for (UniAugmentation uni : listUnis) {
48 sb.append(String.format("#%d - IpAddress: %s\n", counter, uni.getIpAddress().getIpv4Address().getValue()));
53 return String.format("No uni found. Check the logs for more details.");