From 2fdcfc2e4cf2bfebc4edd74cb28b1807eb352dd6 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 1 Oct 2019 16:43:31 -0700 Subject: [PATCH] composer-cli: Add providers info command This will print details about the settings for the provider, as well as the supported image types. --- etc/bash_completion.d/composer-cli | 4 +-- src/composer/cli/providers.py | 42 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/etc/bash_completion.d/composer-cli b/etc/bash_completion.d/composer-cli index 6ee86626..612df396 100644 --- a/etc/bash_completion.d/composer-cli +++ b/etc/bash_completion.d/composer-cli @@ -9,7 +9,7 @@ declare -A __composer_cli_cmds=( [projects]="list info" [sources]="list info add change delete" [upload]="list info start log cancel delete reset" - [providers]="list show push save delete template" + [providers]="list info show push save delete template" [help]="" ) @@ -133,7 +133,7 @@ _composer_cli() { upload:start) COMPREPLY=($(compgen -W "$(__composer_composes)" -- "${cur}")) ;; - providers:show|providers:save|providers:delete) + providers:show|providers:save|providers:delete|providers:info) COMPREPLY=($(compgen -W "$(__composer_provider_list)" -- "${cur}")) ;; esac diff --git a/src/composer/cli/providers.py b/src/composer/cli/providers.py index 0bd52493..4503081d 100644 --- a/src/composer/cli/providers.py +++ b/src/composer/cli/providers.py @@ -37,6 +37,7 @@ def providers_cmd(opts): """ cmd_map = { "list": providers_list, + "info": providers_info, "show": providers_show, "push": providers_push, "save": providers_save, @@ -87,6 +88,47 @@ def providers_list(socket_path, api_version, args, show_json=False, testmode=0): return 0 +def providers_info(socket_path, api_version, args, show_json=False, testmode=0): + """Show information about each 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 info + """ + if len(args) == 0: + log.error("info is missing the provider 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 + p = results[args[0]] + print("%s supports these image types: %s" % (p["display"], ", ".join(p["supported_types"]))) + print("Settings:") + for k in p["settings-info"]: + f = p["settings-info"][k] + print(" %-20s: %s is a %s" % (k, f["display"], f["type"])) + + return 0 + def providers_show(socket_path, api_version, args, show_json=False, testmode=0): """Return details about a provider