Extended network API to support multiple interfaces in a single Docker container...
authorpeusterm <manuel.peuster@uni-paderborn.de>
Sun, 28 Feb 2016 17:38:10 +0000 (18:38 +0100)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Sun, 28 Feb 2016 17:38:10 +0000 (18:38 +0100)
emuvim/api/zerorpcapi.py
emuvim/cli/compute.py
emuvim/dcemulator/node.py

index fd814b3..59b960c 100755 (executable)
@@ -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:
index 15fea91..70de20a 100755 (executable)
@@ -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):
index 13007eb..336126c 100755 (executable)
@@ -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