Exemple #1
0
def cmd_sqldump(args, env, config):
    label = args.label[0]
    
    # request SQL dump and stream the response through uncompression
    
    err("Dumping database... ")
    url = "%s/instance/sqldump/" % config["gondor.endpoint"]
    params = {
        "version": __version__,
        "site_key": config["gondor.site_key"],
        "label": label,
    }
    try:
        response = make_api_call(config, url, urllib.urlencode(params))
    except urllib2.HTTPError, e:
        api_error(e)
Exemple #2
0
def cmd_run(args, env, config):
    
    instance_label = args.instance_label[0]
    command = args.command_
    
    if args.detached:
        err("Spawning... ")
    else:
        err("Attaching... ")
    url = "%s/instance/run/" % config["gondor.endpoint"]
    params = {
        "version": __version__,
        "site_key": config["gondor.site_key"],
        "instance_label": instance_label,
        "project_root": os.path.relpath(env["project_root"], env["repo_root"]),
        "detached": {True: "true", False: "false"}[args.detached],
        "command": " ".join(command),
        "app": json.dumps(config["app"]),
    }
    if sys.platform == "win32":
        params["term"] = "win32"
    if "TERM" in os.environ:
        try:
            params.update({
                "tc": utils.check_output(["tput", "cols"]).strip(),
                "tl": utils.check_output(["tput", "lines"]).strip(),
            })
        except (OSError, subprocess.CalledProcessError):
            # if the above fails then no big deal; we just can't set correct
            # terminal info so it will default some common values
            pass
    try:
        response = make_api_call(config, url, urllib.urlencode(params))
    except urllib2.HTTPError, e:
        err("[failed]\n")
        api_error(e)
Exemple #3
0
 while True:
     params = {
         "version": __version__,
         "site_key": config["gondor.site_key"],
         "instance_label": label,
         "task_id": task_id,
     }
     url = "%s/task/status/" % config["gondor.endpoint"]
     try:
         response = make_api_call(config, url, urllib.urlencode(params))
     except urllib2.URLError:
         # @@@ add max retries
         continue
     data = json.loads(response.read())
     if data["status"] == "error":
         err("[error]\n")
         error("%s\n" % data["message"])
     if data["status"] == "success":
         if data["state"] == "finished":
             err("[ok]\n")
             break
         elif data["state"] == "failed":
             err("[failed]\n")
             err("\n%s\n" % data["reason"])
             sys.exit(1)
         elif data["state"] == "locked":
             err("[locked]\n")
             err("\nYour database dump failed due to being locked. "
                 "This means there is another database dump already "
                 "in progress.\n")
             sys.exit(1)