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
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")
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):
"""
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()