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