uni show and list commands 26/29826/1
authorMohamed El-Serngawy <melserngawy@inocybe.com>
Tue, 17 Nov 2015 17:58:25 +0000 (12:58 -0500)
committerMohamed El-Serngawy <melserngawy@inocybe.com>
Tue, 17 Nov 2015 17:58:25 +0000 (12:58 -0500)
Change-Id: Iac5914c9d205088a06ce1dd4318666a4fa74aa96
Signed-off-by: Mohamed El-Serngawy <melserngawy@inocybe.com>
cli/src/main/java/org/opendaylight/unimgr/cli/UniListShellCommand.java
cli/src/main/java/org/opendaylight/unimgr/cli/UniShowShellCommand.java
impl/src/main/java/org/opendaylight/unimgr/api/IUnimgrConsoleProvider.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrProvider.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java

index a210b898908c8b7d4308cbb77f1e819f5dd6ae1d..988c1f7aae8cca4d407affec8f235a8d4ba70bb4 100755 (executable)
@@ -16,8 +16,9 @@ import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
 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;
 
-@Command(name = "list", scope = "uni", description = "Lists all uni in the controller.")
+@Command(name = "uni-list", scope = "uni", description = "Lists all uni in the controller.")
 public class UniListShellCommand extends OsgiCommandSupport {
 
     protected IUnimgrConsoleProvider provider;
@@ -36,14 +37,15 @@ public class UniListShellCommand extends OsgiCommandSupport {
     @Override
     protected Object doExecute() throws Exception {
 
-        List<Uni> listUnis = provider.listUnis(isConfigurationData);
+        LogicalDatastoreType storeType = isConfigurationData ? LogicalDatastoreType.CONFIGURATION : LogicalDatastoreType.OPERATIONAL; 
+        List<UniAugmentation> listUnis = provider.listUnis(storeType);
 
         if (listUnis.size() > 0) {
             StringBuilder sb = new StringBuilder();
             Integer counter = 1;
-            for (Uni uni : listUnis) {
+            for (UniAugmentation uni : listUnis) {
                 // TODO
-                sb.append(String.format("#%d - id: %s\n", counter, uni.getIpAddress().getIpv4Address()));
+                sb.append(String.format("#%d - IpAddress: %s\n", counter, uni.getIpAddress().getIpv4Address().getValue()));
                 counter++;
             }
             return sb.toString();
index eeb02e2d7ef35d0b5daecabadaf66004b8608a53..0df6db2114e754469edfdda3353568e59aa3a539 100755 (executable)
@@ -12,9 +12,9 @@ import org.apache.karaf.shell.commands.Command;
 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.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
 
-@Command(name = "show", scope = "uni", description = "Shows detailed information about an uni.")
+@Command(name = "uni-show", scope = "uni", description = "Shows detailed information about an uni.")
 public class UniShowShellCommand extends OsgiCommandSupport {
 
     protected IUnimgrConsoleProvider provider;
@@ -30,12 +30,12 @@ public class UniShowShellCommand extends OsgiCommandSupport {
     protected Object doExecute() throws Exception {
         StringBuilder sb = new StringBuilder();
         IpAddress ipAddre = new IpAddress(ipAddress.toCharArray());
-        Uni uni = provider.getUni(ipAddre);
+        UniAugmentation uni = provider.getUni(ipAddre);
 
         if (uni != null) {
-            //sb.append(String.format("Uni Id: <%s>\n", uni.getUniId()));
-            sb.append(String.format("Physical medium: <%s>\n", uni.getPhysicalMedium()));
+            sb.append(String.format("Ip Address: <%s>\n", uni.getIpAddress().getIpv4Address().getValue()));
             sb.append(String.format("Mac address: <%s>\n", uni.getMacAddress()));
+            sb.append(String.format("Physical medium: <%s>\n", uni.getPhysicalMedium()));
             sb.append(String.format("Speed: " + uni.getSpeed() + "\n"));
             sb.append(String.format("Mode: <%s>\n", uni.getMode()));
             sb.append(String.format("Mac layer: <%s>\n", uni.getMacLayer()));
index 1346649dd8b9006be684c13cf6fd4767844d9e36..c4fc4ce1cea7d28c9ba6a770717518454a586ddc 100755 (executable)
@@ -12,7 +12,6 @@ import java.util.List;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Evc;
-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;
 
 public interface IUnimgrConsoleProvider extends AutoCloseable {
@@ -21,9 +20,9 @@ public interface IUnimgrConsoleProvider extends AutoCloseable {
 
     boolean removeUni(IpAddress ipAddress);
 
-    List<Uni> listUnis(Boolean isConfigurationData);
+    List<UniAugmentation> listUnis(LogicalDatastoreType dataStoreType);
 
-    Uni getUni(IpAddress ipAddress);
+    UniAugmentation getUni(IpAddress ipAddress);
 
     boolean removeEvc(String uuid);
 
index beb31dc66e698740b5a0a6349f22f1ad828c314c..4bc29f54cbbd8822e0c27dcdb11635476030a36b 100755 (executable)
@@ -20,7 +20,6 @@ import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
 import org.opendaylight.unimgr.command.TransactionInvoker;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Evc;
-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.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopologyBuilder;
@@ -143,15 +142,13 @@ public class UnimgrProvider implements BindingAwareProvider, AutoCloseable, IUni
     }
 
     @Override
-    public List<Uni> listUnis(Boolean isConfigurationData) {
-        // TODO Auto-generated method stub
-        return null;
+    public List<UniAugmentation> listUnis(LogicalDatastoreType dataStoreType) {
+        return UnimgrUtils.getUnis(dataBroker, dataStoreType);
     }
 
     @Override
-    public Uni getUni(IpAddress ipAddress) {
-        // TODO Auto-generated method stub
-        return null;
+    public UniAugmentation getUni(IpAddress ipAddress) {
+        return UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.CONFIGURATION, ipAddress);
     }
 
 
index edc213b120e65ba854557e773e47161ba25c869f..5195eddaca6a6c4476e82759183865f11a4db527 100644 (file)
@@ -741,6 +741,54 @@ public class UnimgrUtils {
         return uniNodes;
     }
 
+    /**
+     * Retrieve a list of Unis on a specific DataStore
+     * @param dataBroker instance to create transactions
+     * @param store to which send the read request
+     * @return A List of Unis.
+     */
+    public static List<UniAugmentation> getUnis(DataBroker dataBroker,
+                                         LogicalDatastoreType store) {
+        List<UniAugmentation> unis = new ArrayList<>();
+        InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
+        Topology topology = read(dataBroker,
+                                 store,
+                                 topologyInstanceIdentifier);
+        if (topology != null && topology.getNode() != null) {
+            for (Node node : topology.getNode()) {
+                UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+                if (uniAugmentation != null) {
+                    unis.add(uniAugmentation);
+                }
+            }
+        }
+        return unis;
+    }
+
+    /**
+     * Retrieve a list of Unis on a specific DataStore
+     * @param dataBroker instance to create transactions
+     * @param store to which send the read request
+     * @param ipAddress of the required Uni
+     * @return uni.
+     */
+    public static UniAugmentation getUni(DataBroker dataBroker,
+                                         LogicalDatastoreType store, IpAddress ipAddress) {
+        InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
+        Topology topology = read(dataBroker,
+                                 store,
+                                 topologyInstanceIdentifier);
+        if (topology != null && topology.getNode() != null) {
+            for (Node node : topology.getNode()) {
+                UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+                if (uniAugmentation != null && uniAugmentation.getIpAddress().getIpv4Address().getValue().equals(ipAddress.getIpv4Address().getValue())) {
+                    return uniAugmentation;
+                }
+            }
+        }
+        return null;
+    }
+
     /**
      * Read a specific datastore type and return a DataObject as a casted
      * class type Object.