status["state"] = self.dcli.inspect_container(self.dc)["State"]
status["id"] = self.dcli.inspect_container(self.dc)["Id"]
status["datacenter"] = (None if self.datacenter is None
- else self.datacenter.name)
+ else self.datacenter.label)
return status
Will also implement resource bookkeeping in later versions.
"""
- def __init__(self, name):
+ DC_COUNTER = 1
+
+ def __init__(self, label, metadata={}):
self.net = None # DCNetwork to which we belong
- self.name = name
+ # each node (DC) has a short internal name used by Mininet
+ # this is caused by Mininets naming limitations for swtiches etc.
+ self.name = "dc%d" % Datacenter.DC_COUNTER
+ Datacenter.DC_COUNTER += 1
+ # use this for user defined names that can be longer than self.name
+ self.label = label
+ # dict to store arbitrary metadata (e.g. latitude and longitude)
+ self.metadata = metadata
self.switch = None # first prototype assumes one "bigswitch" per DC
self.containers = {} # keep track of running containers
TODO: This will be changed in the future to support multiple networks
per data center
"""
- self.switch = self.net.mnet.addSwitch(
+ self.switch = self.net.addSwitch(
"%s.s1" % self.name, dpid=hex(self._get_next_dc_dpid())[2:])
logging.debug("created data center switch: %s" % str(self.switch))
def start(self):
pass
- def startCompute(self, name, image=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.
"""
assert name is not None
# no duplications
- if name in self.containers:
+ if name in [c.name for c in self.net.getAllContainers()]:
raise Exception("Container with name %s already exists." % name)
# set default parameter
if image is None:
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)
+ d = self.net.addDocker("%s" % (name), dimage=image, dcmd=command)
self.net.addLink(d, self.switch, params1=network)
# do bookkeeping
self.containers[name] = d
d.datacenter = self
- return name # we might use UUIDs for naming later on
+ return d # we might use UUIDs for naming later on
def stopCompute(self, name):
"""
Return a list of all running containers assigned to this
data center.
"""
- return self.containers.itervalues()
+ return list(self.containers.itervalues())
+
+ def getStatus(self):
+ """
+ Return a dict with status information about this DC.
+ """
+ return {
+ "label": self.label,
+ "internalname": self.name,
+ "switch": self.switch.name,
+ "n_running_containers": len(self.containers),
+ "metadata": self.metadata
+ }