#### 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
import json
import networkx
-logging.basicConfig(level=logging.INFO)
+logging.basicConfig(level=logging.DEBUG)
CORS_HEADER = {'Access-Control-Allow-Origin': '*'}
# 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 = {}
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")
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
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):
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'],
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):
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
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"),
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'],
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))
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"),
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"),
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]
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'],
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))
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)