def sources_info(socket_path, api_version, args, show_json=False): """Output info on a list of projects :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool sources info <source-name> """ if len(args) == 0: log.error("sources info is missing the name of the source") return 1 if show_json: api_route = client.api_url(api_version, "/projects/source/info/%s" % ",".join(args)) result = client.get_url_json(socket_path, api_route) print(json.dumps(result, indent=4)) return 0 else: api_route = client.api_url(api_version, "/projects/source/info/%s?format=toml" % ",".join(args)) result = client.get_url_raw(socket_path, api_route) print(result) return 0
def compose_list(socket_path, api_version, args, show_json=False, testmode=0, api=None): """Return a simple list of compose identifiers""" states = ("running", "waiting", "finished", "failed") which = set() if any(a not in states for a in args): # TODO: error about unknown state return 1 elif not args: which.update(states) else: which.update(args) results = [] if "running" in which or "waiting" in which: api_route = client.api_url(api_version, "/compose/queue") r = client.get_url_json(socket_path, api_route) if "running" in which: results += r["run"] if "waiting" in which: results += r["new"] if "finished" in which: api_route = client.api_url(api_version, "/compose/finished") r = client.get_url_json(socket_path, api_route) results += r["finished"] if "failed" in which: api_route = client.api_url(api_version, "/compose/failed") r = client.get_url_json(socket_path, api_route) results += r["failed"] if results: if show_json: print(json.dumps(results, indent=4)) else: list_fmt = "{id} {queue_status} {blueprint} {version} {compose_type}" print("\n".join(list_fmt.format(**c) for c in results)) return 0
def compose_delete(socket_path, api_version, args, show_json=False, testmode=0, api=None): """Delete a finished compose's results :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose delete <uuid,...> Delete the listed compose results. It will only delete results for composes that have finished or failed, not a running compose. """ if len(args) == 0: log.error("delete is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/delete/%s" % (",".join(argify(args)))) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)[0]
def compose_types(socket_path, api_version, args, show_json=False, testmode=0, api=None): """Return information about the supported compose types :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int Add additional details to types that are known to composer-cli. Raw JSON output does not include this extra information. """ api_route = client.api_url(api_version, "/compose/types") result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) return 0 # output a plain list of identifiers, one per line print("\n".join(t["name"] for t in result["types"] if t["enabled"]))
def upload_list(socket_path, api_version, args, show_json=False, testmode=0): """Return the composes and their associated upload uuids and status :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int upload list """ api_route = client.api_url(api_version, "/compose/finished") r = client.get_url_json(socket_path, api_route) results = r["finished"] if not results: return 0 if show_json: print(json.dumps(results, indent=4)) else: compose_fmt = "{id} {queue_status} {blueprint} {version} {compose_type}" upload_fmt = ' {uuid} "{image_name}" {provider_name} {status}' for c in results: print(compose_fmt.format(**c)) print("\n".join(upload_fmt.format(**u) for u in c["uploads"])) print() return 0
def upload_log(socket_path, api_version, args, show_json=False, testmode=0): """Return the upload log :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int upload log <build-uuid> """ if len(args) == 0: log.error("log is missing the upload uuid") return 1 api_route = client.api_url(api_version, "/upload/log/%s" % args[0]) result = client.get_url_json(socket_path, api_route) (rc, exit_now) = handle_api_result(result, show_json) if exit_now: return rc print("Upload log for %s:\n" % result["upload_id"]) print(result["log"]) return 0
def providers_list(socket_path, api_version, args, show_json=False, testmode=0): """Return the list of providers :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int providers list """ api_route = client.api_url(api_version, "/upload/providers") r = client.get_url_json(socket_path, api_route) results = r["providers"] if not results: return 0 if show_json: print(json.dumps(results, indent=4)) else: if len(args) == 1: if args[0] not in results: log.error("%s is not a valid provider", args[0]) return 1 print("\n".join(sorted(results[args[0]]["profiles"].keys()))) else: print("\n".join(sorted(results.keys()))) return 0
def providers_push(socket_path, api_version, args, show_json=False, testmode=0): """Add a new provider profile or overwrite an existing one :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int providers push <profile.toml> """ if len(args) == 0: log.error("push is missing the profile TOML file") return 1 if not os.path.exists(args[0]): log.error("Missing profile TOML file: %s", args[0]) return 1 api_route = client.api_url(api_version, "/upload/providers/save") profile = toml.load(args[0]) result = client.post_url_json(socket_path, api_route, json.dumps(profile)) return handle_api_result(result, show_json)[0]
def providers_delete(socket_path, api_version, args, show_json=False, testmode=0): """Delete a profile from a provider :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int providers delete <provider> <profile> """ if len(args) == 0: log.error("delete is missing the provider name") return 1 if len(args) == 1: log.error("delete is missing the profile name") return 1 api_route = client.api_url(api_version, "/upload/providers/delete/%s/%s" % (args[0], args[1])) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)[0]
def blueprints_workspace(socket_path, api_version, args, show_json=False): """Push the blueprint TOML to the temporary workspace storage :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints workspace <blueprint> Push the blueprint TOML to the temporary workspace storage. """ api_route = client.api_url(api_version, "/blueprints/workspace") rval = 0 for blueprint in argify(args): if not os.path.exists(blueprint): log.error("Missing blueprint file: %s", blueprint) continue with open(blueprint, "r") as f: blueprint_toml = f.read() result = client.post_url_toml(socket_path, api_route, blueprint_toml) if handle_api_result(result, show_json)[0]: rval = 1 return rval
def blueprints_changes(socket_path, api_version, args, show_json=False): """Display the changes for each of the blueprints :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints changes <blueprint,...> Display the changes for each blueprint. """ def changes_total_fn(data): """Return the maximum number of possible changes""" # Each blueprint can have a different total, return the largest one return max([c["total"] for c in data["blueprints"]]) api_route = client.api_url(api_version, "/blueprints/changes/%s" % (",".join(argify(args)))) result = client.get_url_json_unlimited(socket_path, api_route, total_fn=changes_total_fn) (rc, exit_now) = handle_api_result(result, show_json) if exit_now: return rc for blueprint in result["blueprints"]: print(blueprint["name"]) for change in blueprint["changes"]: prettyCommitDetails(change) return rc
def modules_cmd(opts): """Process modules commands :param opts: Cmdline arguments :type opts: argparse.Namespace :returns: Value to return from sys.exit() :rtype: int """ if opts.args[1] == "help" or opts.args[1] == "--help": print(modules_help) return 0 elif opts.args[1] != "list": log.error("Unknown modules command: %s", opts.args[1]) return 1 api_route = client.api_url(opts.api_version, "/modules/list") result = client.get_url_json_unlimited(opts.socket, api_route) (rc, exit_now) = handle_api_result(result, opts.json) if exit_now: return rc # "list" should output a plain list of identifiers, one per line. print("\n".join(r["name"] for r in result["modules"])) return rc
def compose_logs(socket_path, api_version, args, show_json=False, testmode=0, api=None): """Download a tar of the compose's logs :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose logs <uuid> Saves the logs as uuid-logs.tar """ if len(args) == 0: log.error("logs is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/logs/%s" % args[0]) try: rc = client.download_file(socket_path, api_route, sys.stdout.isatty()) except RuntimeError as e: print(str(e)) rc = 1 return rc
def projects_list(socket_path, api_version, args, show_json=False): """Output the list of available projects :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool projects list """ api_route = client.api_url(api_version, "/projects/list") result = client.get_url_json(socket_path, api_route) (rc, exit_now) = handle_api_result(result, show_json) if exit_now: return rc for proj in result["projects"]: for k in [ field for field in ("name", "summary", "homepage", "description") if proj[field] ]: print("%s: %s" % (k.title(), textwrap.fill(proj[k], subsequent_indent=" " * (len(k) + 2)))) print("\n\n") return rc
def sources_add(socket_path, api_version, args, show_json=False): """Add or change a source :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool sources add <source.toml> """ api_route = client.api_url(api_version, "/projects/source/new") rval = 0 for source in argify(args): if not os.path.exists(source): log.error("Missing source file: %s", source) continue source_toml = open(source, "r").read() result = client.post_url_toml(socket_path, api_route, source_toml) if handle_api_result(result, show_json): rval = 1 return rval
def blueprints_undo(socket_path, api_version, args, show_json=False): """Undo changes to a blueprint :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints undo <blueprint> <commit> Undo changes to a blueprint by reverting to the selected commit. """ if len(args) == 0: log.error("undo is missing the blueprint name and commit hash") return 1 elif len(args) == 1: log.error("undo is missing commit hash") return 1 api_route = client.api_url(api_version, "/blueprints/undo/%s/%s" % (args[0], args[1])) result = client.post_url(socket_path, api_route, "") return handle_api_result(result, show_json)
def blueprints_workspace(socket_path, api_version, args, show_json=False): """Push the blueprint TOML to the temporary workspace storage :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints workspace <blueprint> Push the blueprint TOML to the temporary workspace storage. """ api_route = client.api_url(api_version, "/blueprints/workspace") rval = 0 for blueprint in argify(args): if not os.path.exists(blueprint): log.error("Missing blueprint file: %s", blueprint) continue blueprint_toml = open(blueprint, "r").read() result = client.post_url_toml(socket_path, api_route, blueprint_toml) if show_json: print(json.dumps(result, indent=4)) for err in result.get("errors", []): log.error(err) # Any errors results in returning a 1, but we continue with the rest first if not result.get("status", False): rval = 1 return rval
def blueprints_depsolve(socket_path, api_version, args, show_json=False): """Display the packages needed to install the blueprint :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints depsolve <blueprint,...> Display the packages needed to install the blueprint. """ api_route = client.api_url( api_version, "/blueprints/depsolve/%s" % (",".join(argify(args)))) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) return 0 for blueprint in result["blueprints"]: if blueprint["blueprint"].get("version", ""): print("blueprint: %s v%s" % (blueprint["blueprint"]["name"], blueprint["blueprint"]["version"])) else: print("blueprint: %s" % (blueprint["blueprint"]["name"])) for dep in blueprint["dependencies"]: print(" " + packageNEVRA(dep)) return 0
def blueprints_freeze_save(socket_path, api_version, args, show_json=False): """Save the frozen blueprint to a TOML file :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints freeze save <blueprint,...> Save the frozen blueprint to a file, <blueprint-name>.frozen.toml. """ if len(args) == 0: log.error("freeze save is missing the blueprint name") return 1 for blueprint in argify(args): api_route = client.api_url( api_version, "/blueprints/freeze/%s?format=toml" % blueprint) blueprint_toml = client.get_url_raw(socket_path, api_route) open(frozen_toml_filename(blueprint), "w").write(blueprint_toml) return 0
def blueprints_push(socket_path, api_version, args, show_json=False): """Push a blueprint TOML file to the server, updating the blueprint :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool push <blueprint> Push a blueprint TOML file to the server. """ api_route = client.api_url(api_version, "/blueprints/new") rval = 0 for blueprint in argify(args): if not os.path.exists(blueprint): log.error("Missing blueprint file: %s", blueprint) continue blueprint_toml = open(blueprint, "r").read() result = client.post_url_toml(socket_path, api_route, blueprint_toml) if handle_api_result(result, show_json): rval = 1 return rval
def blueprints_changes(socket_path, api_version, args, show_json=False): """Display the changes for each of the blueprints :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints changes <blueprint,...> Display the changes for each blueprint. """ api_route = client.api_url( api_version, "/blueprints/changes/%s" % (",".join(argify(args)))) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) return 0 for blueprint in result["blueprints"]: print(blueprint["name"]) for change in blueprint["changes"]: prettyCommitDetails(change) return 0
def compose_image(socket_path, api_version, args, show_json=False, testmode=0): """Download the compose's output image :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose image <uuid> This downloads only the result image, saving it as the image name, which depends on the type of compose that was selected. """ if len(args) == 0: log.error("logs is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/image/%s" % args[0]) return client.download_file(socket_path, api_route, sys.stdout.isatty())
def compose_results(socket_path, api_version, args, show_json=False, testmode=0): """Download a tar file of the compose's results :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose results <uuid> The results includes the metadata, output image, and logs. It is saved as uuid.tar """ if len(args) == 0: log.error("results is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/results/%s" % args[0]) return client.download_file(socket_path, api_route, sys.stdout.isatty())
def compose_cancel(socket_path, api_version, args, show_json=False, testmode=0): """Cancel a running compose :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose cancel <uuid> This will cancel a running compose. It does nothing if the compose has finished. """ if len(args) == 0: log.error("cancel is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/cancel/%s" % args[0]) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)
def blueprints_freeze(socket_path, api_version, args, show_json=False): """Handle the blueprints freeze commands :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints freeze <blueprint,...> Display the frozen blueprint's modules and packages. blueprints freeze show <blueprint,...> Display the frozen blueprint in TOML format. blueprints freeze save <blueprint,...> Save the frozen blueprint to a file, <blueprint-name>.frozen.toml. """ if args[0] == "show": return blueprints_freeze_show(socket_path, api_version, args[1:], show_json) elif args[0] == "save": return blueprints_freeze_save(socket_path, api_version, args[1:], show_json) if len(args) == 0: log.error("freeze is missing the blueprint name") return 1 api_route = client.api_url( api_version, "/blueprints/freeze/%s" % (",".join(argify(args)))) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) else: for entry in result["blueprints"]: blueprint = entry["blueprint"] if blueprint.get("version", ""): print("blueprint: %s v%s" % (blueprint["name"], blueprint["version"])) else: print("blueprint: %s" % (blueprint["name"])) for m in blueprint["modules"]: print(" %s-%s" % (m["name"], m["version"])) for p in blueprint["packages"]: print(" %s-%s" % (p["name"], p["version"])) # Print any errors for err in result.get("errors", []): log.error(err) # Return a 1 if there are any errors if result.get("errors", []): return 1 else: return 0
def compose_info(socket_path, api_version, args, show_json=False, testmode=0): """Return detailed information about the compose :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose info <uuid> This returns information about the compose, including the blueprint and the dependencies. """ if len(args) == 0: log.error("info is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/info/%s" % args[0]) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) return 0 for err in result.get("errors", []): log.error(err) if result.get("errors", []): return 1 if result["image_size"] > 0: image_size = str(result["image_size"]) else: image_size = "" print("%s %-8s %-15s %s %-16s %s" % (result["id"], result["queue_status"], result["blueprint"]["name"], result["blueprint"]["version"], result["compose_type"], image_size)) print("Packages:") for p in result["blueprint"]["packages"]: print(" %s-%s" % (p["name"], p["version"])) print("Modules:") for m in result["blueprint"]["modules"]: print(" %s-%s" % (m["name"], m["version"])) print("Dependencies:") for d in result["deps"]["packages"]: print(" " + packageNEVRA(d))
def providers_save(socket_path, api_version, args, show_json=False, testmode=0): """Save a provider's profile to a TOML file :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int providers save <provider> <profile> """ if len(args) == 0: log.error("save is missing the provider name") return 1 if len(args) == 1: log.error("save is missing the profile name") return 1 api_route = client.api_url(api_version, "/upload/providers") r = client.get_url_json(socket_path, api_route) results = r["providers"] if not results: return 0 if show_json: print(json.dumps(results, indent=4)) else: if args[0] not in results: log.error("%s is not a valid provider", args[0]) return 1 if args[1] not in results[args[0]]["profiles"]: log.error("%s is not a valid %s profile", args[1], args[0]) return 1 profile = { "provider": args[0], "profile": args[1], "settings": results[args[0]]["profiles"][args[1]] } with open(toml_filename(args[1]), "w") as f: f.write(toml.dumps(profile)) return 0
def providers_show(socket_path, api_version, args, show_json=False, testmode=0): """Return details about a provider :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int providers show <provider> <profile> """ if len(args) == 0: log.error("show is missing the provider name") return 1 if len(args) == 1: log.error("show is missing the profile name") return 1 api_route = client.api_url(api_version, "/upload/providers") r = client.get_url_json(socket_path, api_route) results = r["providers"] if not results: return 0 if show_json: print(json.dumps(results, indent=4)) else: if args[0] not in results: log.error("%s is not a valid provider", args[0]) return 1 if args[1] not in results[args[0]]["profiles"]: log.error("%s is not a valid %s profile", args[1], args[0]) return 1 # Print the details for this profile # fields are different for each provider, so we just print out the key:values for k in results[args[0]]["profiles"][args[1]]: print("%s: %s" % (k, results[args[0]]["profiles"][args[1]][k])) return 0
def upload_start(socket_path, api_version, args, show_json=False, testmode=0): """Start upload up a build uuid image :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int upload start <build-uuid> <image-name> [<provider> <profile> | <profile.toml>] """ if len(args) == 0: log.error("start is missing the compose build id") return 1 if len(args) == 1: log.error("start is missing the image name") return 1 if len(args) == 2: log.error("start is missing the provider and profile details") return 1 body = {"image_name": args[1]} if len(args) == 3: try: body.update(toml.load(args[2])) except toml.TomlDecodeError as e: log.error(str(e)) return 1 elif len(args) == 4: body["provider"] = args[2] body["profile"] = args[3] else: log.error("start has incorrect number of arguments") return 1 api_route = client.api_url(api_version, "/compose/uploads/schedule/%s" % args[0]) result = client.post_url_json(socket_path, api_route, json.dumps(body)) (rc, exit_now) = handle_api_result(result, show_json) if exit_now: return rc print("Upload %s added to the queue" % result["upload_id"]) return rc
def blueprints_diff(socket_path, api_version, args, show_json=False): """Display the differences between 2 versions of a blueprint :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool blueprints diff <blueprint-name> Display the differences between 2 versions of a blueprint. <from-commit> Commit hash or NEWEST <to-commit> Commit hash, NEWEST, or WORKSPACE """ if len(args) == 0: log.error( "blueprints diff is missing the blueprint name, from commit, and to commit" ) return 1 elif len(args) == 1: log.error( "blueprints diff is missing the from commit, and the to commit") return 1 elif len(args) == 2: log.error("blueprints diff is missing the to commit") return 1 api_route = client.api_url( api_version, "/blueprints/diff/%s/%s/%s" % (args[0], args[1], args[2])) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) return 0 for err in result.get("errors", []): log.error(err) if result.get("errors", False): return 1 for diff in result["diff"]: print(prettyDiffEntry(diff)) return 0