From: peusterm Date: Sun, 28 Feb 2016 17:38:10 +0000 (+0100) Subject: Extended network API to support multiple interfaces in a single Docker container... X-Git-Tag: v3.1~173^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=7f8e8408ef6f118e55e9066c02c70689501b3d2b;p=osm%2Fvim-emu.git Extended network API to support multiple interfaces in a single Docker container. Closes #11. --- diff --git a/emuvim/api/zerorpcapi.py b/emuvim/api/zerorpcapi.py index fd814b3..59b960c 100755 --- a/emuvim/api/zerorpcapi.py +++ b/emuvim/api/zerorpcapi.py @@ -57,7 +57,15 @@ class MultiDatacenterApi(object): self.dcs = dcs def compute_action_start(self, dc_label, compute_name, image, command, network): - # network e.g. {"ip": "10.0.0.254/8"} + """ + Start a new compute instance: A docker container + :param dc_label: name of the DC + :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"}) + """ # TODO what to return UUID / given name / internal name ? logging.debug("RPC CALL: compute start") try: diff --git a/emuvim/cli/compute.py b/emuvim/cli/compute.py index 15fea91..70de20a 100755 --- a/emuvim/cli/compute.py +++ b/emuvim/cli/compute.py @@ -27,15 +27,17 @@ class ZeroRpcClient(object): print "Command not implemented." def start(self, args): - network = {} + nw_list = list() if args.get("network") is not None: - network = {"ip": args.get("network")} + networks = args.get("network").split(",") + for nw in networks: + nw_list.append({"ip": nw}) r = self.c.compute_action_start( args.get("datacenter"), args.get("name"), args.get("image"), args.get("docker_command"), - network) + nw_list) pp.pprint(r) def stop(self, args): @@ -97,7 +99,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'") + 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.") def main(argv): diff --git a/emuvim/dcemulator/node.py b/emuvim/dcemulator/node.py index 13007eb..336126c 100755 --- a/emuvim/dcemulator/node.py +++ b/emuvim/dcemulator/node.py @@ -99,13 +99,15 @@ class Datacenter(object): def start(self): pass - def startCompute(self, name, image=None, command=None,network=None): + def startCompute(self, name, image=None, command=None, network=None): """ Create a new container as compute resource and connect it to this data center. - - TODO: This interface will change to support multiple networks to which - a single container can be connected. + :param name: name (string) + :param image: image name (string) + :param command: command (string) + :param network: networks list({"ip": "10.0.0.254/8"}, {"ip": "11.0.0.254/24"}) + :return: """ assert name is not None # no duplications @@ -116,9 +118,17 @@ class Datacenter(object): image = "ubuntu" if network is None: network = {} # {"ip": "10.0.0.254/8"} - # create the container and connect it to the given network + if isinstance(network, dict): + network = [network] # if we have only one network, put it in a list + if isinstance(network, list): + if len(network) < 1: + network.append({}) + + # create the container d = self.net.addDocker("%s" % (name), dimage=image, dcmd=command) - self.net.addLink(d, self.switch, params1=network) + # connect all given networks + for nw in network: + self.net.addLink(d, self.switch, params1=nw) # do bookkeeping self.containers[name] = d d.datacenter = self