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 741e73265c
commit 439a894947
5 changed files with 56 additions and 4 deletions

View File

@ -77,7 +77,8 @@ def blueprints_list(socket_path, api_version, args, show_json=False):
if exit_now: if exit_now:
return rc 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 return rc

View File

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

View File

@ -25,6 +25,9 @@ compose types
compose status compose status
List the status of all running and finished composes. List the status of all running and finished composes.
compose list [waiting|running|finished|failed]
List basic information about composes.
compose log <UUID> [<SIZE>] compose log <UUID> [<SIZE>]
Show the last SIZE kB of the compose log. Show the last SIZE kB of the compose log.

View File

@ -42,6 +42,7 @@ def modules_cmd(opts):
if exit_now: if exit_now:
return rc 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 return rc

View File

@ -67,7 +67,8 @@ def sources_list(socket_path, api_version, args, show_json=False):
if exit_now: if exit_now:
return rc 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 return rc
def sources_info(socket_path, api_version, args, show_json=False): def sources_info(socket_path, api_version, args, show_json=False):