minor cleanup, add stop_flow
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Thu, 12 May 2016 12:34:12 +0000 (14:34 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Thu, 12 May 2016 12:34:12 +0000 (14:34 +0200)
src/emuvim/api/zerorpc/network.py
src/emuvim/cli/monitor.py
src/emuvim/dcemulator/net.py

index 37b34f9..5fccf4e 100755 (executable)
@@ -134,6 +134,16 @@ class DCNetworkApi(object):
             logging.exception("RPC error.")
             return ex.message
 
+    # remove the flow metrics measurement
+    def setup_flow(self, vnf_name, vnf_interface, metric, cookie):
+        logging.debug("RPC CALL: stop flow")
+        try:
+            c = self.net.monitor_agent.setup_flow(vnf_name, vnf_interface, metric, cookie)
+            return c
+        except Exception as ex:
+            logging.exception("RPC error.")
+            return ex.message
+
     # do prometheus query
     def prometheus(self, dc_label, vnf_name, vnf_interface, query):
         logging.debug("RPC CALL: query prometheus")
index 123abe5..1f2cc36 100755 (executable)
@@ -56,6 +56,16 @@ class ZeroRpcClient(object):
             args.get("cookie"))\r
         pp.pprint(r)\r
 \r
+    def stop_flow(self, args):\r
+        vnf_name = self._parse_vnf_name(args.get("vnf_name"))\r
+        vnf_interface = self._parse_vnf_interface(args.get("vnf_name"))\r
+        r = self.c.stop_flow(\r
+            vnf_name,\r
+            vnf_interface,\r
+            args.get("metric"),\r
+            args.get("cookie"))\r
+        pp.pprint(r)\r
+\r
     def prometheus(self, args):\r
         vnf_name = self._parse_vnf_name(args.get("vnf_name"))\r
         vnf_interface = self._parse_vnf_interface(args.get("vnf_name"))\r
@@ -82,7 +92,8 @@ class ZeroRpcClient(object):
 parser = argparse.ArgumentParser(description='son-emu monitor')\r
 parser.add_argument(\r
     "command",\r
-    help="Action to be executed")\r
+    choices=['setup_metric', 'stop_metric', 'setup_flow', 'stop_flow','prometheus'],\r
+    help="setup/stop a metric/flow to be monitored")\r
 parser.add_argument(\r
     "--vnf_name", "-vnf", dest="vnf_name",\r
     help="vnf name:interface to be monitored")\r
index f5bab44..c29c786 100755 (executable)
@@ -236,15 +236,17 @@ class DCNetwork(Containernet):
         if cmd == 'add-flow':
             ret = self._chainAddFlow(vnf_src_name, vnf_dst_name, vnf_src_interface, vnf_dst_interface, **kwargs)
             if kwargs.get('bidirectional'):
-                return ret +'\n' + self._chainAddFlow(vnf_dst_name, vnf_src_name, vnf_dst_interface, vnf_src_interface, **kwargs)
+                ret = ret +'\n' + self._chainAddFlow(vnf_dst_name, vnf_src_name, vnf_dst_interface, vnf_src_interface, **kwargs)
 
         elif cmd == 'del-flows':  # TODO: del-flow to be implemented
             ret = self._chainAddFlow(vnf_src_name, vnf_dst_name, vnf_src_interface, vnf_dst_interface, **kwargs)
             if kwargs.get('bidirectional'):
-                return ret + '\n' + self._chainAddFlow(vnf_dst_name, vnf_src_name, vnf_dst_interface, vnf_src_interface, **kwargs)
+                ret = ret + '\n' + self._chainAddFlow(vnf_dst_name, vnf_src_name, vnf_dst_interface, vnf_src_interface, **kwargs)
 
         else:
-            return "Command unknown"
+            ret = "Command unknown"
+
+        return ret
 
 
     def _chainAddFlow(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None, **kwargs):