populated compute API
authorpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 12 Jan 2016 13:08:07 +0000 (14:08 +0100)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 12 Jan 2016 13:08:07 +0000 (14:08 +0100)
emuvim/api/zerorpcapi.py
emuvim/cli/__main__.py
emuvim/dcemulator/node.py

index 71505a5..e00ecb9 100644 (file)
@@ -57,15 +57,21 @@ class MultiDatacenterApi(object):
         self.dcs = dcs
 
     def compute_action_start(self, dc_name, compute_name):
-        # TODO what to return UUID / IP ?
+        # TODO what to return UUID / given name / internal name ?
         logging.debug("RPC CALL: compute start")
         if dc_name in self.dcs:
-            self.dcs[dc_name].addCompute(compute_name)
+            return self.dcs[dc_name].addCompute(compute_name)
 
     def compute_action_stop(self, dc_name, compute_name):
-        logging.info("compute stop")
+        logging.info("RPC CALL: compute stop")
         if dc_name in self.dcs:
-            self.dcs[dc_name].removeCompute(compute_name)
+            return self.dcs[dc_name].removeCompute(compute_name)
 
-    def compute_list(self):
-        pass
+    def compute_list(self, dc_name):
+        logging.info("RPC CALL: compute list")
+        if dc_name in self.dcs:
+            return [(c.name, c.IP()) for c in self.dcs[dc_name].listCompute()]
+
+    def compute_status(self, dc_name, compute_name):
+        logging.info("RPC CALL: compute status")
+        # TODO implement
index 1957082..82930dc 100644 (file)
@@ -21,7 +21,14 @@ def main():
     print c.compute_action_start("dc2", "d1")
     print c.compute_action_start("dc2", "d2")
 
-    time.sleep(20)
+    time.sleep(1)
+    print c.compute_list("dc2")
+
+    time.sleep(1)
+    print c.compute_status("dc2", "d1")
+    print c.compute_status("dc2", "d2")
+
+    time.sleep(5)
 
     print c.compute_action_stop("dc2", "d1")
     print c.compute_action_stop("dc2", "d2")
index 67ce600..3ab6341 100644 (file)
@@ -42,15 +42,25 @@ class Datacenter(object):
     def start(self):
         pass
 
-    def addCompute(self, name):
+    def addCompute(self, name, image=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.
         """
-        # TODO ip management
-        d = self.net.addDocker("%s" % (name), dimage="ubuntu")
-        self.net.addLink(d, self.switch) #params1={"ip": "10.0.0.254/8"}
+        assert name is not None
+        # set default parameter
+        if image is None:
+            image = "ubuntu"
+        if network is None:
+            network = {}  # {"ip": "10.0.0.254/8"}
+        # create the container and connect it to the given network
+        d = self.net.addDocker("%s" % (name), dimage=image)
+        self.net.addLink(d, self.switch, params1=network)
         self.containers[name] = d
+        return name  # we might use UUIDs for naming later on
 
     def removeCompute(self, name):
         """
@@ -61,3 +71,11 @@ class Datacenter(object):
             link=None, node1=self.containers[name], node2=self.switch)
         self.net.removeDocker("%s" % (name))
         del self.containers[name]
+        return True
+
+    def listCompute(self):
+        """
+        Return a list of all running containers assigned to this
+        data center.
+        """
+        return self.containers.itervalues()