CLI: Add --resolve to 'ara host list'

This will return the playbook id in addition to it's path.

Change-Id: Ic8c912475d875b38b69eef9f2fcd7cef7f302e84
This commit is contained in:
David Moreau Simard 2020-08-31 18:53:43 -04:00
parent 411017e336
commit e2534a10fd
No known key found for this signature in database
GPG Key ID: 7D4729EC4E64E8B7

@ -9,6 +9,7 @@ from cliff.command import Command
from cliff.lister import Lister
from cliff.show import ShowOne
import ara.cli.utils as cli_utils
from ara.cli.base import global_arguments
from ara.clients.utils import get_client
@ -78,7 +79,12 @@ class HostList(Lister):
default=False,
help=("Don't return hosts with unreachable results")
)
parser.add_argument(
"--resolve",
action="store_true",
default=os.environ.get("ARA_CLI_RESOLVE", False),
help=("Resolve IDs to identifiers (such as path or names). Defaults to ARA_CLI_RESOLVE or False")
)
parser.add_argument(
"--order",
metavar="<order>",
@ -132,6 +138,12 @@ class HostList(Lister):
query["limit"] = args.limit
hosts = client.get("/api/v1/hosts", **query)
if args.resolve:
for host in hosts["results"]:
playbook = cli_utils.get_playbook(client, host["playbook"])
host["playbook"] = "(%s) %s" % (playbook["id"], playbook["path"])
columns = ("id", "name", "playbook", "changed", "failed", "ok", "skipped", "unreachable", "updated")
# fmt: off
return (