Uni Add cmd CLI implmentation
[unimgr.git] / cli / src / main / java / org / opendaylight / unimgr / cli / UniAddShellCommand.java
index 9b5835e4c810f77c864badd6ec7669057421314e..8de1a77513f14d9096b9c946edb940fbdaa74d2a 100755 (executable)
@@ -13,40 +13,37 @@ import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-@Command(name = "add",
+@Command(name = "uni-add",
          scope = "uni",
          description = "Adds an uni to the controller.")
 public class UniAddShellCommand extends OsgiCommandSupport {
 
+    private static final Logger LOG = LoggerFactory.getLogger(UniAddShellCommand.class);
     protected IUnimgrConsoleProvider provider;
 
-    @Option(name = "-id",
-            aliases = { "--uni-id" },
-            description = "The id.\n-id / --id <id>",
-            required = true,
-            multiValued = false)
-    private String uniId = "any";
-
     @Option(name = "-pm",
             aliases = { "--physical-medium" },
             description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
             required = false,
             multiValued = false)
-    private String physicalMedium = "any";
+    private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
 
     @Option(name = "-ma",
             aliases = { "--mac-address" },
             description = "The mac address.\n-ma / --mac-address <mac-address>",
-            required = false,
+            required = true,
             multiValued = false)
     private String macAddress = "any";
 
@@ -55,64 +52,67 @@ public class UniAddShellCommand extends OsgiCommandSupport {
             description = "The mode.\n-m / --mode <mode>",
             required = false,
             multiValued = false)
-    private String mode = "any";
+    private String mode = "Full Duplex";
 
     @Option(name = "-ml",
             aliases = { "--mac-layer" },
             description = "The mac layer.\n-ml / --mac-layer <mac-layer",
             required = false,
             multiValued = false)
-    private String macLayer = "any";
+    private String macLayer = "IEEE 802.3-2005";
 
     @Option(name = "-t",
             aliases = { "--type" },
             description = "The type.\n-t / --type <type>",
             required = false,
             multiValued = false)
-    private String type = "any";
+    private String type = "";
 
     @Option(name = "-ms",
             aliases = { "--mtu-size" },
             description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
             required = false,
             multiValued = false)
-    private String mtuSize;
+    private String mtuSize = "0";
 
     @Option(name = "-s",
             aliases = { "--speed" },
             description = "Spped.\n-s / --speed 10M/100M/1G/10G",
-            required = true,
+            required = false,
             multiValued = true)
-    private String speed = "any";
+    private String speed = "";
+
+    @Option(name = "-ip",
+            aliases = { "--ipAddress" },
+            description = "IpAddress of the Uni",
+            required = true,
+            multiValued = false)
+    private String ipAddress = "any";
 
     public UniAddShellCommand(IUnimgrConsoleProvider provider) {
         this.provider = provider;
     }
 
     private Object getSpeed() {
-
-        System.out.println(speed);
-
         Object speedObject = null;
         if (speed.equals("10M")) {
             speedObject = new Speed10MBuilder().build();
         }
-        if (speed.equals("100M")) {
+        else if (speed.equals("100M")) {
             speedObject = new Speed100MBuilder().build();
         }
-        if (speed.equals("1G")) {
+        else if (speed.equals("1G")) {
             speedObject = new Speed1GBuilder().build();
         }
-        if (speed.equals("10G")) {
+        else if (speed.equals("10G")) {
             speedObject = new Speed10GBuilder().build();
         }
-        System.out.println(speedObject);
         return speedObject;
     }
 
     @Override
     protected Object doExecute() throws Exception {
-        Uni uni = new UniAugmentationBuilder()
+        UniAugmentation uni = new UniAugmentationBuilder()
                         .setMacAddress(new MacAddress(macAddress))
                         .setMacLayer(macLayer)
                         .setMode(mode)
@@ -120,12 +120,13 @@ public class UniAddShellCommand extends OsgiCommandSupport {
                         .setPhysicalMedium(physicalMedium)
                         .setSpeed((Speed) getSpeed())
                         .setType(type)
+                        .setIpAddress(new IpAddress(ipAddress.toCharArray()))
                         .build();
 
         if (provider.addUni(uni)) {
-            return String.format("Uni created {}", uni.getIpAddress().getIpv4Address());
+            return new String("Uni with ip " +ipAddress+" created");
         } else {
-            return new String("Error creating new uni");
+            return new String("Error creating new Uni");
         }
     }
 }