Merge pull request #133 from mpeuster/master
[osm/vim-emu.git] / src / emuvim / cli / network.py
index 5b0aa51..960e387 100755 (executable)
@@ -1,6 +1,29 @@
 """\r
-son-emu network CLI\r
-(c) 2016 by Manuel Peuster <manuel.peuster@upb.de>\r
+Copyright (c) 2015 SONATA-NFV\r
+ALL RIGHTS RESERVED.\r
+\r
+Licensed under the Apache License, Version 2.0 (the "License");\r
+you may not use this file except in compliance with the License.\r
+You may obtain a copy of the License at\r
+\r
+    http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+Unless required by applicable law or agreed to in writing, software\r
+distributed under the License is distributed on an "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+See the License for the specific language governing permissions and\r
+limitations under the License.\r
+\r
+Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]\r
+nor the names of its contributors may be used to endorse or promote\r
+products derived from this software without specific prior written\r
+permission.\r
+\r
+This work has been performed in the framework of the SONATA project,\r
+funded by the European Commission under Grant number 671517 through\r
+the Horizon 2020 and 5G-PPP programmes. The authors would like to\r
+acknowledge the contributions of their colleagues of the SONATA\r
+partner consortium (www.sonata-nfv.eu).\r
 """\r
 \r
 import argparse\r
@@ -25,36 +48,45 @@ class ZeroRpcClient(object):
             # call the local method with the same name as the command arg\r
             getattr(self, args["command"])(args)\r
         else:\r
-            print "Command not implemented."\r
+            print("Command not implemented.")\r
 \r
     def add(self, args):\r
         vnf_src_name = self._parse_vnf_name(args.get("source"))\r
-        vnf_src_interface = self._parse_vnf_interface(args.get("source"))\r
         vnf_dst_name = self._parse_vnf_name(args.get("destination"))\r
-        vnf_dst_interface = self._parse_vnf_interface(args.get("destination"))\r
-        weight = args.get("weight")\r
+\r
+        params = self._create_dict(\r
+            vnf_src_interface=self._parse_vnf_interface(args.get("source")),\r
+            vnf_dst_interface=self._parse_vnf_interface(args.get("destination")),\r
+            weight=args.get("weight"),\r
+            match=args.get("match"),\r
+            bidirectional=args.get("bidirectional"),\r
+            cookie=args.get("cookie"))\r
+\r
+        # note zerorpc does not support named arguments\r
         r = self.c.network_action_start(\r
             #args.get("datacenter"),\r
             vnf_src_name,\r
             vnf_dst_name,\r
-            vnf_src_interface,\r
-            vnf_dst_interface,\r
-            weight=weight)\r
+            params)\r
         pp.pprint(r)\r
 \r
     def remove(self, args):\r
         vnf_src_name = self._parse_vnf_name(args.get("source"))\r
-        vnf_src_interface = self._parse_vnf_interface(args.get("source"))\r
         vnf_dst_name = self._parse_vnf_name(args.get("destination"))\r
-        vnf_dst_interface = self._parse_vnf_interface(args.get("destination"))\r
-        weight = args.get("weight")\r
+\r
+        params = self._create_dict(\r
+            vnf_src_interface=self._parse_vnf_interface(args.get("source")),\r
+            vnf_dst_interface=self._parse_vnf_interface(args.get("destination")),\r
+            weight=args.get("weight"),\r
+            match=args.get("match"),\r
+            bidirectional=args.get("bidirectional"),\r
+            cookie=args.get("cookie"))\r
+\r
         r = self.c.network_action_stop(\r
             #args.get("datacenter"),\r
             vnf_src_name,\r
             vnf_dst_name,\r
-            vnf_src_interface,\r
-            vnf_dst_interface,\r
-            weight=weight)\r
+            params)\r
         pp.pprint(r)\r
 \r
     def _parse_vnf_name(self, vnf_name_str):\r
@@ -69,11 +101,14 @@ class ZeroRpcClient(object):
 \r
         return vnf_interface\r
 \r
+    def _create_dict(self, **kwargs):\r
+        return kwargs\r
 \r
 parser = argparse.ArgumentParser(description='son-emu network')\r
 parser.add_argument(\r
     "command",\r
-    help="Action to be executed: add|remove")\r
+    choices=['add', 'remove'],\r
+    help="Action to be executed.")\r
 parser.add_argument(\r
     "--datacenter", "-d", dest="datacenter",\r
     help="Data center to in which the network action should be initiated")\r
@@ -86,6 +121,16 @@ parser.add_argument(
 parser.add_argument(\r
     "--weight", "-w", dest="weight",\r
     help="weight metric to calculate the path")\r
+parser.add_argument(\r
+    "--match", "-m", dest="match",\r
+    help="string holding extra matches for the flow entries")\r
+parser.add_argument(\r
+    "--bidirectional", "-b", dest="bidirectional",\r
+    action='store_true',\r
+    help="add/remove the flow entries from src to dst and back")\r
+parser.add_argument(\r
+    "--cookie", "-c", dest="cookie",\r
+    help="cookie for this flow, as easy to use identifier (eg. per tenant/service)")\r
 \r
 def main(argv):\r
     args = vars(parser.parse_args(argv))\r