Example #1
0
    def restart_app(self, config, appname, app_dict):

        if boot2docker.has():
            boot2docker.run(config, appname)
            config["docker_sock"] = "tcp://%s:2375"%(boot2docker.ip(config,appname))
            config["chroot"] = os.path.join("/mnt/host",config.get("chroot",""))
        config["hosts_table"] = app_dict.get("hosts_table",{})
        app = {}
        for hostname in app_dict.get("hosts",{}):
            for state in app_dict["hosts"][hostname]:
                if state == "linux.docker.deploy":
                    for container in app_dict["hosts"][hostname][state]:
                        container_name = "%s-%s-%s"%(appname,hostname,container)
                        containers = ([container_name]
                                      if not app_dict["hosts"][hostname][state][container].get("count")
                                      else ["%s_%s"%(container_name,i)
                                            for i in range(1,int(app_dict["hosts"][hostname][state][container]["count"])+1)])
                        for cname in containers:
                            if dockervisops.restart(config, cname) is True:
                                app[cname] = dockervisops.get_container_infos(config,cname)
                                print "Container %s restarted"%cname
                            else:
                                utils.error("Unable to restart container %s"%container_name)

        dockervisops.generate_hosts(config, app)

        print "App %s restarted."%appname
Example #2
0
    def start_app(self, config, appname, app_dict):
        config["appname"] = appname
        if boot2docker.has():
            boot2docker.run(config, appname)
            config["docker_sock"] = "tcp://%s:2375"%(boot2docker.ip(config,appname))
            config["chroot"] = os.path.join("/mnt/host",config.get("chroot",""))
        config["hosts_table"] = app_dict.get("hosts_table",{})
        actions = {}
        for hostname in app_dict.get("hosts",{}):
            actions[hostname] = {}
            for state in app_dict["hosts"][hostname]:
                if state == "linux.docker.deploy":
                    for container in app_dict["hosts"][hostname][state]:
                        actions[hostname][container] = (dockervisops.preproc_deploy(config,
                                                                                    config["appname"],
                                                                                    hostname,
                                                                                    app_dict["hosts"][hostname][state][container],
                                                                                    "start"))
        config["actions"] = actions
        app = {}
        for hostname in actions:
            for container in actions[hostname]:
                app.update(dockervisops.deploy(config, actions[hostname][container]))

        dockervisops.generate_hosts(config, app)

        print "App %s started."%appname
Example #3
0
File: run.py Project: VisualOps/cli
def run_stack(config, app_dict, force=True):
    config["appname"] = utils.user_param(config, "Enter app name",config["appname"])
    config["dirs"] = {
        "containers": os.path.join(config["config_path"],"docker","containers"),
        "boot2docker": os.path.join(config["config_path"],"docker","boot2docker"),
    }
    for d in config["dirs"]:
        if not os.path.exists(config["dirs"][d]):
            os.makedirs(config["dirs"][d])
    if boot2docker.has():
        print "Starting Boot2docker ... (this may take a while)"
        if not os.path.isfile(os.path.join(config["dirs"]["boot2docker"],"boot2docker.iso")):
            utils.download(config["boot2docker_iso"],os.path.join(config["dirs"]["boot2docker"],"boot2docker.iso"))

        if not boot2docker.gen_config(config, config["appname"]):
            utils.error("Unable to generate boot2docker configuration")
            return False
        boot2docker.delete(config, config["appname"])
        boot2docker.init(config, config["appname"])
        boot2docker.mount(config["appname"], [{
            "volume": "visops_root",
            "hostpath": "/",
        },{
            "volume": "visops_containers",
            "hostpath": config["dirs"]["containers"],
        }])
        if boot2docker.run(config, config["appname"]):
            print "Boot2docker successfully running!"
        else:
            utils.error("Unable to run Boot2docker.")
        config["chroot"] = os.path.join("/mnt/host",config.get("chroot",""))
        config["docker_sock"] = "tcp://%s:2375"%(boot2docker.ip(config,config["appname"]))
    config["hosts_table"] = app_dict.get("hosts_table",{})
    actions = {}
    for hostname in app_dict.get("hosts",{}):
        actions[hostname] = {}
        for state in app_dict["hosts"][hostname]:
            if state == "linux.docker.deploy":
                for container in app_dict["hosts"][hostname][state]:
                    app_dict["hosts"][hostname][state][container]["hostname"] = app_dict["hosts"][hostname][state][container].get("container")
                    app_dict["hosts"][hostname][state][container]["container"] = "%s-%s-%s"%(config["appname"],
                                                                                             hostname,
                                                                                             app_dict["hosts"][hostname][state][container].get("container",""))
                    actions[hostname][container] = (dockervisops.preproc_deploy(config,
                                                                                config["appname"],
                                                                                hostname,
                                                                                app_dict["hosts"][hostname][state][container],
                                                                                "deploy"))
    config["actions"] = actions
    actions = dockervisops.render_all(config, actions)
    config["actions"] = actions
    app = {}
    for hostname in actions:
        for container in actions[hostname]:
            app.update(dockervisops.deploy(config, actions[hostname][container]))
    dockervisops.generate_hosts(config, app)

    #save user input parameter to app_dict
    utils.persist_app(actions,app_dict)
Example #4
0
    def terminate_app(self, config, appname, app_dict):
        if boot2docker.has():
            config["docker_sock"] = "tcp://%s:2375"%(boot2docker.ip(config,appname))
        for hostname in app_dict.get("hosts",{}):
            for state in app_dict["hosts"][hostname]:
                if state == "linux.docker.deploy":
                    for container in app_dict["hosts"][hostname][state]:
                        container_name = "%s-%s-%s"%(appname,hostname,container)
                        containers = ([container_name]
                                      if not app_dict["hosts"][hostname][state][container].get("count")
                                      else ["%s_%s"%(container_name,i)
                                            for i in range(1,int(app_dict["hosts"][hostname][state][container]["count"])+1)])
                        print containers
                        for cname in containers:
                            if dockervisops.remove_container(config, cname) is True:
                                print "Container %s removed"%cname
                            else:
                                utils.error("Unable to remove container %s"%cname)

        if boot2docker.has():
            boot2docker.delete(config, appname)
        print "App %s terminated."%appname