From: stevenvanrossem Date: Wed, 4 May 2016 10:36:57 +0000 (+0200) Subject: fix network definition when starting container X-Git-Tag: v3.1~133^2~3 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fvim-emu.git;a=commitdiff_plain;h=994245bc4fb59f4c5129a5cb977af1871f08ce13 fix network definition when starting container --- diff --git a/src/emuvim/api/zerorpc/compute.py b/src/emuvim/api/zerorpc/compute.py index 7b6c1d4..38b0a06 100644 --- a/src/emuvim/api/zerorpc/compute.py +++ b/src/emuvim/api/zerorpc/compute.py @@ -56,9 +56,9 @@ class MultiDatacenterApi(object): def __init__(self, dcs): self.dcs = dcs - def compute_action_start(self, dc_label, compute_name, image, network=None, command=None): + def compute_action_start(self, dc_label, compute_name, image, network, command): """ - Start a new compute instance: A docker container + Start a new compute instance: A docker container (note: zerorpc does not support keyword arguments) :param dc_label: name of the DC :param compute_name: compute container name :param image: image name @@ -68,6 +68,7 @@ class MultiDatacenterApi(object): """ # TODO what to return UUID / given name / internal name ? logging.debug("RPC CALL: compute start") + logging.info('nwlist2: {0}'.format(network)) try: c = self.dcs.get(dc_label).startCompute( compute_name, image=image, command=command, network=network) @@ -113,6 +114,21 @@ class MultiDatacenterApi(object): logging.exception("RPC error.") return ex.message + def compute_profile(self, dc_label, compute_name, image, kwargs): + # note: zerorpc does not support keyword arguments + + # start vnf + vnf_status = self.compute_action_start(self, dc_label, compute_name, image, + kwargs.get('network'), + kwargs.get('command')) + + # start traffic source (with fixed ip addres, no use for now...) + self.compute_action_start(self, dc_label, 'psrc', 'profile_source', [{'id':'output','ip':'10.0.10.1/24'}], None) + + + + + def datacenter_list(self): logging.debug("RPC CALL: datacenter list") try: @@ -128,3 +144,10 @@ class MultiDatacenterApi(object): except Exception as ex: logging.exception("RPC error.") return ex.message + +''' +if __name__ == "__main__": + test = MultiDatacenterApi({}) + test.compute_profile('dc1','vnf1', 'image',network='',command='test',other='other') +''' + diff --git a/src/emuvim/api/zerorpc/network.py b/src/emuvim/api/zerorpc/network.py index 116d13b..b1e5d41 100644 --- a/src/emuvim/api/zerorpc/network.py +++ b/src/emuvim/api/zerorpc/network.py @@ -117,3 +117,5 @@ class DCNetworkApi(object): logging.exception("RPC error.") return ex.message + + diff --git a/src/emuvim/cli/compute.py b/src/emuvim/cli/compute.py index f2fdc62..6423917 100755 --- a/src/emuvim/cli/compute.py +++ b/src/emuvim/cli/compute.py @@ -31,12 +31,14 @@ class ZeroRpcClient(object): if args.get("network") is not None: nw_list = self._parse_network(args.get("network")) + pp.pprint('nwlist1: {0}'.format(nw_list)) + r = self.c.compute_action_start( args.get("datacenter"), args.get("name"), args.get("image"), - network=nw_list, - command=args.get("docker_command") + nw_list, + args.get("docker_command") ) pp.pprint(r) @@ -79,6 +81,22 @@ class ZeroRpcClient(object): args.get("datacenter"), args.get("name")) pp.pprint(r) + def profile(self, args): + nw_list = list() + if args.get("network") is not None: + nw_list = self._parse_network(args.get("network")) + logging.info('nwlist: {0}'.format(nw_list)) + r = self.c.compute_profile( + args.get("datacenter"), + args.get("name"), + args.get("image"), + network=nw_list, + command=args.get("docker_command"), + input=args.get("input"), + output=args.get("output") + ) + pp.pprint(r) + def _parse_network(self, network_str): ''' parse the options for all network interfaces of the vnf @@ -116,6 +134,12 @@ 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.") +parser.add_argument( + "--input", "-in", dest="input", + help="input interface of the vnf to profile") +parser.add_argument( + "--output", "-out", dest="output", + help="output interface of the vnf to profile") def main(argv): diff --git a/src/emuvim/cli/monitor.py b/src/emuvim/cli/monitor.py index 14cce08..3b667f7 100755 --- a/src/emuvim/cli/monitor.py +++ b/src/emuvim/cli/monitor.py @@ -69,6 +69,7 @@ parser.add_argument( "--metric", "-m", dest="metric", help="tx_bytes, rx_bytes, tx_packets, rx_packets") + def main(argv): #print "This is the son-emu monitor CLI." #print "Arguments: %s" % str(argv) diff --git a/src/emuvim/dcemulator/node.py b/src/emuvim/dcemulator/node.py index 41da627..2943b6d 100755 --- a/src/emuvim/dcemulator/node.py +++ b/src/emuvim/dcemulator/node.py @@ -167,8 +167,10 @@ class Datacenter(object): # 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 + logging.info('nwlist: {0}'.format(network)) for nw in network: # TODO we cannot use TCLink here (see: https://github.com/mpeuster/dockernet/issues/3) + logging.info('nw: {0}'.format(nw)) self.net.addLink(d, self.switch, params1=nw, cls=Link) # do bookkeeping self.containers[name] = d