composer-cli: Add providers info <PROVIDER> command

This will print details about the settings for the provider, as well as
the supported image types.
This commit is contained in:
Brian C. Lane 2019-10-01 16:43:31 -07:00
parent 63816d9764
commit 2fdcfc2e4c
2 changed files with 44 additions and 2 deletions

View File

@ -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

View File

@ -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 <PROVIDER>
"""
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