Uni Add cmd CLI implmentation
[unimgr.git] / cli / src / main / java / org / opendaylight / unimgr / cli / UniShowShellCommand.java
1 /*
2  * Copyright (c) 2015 CableLabs 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.unimgr.cli;
9
10 import org.apache.karaf.shell.commands.Argument;
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
16
17 @Command(name = "show", scope = "uni", description = "Shows detailed information about an uni.")
18 public class UniShowShellCommand extends OsgiCommandSupport {
19
20     protected IUnimgrConsoleProvider provider;
21
22     @Argument(index = 0, name = "ip", description = "Uni ipAddress", required = true, multiValued = false)
23     String ipAddress;
24
25     public UniShowShellCommand(IUnimgrConsoleProvider provider) {
26         this.provider = provider;
27     }
28
29     @Override
30     protected Object doExecute() throws Exception {
31         StringBuilder sb = new StringBuilder();
32         IpAddress ipAddre = new IpAddress(ipAddress.toCharArray());
33         Uni uni = provider.getUni(ipAddre);
34
35         if (uni != null) {
36             //sb.append(String.format("Uni Id: <%s>\n", uni.getUniId()));
37             sb.append(String.format("Physical medium: <%s>\n", uni.getPhysicalMedium()));
38             sb.append(String.format("Mac address: <%s>\n", uni.getMacAddress()));
39             sb.append(String.format("Speed: " + uni.getSpeed() + "\n"));
40             sb.append(String.format("Mode: <%s>\n", uni.getMode()));
41             sb.append(String.format("Mac layer: <%s>\n", uni.getMacLayer()));
42             sb.append(String.format("Type: <%s>\n", uni.getType()));
43             sb.append(String.format("Mtu size: <%s>\n", uni.getMtuSize()));
44             return sb.toString();
45         } else {
46             return String.format("No uni found. Check the logs for more details.");
47         }
48     }
49 }