composer-cli: clean up "list" commands

This patch does two things:

1) Add "compose list", which lists compose UUIDs and other basic info,
2) Fix up "blueprints list", "modules list", "sources list", and
   "compose types" so their output is just a plain list of identifiers
This commit is contained in:
Will Woods 2018-07-30 12:03:06 -04:00
parent 86d79cd8a6
commit 80b5a37036
5 changed files with 53 additions and 4 deletions

View File

@ -77,7 +77,8 @@ def blueprints_list(socket_path, api_version, args, show_json=False):
if exit_now:
return rc
print("blueprints: " + ", ".join([r for r in result["blueprints"]]))
# "list" should output a plain list of identifiers, one per line.
print("\n".join(result["blueprints"]))
return rc

View File

@ -36,6 +36,7 @@ def compose_cmd(opts):
This dispatches the compose commands to a function
"""
cmd_map = {
"list": compose_list,
"status": compose_status,
"types": compose_types,
"start": compose_start,
@ -57,6 +58,50 @@ def compose_cmd(opts):
return cmd_map[opts.args[1]](opts.socket, opts.api_version, opts.args[2:], opts.json, opts.testmode)
def compose_list(socket_path, api_version, args, show_json=False, testmode=0):
"""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_status(socket_path, api_version, args, show_json=False, testmode=0):
"""Return the status of all known composes
@ -148,7 +193,7 @@ def compose_types(socket_path, api_version, args, show_json=False, testmode=0):
print(json.dumps(result, indent=4))
return 0
print("Compose Types: " + ", ".join([t["name"] for t in result["types"]]))
print("\n".join(t["name"] for t in result["types"]))
def compose_start(socket_path, api_version, args, show_json=False, testmode=0):
"""Start a new compose using the selected blueprint and type

View File

@ -18,6 +18,7 @@ compose_help = """
compose start <blueprint> <type> Start a compose using the selected blueprint and output type.
types List the supported output types.
status List the status of all running and finished composes.
list [WHICH] List (waiting, running, finished, failed) composes.
log <uuid> [<size>kB] Show the last 1kB of the compose log.
cancel <uuid> Cancel a running compose and delete any intermediate results.
delete <uuid,...> Delete the listed compose results.

View File

@ -42,6 +42,7 @@ def modules_cmd(opts):
if exit_now:
return rc
print("Modules:\n" + "\n".join([" "+r["name"] for r in result["modules"]]))
# "list" should output a plain list of identifiers, one per line.
print("\n".join(r["name"] for r in result["modules"]))
return rc

View File

@ -67,7 +67,8 @@ def sources_list(socket_path, api_version, args, show_json=False):
if exit_now:
return rc
print("Sources: %s" % ", ".join(result["sources"]))
# "list" should output a plain list of identifiers, one per line.
print("\n".join(result["sources"]))
return rc
def sources_info(socket_path, api_version, args, show_json=False):