From 4e98b6362438ec5ce0cfec4b497fa24620efe212 Mon Sep 17 00:00:00 2001 From: peusterm Date: Tue, 12 Jan 2016 14:08:07 +0100 Subject: [PATCH] populated compute API --- emuvim/api/zerorpcapi.py | 18 ++++++++++++------ emuvim/cli/__main__.py | 9 ++++++++- emuvim/dcemulator/node.py | 26 ++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/emuvim/api/zerorpcapi.py b/emuvim/api/zerorpcapi.py index 71505a5..e00ecb9 100644 --- a/emuvim/api/zerorpcapi.py +++ b/emuvim/api/zerorpcapi.py @@ -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 diff --git a/emuvim/cli/__main__.py b/emuvim/cli/__main__.py index 1957082..82930dc 100644 --- a/emuvim/cli/__main__.py +++ b/emuvim/cli/__main__.py @@ -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") diff --git a/emuvim/dcemulator/node.py b/emuvim/dcemulator/node.py index 67ce600..3ab6341 100644 --- a/emuvim/dcemulator/node.py +++ b/emuvim/dcemulator/node.py @@ -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() -- 2.25.1