Merge remote-tracking branch 'upstream/master'
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 20 May 2016 07:40:22 +0000 (09:40 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 20 May 2016 07:40:22 +0000 (09:40 +0200)
setup.py
src/emuvim/api/zerorpc/compute.py
src/emuvim/cli/compute.py
src/emuvim/cli/datacenter.py
src/emuvim/cli/monitor.py
src/emuvim/cli/network.py
src/emuvim/cli/prometheus.py
src/emuvim/cli/son_emu_cli.py
utils/ci/test_sdk_monitor.sh

index 3657816..b8af834 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,8 @@ setup(name='emuvim',
           'requests',
           'prometheus_client',
           'paramiko',
-          'urllib3'
+          'urllib3',
+          'requests'
       ],
       zip_safe=False,
       entry_points={
index 63786fa..a08c118 100755 (executable)
@@ -119,12 +119,13 @@ class MultiDatacenterApi(object):
             return ex.message
 
     @zerorpc.stream
-    def compute_profile(self, dc_label, compute_name, image, kwargs):
+    def compute_profile(self, dc_label, compute_name, kwargs):
         # note: zerorpc does not support keyword arguments
 
         ## VIM/dummy gatekeeper's tasks:
         # start vnf
-        vnf_status = self.compute_action_start( dc_label, compute_name, image,
+        vnf_status = self.compute_action_start( dc_label, compute_name,
+                                  kwargs.get('image'),
                                   kwargs.get('network'),
                                   kwargs.get('command'))
         # start traffic source (with fixed ip addres, no use for now...)
index 433826e..4869a17 100755 (executable)
@@ -24,7 +24,7 @@ class ZeroRpcClient(object):
             # call the local method with the same name as the command arg
             getattr(self, args["command"])(args)
         else:
-            print "Command not implemented."
+            print("Command not implemented.")
 
     def start(self, args):
         nw_list = list()
@@ -71,7 +71,7 @@ class ZeroRpcClient(object):
                    "eth0 IP",
                    "eth0 status",
                    "Status"]
-        print tabulate(table, headers=headers, tablefmt="grid")
+        print(tabulate(table, headers=headers, tablefmt="grid"))
 
     def status(self, args):
         r = self.c.compute_status(
@@ -86,15 +86,14 @@ class ZeroRpcClient(object):
         params = self._create_dict(
             network=nw_list,
             command=args.get("docker_command"),
+            image=args.get("image"),
             input=args.get("input"),
             output=args.get("output"))
 
         for output in self.c.compute_profile(
             args.get("datacenter"),
             args.get("name"),
-            args.get("image"),
-            params
-            ):
+            params):
             print(output + '\n')
 
         #pp.pprint(r)
@@ -138,8 +137,8 @@ parser.add_argument(
     help="Startup command of the container e.g. './start.sh'")
 parser.add_argument(
     "--net", dest="network",
-    help="Network properties of compute instance e.g. \
-          '10.0.0.123/8' or '10.0.0.123/8,11.0.0.123/24' for multiple interfaces.")
+    help="Network properties of compute instance e.g. \
+          '(id=input,ip=10.0.10.3/24),(id=output,ip=10.0.10.4/24)' for multiple interfaces.")
 parser.add_argument(
     "--input", "-in", dest="input",
     help="input interface of the vnf to profile")
index c3850fc..cbe4d0b 100755 (executable)
@@ -24,7 +24,7 @@ class ZeroRpcClient(object):
             # call the local method with the same name as the command arg
             getattr(self, args["command"])(args)
         else:
-            print "Command not implemented."
+            print("Command not implemented.")
 
     def list(self, args):
         r = self.c.datacenter_list()
@@ -42,7 +42,7 @@ class ZeroRpcClient(object):
                    "Switch",
                    "# Containers",
                    "# Metadata Items"]
-        print tabulate(table, headers=headers, tablefmt="grid")
+        print(tabulate(table, headers=headers, tablefmt="grid"))
 
     def status(self, args):
         r = self.c.datacenter_status(
index 79ff25b..20bfc25 100755 (executable)
@@ -1,12 +1,13 @@
 """\r
 son-emu monitor CLI\r
 (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>\r
+Steven Van Rossem <steven.vanrossem@intec.ugent.be>\r
 """\r
 \r
 import argparse\r
 import pprint\r
 import zerorpc\r
-import prometheus\r
+from emuvim.cli import prometheus\r
 \r
 pp = pprint.PrettyPrinter(indent=4)\r
 \r
@@ -30,7 +31,7 @@ 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 setup_metric(self, args):\r
         vnf_name = self._parse_vnf_name(args.get("vnf_name"))\r
index 516a752..48ff33a 100755 (executable)
@@ -1,6 +1,7 @@
 """\r
 son-emu network CLI\r
 (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>\r
+Steven Van Rossem <steven.vanrossem@intec.ugent.be>\r
 """\r
 \r
 import argparse\r
@@ -25,7 +26,7 @@ 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
index 26f18bf..9432408 100755 (executable)
@@ -3,8 +3,9 @@ Prometheus API helper functions
 (c) 2016 by Steven Van Rossem <steven.vanrossem@intec.ugent.be>
 """
 
-import urllib2
-import ast
+#import urllib2
+import requests
+#import ast
 
 # set this to localhost for now
 # this is correct for son-emu started outside of a container or as a container with net=host
@@ -16,9 +17,11 @@ prometheus_REST_api = 'http://{0}:{1}'.format(prometheus_ip, prometheus_port)
 def query_Prometheus(query):
     url = prometheus_REST_api + '/' + 'api/v1/query?query=' + query
     # logging.info('query:{0}'.format(url))
-    req = urllib2.Request(url)
-    ret = urllib2.urlopen(req).read()
-    ret = ast.literal_eval(ret)
+    #req = urllib2.Request(url)
+    req = requests.get(url)
+    #ret = urllib2.urlopen(req).read()
+    #ret = ast.literal_eval(ret)
+    ret = req.json()
     if ret['status'] == 'success':
         # logging.info('return:{0}'.format(ret))
         try:
index 195fe06..842d0a1 100755 (executable)
@@ -20,7 +20,7 @@ from emuvim.cli import monitor
 
 def main():
     if len(sys.argv) < 2:
-        print "Usage: son-emu-cli <toolname> <arguments>"
+        print("Usage: son-emu-cli <toolname> <arguments>")
         exit(0)
     if sys.argv[1] == "compute":
         compute.main(sys.argv[2:])
index afd4b8c..51e5e7a 100755 (executable)
@@ -29,6 +29,9 @@ son-emu-cli compute stop -d datacenter1 -n vnf1
 
 # test if prometheus query worked
 echo $cpu_load
+
+regex='\[[0-9.]*, .*\]'
+
 if [[ $cpu_load =~ $regex ]] ; then
        echo " cpu monitor test OK"
        exit 0
@@ -36,3 +39,5 @@ else
        echo "cpu monitor test not OK"
        exit 1
 fi
+
+