From: stevenvanrossem Date: Thu, 1 Jun 2017 13:15:59 +0000 (+0200) Subject: update son-emu-cli network CLI X-Git-Tag: v3.1~24^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=f693a3b7d6bc9190f180bbd23ae4c577143fe5a5;p=osm%2Fvim-emu.git update son-emu-cli network CLI --- diff --git a/README.md b/README.md index 3877e87..f9b8c28 100755 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ To install the emulator package in development mode, do: #### Run Unit Tests * `cd ~/son-emu` * `sudo py.test -v src/emuvim/test/unittests` +(To force using Python2: `python2 -m pytest -v src/emuvim/test/unittests`) ### Building diff --git a/src/emuvim/api/rest/network.py b/src/emuvim/api/rest/network.py index 84db87e..1374373 100755 --- a/src/emuvim/api/rest/network.py +++ b/src/emuvim/api/rest/network.py @@ -38,7 +38,7 @@ from flask import request import json import networkx -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.DEBUG) CORS_HEADER = {'Access-Control-Allow-Origin': '*'} @@ -83,8 +83,7 @@ class NetworkAction(Resource): # check if json data is a dict data = request.args # try json payload - if data is None: - data = request.json + data = request.json # then no data if data is None: data = {} diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index 10b6c26..b2a7b86 100755 --- a/src/emuvim/api/rest/rest_api_endpoint.py +++ b/src/emuvim/api/rest/rest_api_endpoint.py @@ -56,10 +56,13 @@ class RestApiEndpoint(object): default command line client. """ - def __init__(self, listenip, port): + def __init__(self, listenip, port, DCnetwork=None): self.ip = listenip self.port = port + # connect this DC network to the rest api endpoint (needed for the networking and monitoring api) + self.connectDCNetwork(DCnetwork) + # setup Flask # find directory of dashboard files dashboard_file = pkg_resources.resource_filename('emuvim.dashboard', "index.html") diff --git a/src/emuvim/cli/rest/compute.py b/src/emuvim/cli/rest/compute.py index 9e5e0ab..fdfc11b 100755 --- a/src/emuvim/cli/rest/compute.py +++ b/src/emuvim/cli/rest/compute.py @@ -110,7 +110,7 @@ class RestApiClient(): Popen(['xterm', '-xrm', 'XTerm.vt100.allowTitleOps: false', '-T', vnf_name, '-e', "docker exec -it mn.{0} /bin/bash".format(vnf_name)]) -parser = argparse.ArgumentParser(description="""son-emu compute +parser = argparse.ArgumentParser(description="""son-emu-cli compute Examples: - son-emu-cli compute start -d dc2 -n client -i sonatanfv/sonata-iperf3-vnf @@ -144,7 +144,7 @@ parser.add_argument( parser.add_argument( "--endpoint", "-e", dest="endpoint", default="http://127.0.0.1:5001", - help="UUID of the plugin to be manipulated.") + help="REST API endpoint of son-emu (default:http://127.0.0.1:5001)") def main(argv): diff --git a/src/emuvim/cli/rest/datacenter.py b/src/emuvim/cli/rest/datacenter.py index e8a41ce..651c55c 100755 --- a/src/emuvim/cli/rest/datacenter.py +++ b/src/emuvim/cli/rest/datacenter.py @@ -80,7 +80,7 @@ class RestApiClient(): print (tabulate(table, headers=headers, tablefmt="grid")) -parser = argparse.ArgumentParser(description='son-emu datacenter') +parser = argparse.ArgumentParser(description='son-emu-cli datacenter') parser.add_argument( "command", choices=['list', 'status'], @@ -91,7 +91,7 @@ parser.add_argument( parser.add_argument( "--endpoint", "-e", dest="endpoint", default="http://127.0.0.1:5001", - help="UUID of the plugin to be manipulated.") + help="REST API endpoint of son-emu (default:http://127.0.0.1:5001)") def main(argv): diff --git a/src/emuvim/cli/rest/monitor.py b/src/emuvim/cli/rest/monitor.py index 7af1fbb..8be1e7f 100755 --- a/src/emuvim/cli/rest/monitor.py +++ b/src/emuvim/cli/rest/monitor.py @@ -46,52 +46,47 @@ class RestApiClient(): print("Command not implemented.") def setup_metric(self, args): - vnf_name = self._parse_vnf_name(args.get("vnf_name")) - vnf_interface = self._parse_vnf_interface(args.get("vnf_name")) - response = put("%s/restapi/monitor/interface/%s/%s/%s" % - (args.get("endpoint"), - vnf_name, - vnf_interface, - args.get("metric"))) - pp.pprint(response.json()) + params = self._create_dict( + vnf_name=self._parse_vnf_name(args.get("vnf_name")), + vnf_interface = self._parse_vnf_interface(args.get("vnf_name")), + metric = args.get("metric")) + + url = "{0}/restapi/monitor/interface".format(args.get("endpoint")) + response = put(url, params=params) + pp.pprint(response.text) def stop_metric(self, args): - vnf_name = self._parse_vnf_name(args.get("vnf_name")) - vnf_interface = self._parse_vnf_interface(args.get("vnf_name")) + params = self._create_dict( + vnf_name=self._parse_vnf_name(args.get("vnf_name")), + vnf_interface=self._parse_vnf_interface(args.get("vnf_name")), + metric=args.get("metric")) - response = delete("%s/restapi/monitor/interface/%s/%s/%s" % - (args.get("endpoint"), - vnf_name, - vnf_interface, - args.get("metric"))) - pp.pprint(response.json()) + url = "{0}/restapi/monitor/interface".format(args.get("endpoint")) + response = put(url, params=params) + pp.pprint(response.text) def setup_flow(self, args): - vnf_name = self._parse_vnf_name(args.get("vnf_name")) - vnf_interface = self._parse_vnf_interface(args.get("vnf_name")) + params = self._create_dict( + vnf_name=self._parse_vnf_name(args.get("vnf_name")), + vnf_interface=self._parse_vnf_interface(args.get("vnf_name")), + metric=args.get("metric"), + cookie=args.get("cookie")) - response = put("%s/restapi/monitor/flow/%s/%s/%s/%s" % - (args.get("endpoint"), - vnf_name, - vnf_interface, - args.get("metric"), - args.get("cookie"))) - - pp.pprint(response.json()) + url = "{0}/restapi/monitor/flow".format(args.get("endpoint")) + response = put(url, params=params) + pp.pprint(response.text) def stop_flow(self, args): - vnf_name = self._parse_vnf_name(args.get("vnf_name")) - vnf_interface = self._parse_vnf_interface(args.get("vnf_name")) + params = self._create_dict( + vnf_name=self._parse_vnf_name(args.get("vnf_name")), + vnf_interface=self._parse_vnf_interface(args.get("vnf_name")), + metric=args.get("metric"), + cookie=args.get("cookie")) - response = delete("%s/restapi/monitor/flow/%s/%s/%s/%s" % - (args.get("endpoint"), - vnf_name, - vnf_interface, - args.get("metric"), - args.get("cookie"))) - - pp.pprint(response.json()) + url = "{0}/restapi/monitor/flow".format(args.get("endpoint")) + response = put(url, params=params) + pp.pprint(response.text) def prometheus(self, args): # This functions makes it more user-friendly to create the correct prometheus query @@ -100,6 +95,7 @@ class RestApiClient(): vnf_interface = self._parse_vnf_interface(args.get("vnf_name")) dc_label = args.get("datacenter") query = args.get("query") + vnf_status = get("%s/restapi/compute/%s/%s" % (args.get("endpoint"), args.get("datacenter"), @@ -122,7 +118,10 @@ class RestApiClient(): return vnf_interface -parser = argparse.ArgumentParser(description='son-emu monitor') + def _create_dict(self, **kwargs): + return kwargs + +parser = argparse.ArgumentParser(description='son-emu-cli monitor') parser.add_argument( "command", choices=['setup_metric', 'stop_metric', 'setup_flow', 'stop_flow','prometheus'], @@ -145,7 +144,7 @@ parser.add_argument( parser.add_argument( "--endpoint", "-e", dest="endpoint", default="http://127.0.0.1:5001", - help="UUID of the plugin to be manipulated.") + help="REST API endpoint of son-emu (default:http://127.0.0.1:5001)") def main(argv): args = vars(parser.parse_args(argv)) diff --git a/src/emuvim/cli/rest/network.py b/src/emuvim/cli/rest/network.py index 91051dd..44cba60 100755 --- a/src/emuvim/cli/rest/network.py +++ b/src/emuvim/cli/rest/network.py @@ -44,10 +44,9 @@ class RestApiClient(): print("Command not implemented.") def add(self, args): - vnf_src_name = self._parse_vnf_name(args.get("source")) - vnf_dst_name = self._parse_vnf_name(args.get("destination")) - params = self._create_dict( + vnf_src_name=self._parse_vnf_name(args.get("source")), + vnf_dst_name = self._parse_vnf_name(args.get("destination")), vnf_src_interface=self._parse_vnf_interface(args.get("source")), vnf_dst_interface=self._parse_vnf_interface(args.get("destination")), weight=args.get("weight"), @@ -56,18 +55,14 @@ class RestApiClient(): cookie=args.get("cookie"), priority=args.get("priority")) - response = put("%s/restapi/network/%s/%s" % - (args.get("endpoint"), - vnf_src_name, - vnf_dst_name), - json=params) - pp.pprint(response.json()) + response = put("{0}/restapi/network".format(args.get("endpoint")), + params=params) + pp.pprint(response.text) def remove(self, args): - vnf_src_name = self._parse_vnf_name(args.get("source")) - vnf_dst_name = self._parse_vnf_name(args.get("destination")) - params = self._create_dict( + vnf_src_name = self._parse_vnf_name(args.get("source")), + vnf_dst_name = self._parse_vnf_name(args.get("destination")), vnf_src_interface=self._parse_vnf_interface(args.get("source")), vnf_dst_interface=self._parse_vnf_interface(args.get("destination")), weight=args.get("weight"), @@ -76,12 +71,9 @@ class RestApiClient(): cookie=args.get("cookie"), priority=args.get("priority")) - response = delete("%s/restapi/network/%s/%s" % - (args.get("endpoint"), - vnf_src_name, - vnf_dst_name), - json=params) - pp.pprint(response.json()) + response = delete("{0}/restapi/network".format(args.get("endpoint")), + params=params) + pp.pprint(response.text) def _parse_vnf_name(self, vnf_name_str): vnf_name = vnf_name_str.split(':')[0] @@ -98,7 +90,7 @@ class RestApiClient(): def _create_dict(self, **kwargs): return kwargs -parser = argparse.ArgumentParser(description='son-emu network') +parser = argparse.ArgumentParser(description='son-emu-cli network') parser.add_argument( "command", choices=['add', 'remove'], @@ -130,7 +122,7 @@ parser.add_argument( parser.add_argument( "--endpoint", "-e", dest="endpoint", default="http://127.0.0.1:5001", - help="UUID of the plugin to be manipulated.") + help="REST API endpoint of son-emu (default:http://127.0.0.1:5001)") def main(argv): args = vars(parser.parse_args(argv)) diff --git a/src/emuvim/examples/simple_topology.py b/src/emuvim/examples/simple_topology.py index d63a07c..b43ad78 100755 --- a/src/emuvim/examples/simple_topology.py +++ b/src/emuvim/examples/simple_topology.py @@ -93,7 +93,7 @@ def create_topology1(): this API, e.g., start/stop/list compute instances. """ # create a new instance of a endpoint implementation - rapi1 = RestApiEndpoint("127.0.0.1", 5001) + rapi1 = RestApiEndpoint("127.0.0.1", 5001, net) # connect data centers to this endpoint rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2)