From 14c89055e7a3951898feb2d70e68448ce31114a1 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Sun, 10 Apr 2016 23:49:59 +0200 Subject: [PATCH] extend --net options for compute start --- src/emuvim/api/zerorpc/compute.py | 4 ++-- src/emuvim/cli/compute.py | 20 +++++++++++++++++--- src/emuvim/dcemulator/node.py | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/emuvim/api/zerorpc/compute.py b/src/emuvim/api/zerorpc/compute.py index 59b960c..6e4a083 100644 --- a/src/emuvim/api/zerorpc/compute.py +++ b/src/emuvim/api/zerorpc/compute.py @@ -63,8 +63,8 @@ class MultiDatacenterApi(object): :param compute_name: compute container name :param image: image name :param command: command to execute - :param network: - :return: networks list({"ip": "10.0.0.254/8"}, {"ip": "11.0.0.254/24"}) + :param network: list of all interface of the vnf, with their parameters (id=id1,ip=x.x.x.x/x),... + :return: networks list({"id":"input","ip": "10.0.0.254/8"}, {"id":"output","ip": "11.0.0.254/24"}) """ # TODO what to return UUID / given name / internal name ? logging.debug("RPC CALL: compute start") diff --git a/src/emuvim/cli/compute.py b/src/emuvim/cli/compute.py index 70de20a..006b57b 100755 --- a/src/emuvim/cli/compute.py +++ b/src/emuvim/cli/compute.py @@ -29,9 +29,8 @@ class ZeroRpcClient(object): def start(self, args): nw_list = list() if args.get("network") is not None: - networks = args.get("network").split(",") - for nw in networks: - nw_list.append({"ip": nw}) + nw_list = self._parse_network(args.get("network")) + r = self.c.compute_action_start( args.get("datacenter"), args.get("name"), @@ -79,6 +78,21 @@ class ZeroRpcClient(object): args.get("datacenter"), args.get("name")) pp.pprint(r) + def _parse_network(self, network_str): + ''' + parse the options for all network interfaces of the vnf + :param network_str: (id=x,ip=x.x.x.x/x), ... + :return: list of dicts [{"id":x,"ip":"x.x.x.x/x"}, ...] + ''' + nw_list = list() + networks = network_str[1:-1].split('),(') + for nw in networks: + nw_dict = dict(tuple(e.split('=')) for e in nw.split(',')) + nw_list.append(nw_dict) + + return nw_list + + parser = argparse.ArgumentParser(description='son-emu compute') parser.add_argument( diff --git a/src/emuvim/dcemulator/node.py b/src/emuvim/dcemulator/node.py index 3f76df9..7590973 100755 --- a/src/emuvim/dcemulator/node.py +++ b/src/emuvim/dcemulator/node.py @@ -182,6 +182,8 @@ class Datacenter(object): memswap_limit="%dm" % int(mem_limit) if mem_limit > 0 else None # lets set swap to mem limit for now ) # connect all given networks + # if no --net option is given, network = [{}], so 1 empty dict in the list + # this results in 1 default interface with a default ip address for nw in network: # TODO we cannot use TCLink here (see: https://github.com/mpeuster/dockernet/issues/3) self.net.addLink(d, self.switch, params1=nw, cls=Link) -- 2.25.1