CLI: Port "ara play show" from ara 0.x

This allows to display details about a play.

Change-Id: Ibd1bb6824d6ee219bf525cf64b2aafb6e8df426a
This commit is contained in:
David Moreau Simard 2020-08-01 16:32:39 -04:00
parent 3b657e3fb0
commit b2fdd45c99
No known key found for this signature in database
GPG Key ID: 7D4729EC4E64E8B7
3 changed files with 67 additions and 0 deletions

View File

@ -3,8 +3,10 @@
import logging
import os
import sys
from cliff.lister import Lister
from cliff.show import ShowOne
from ara.cli.base import global_arguments
from ara.clients.utils import get_client
@ -98,3 +100,56 @@ class PlayList(Lister):
)
)
# fmt: on
class PlayShow(ShowOne):
""" Returns a detailed view of a specified play """
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(PlayShow, self).get_parser(prog_name)
parser = global_arguments(parser)
# fmt: off
parser.add_argument(
"play_id",
metavar="<play-id>",
help="Play to show",
)
# fmt: on
return parser
def take_action(self, args):
client = get_client(
client=args.client,
endpoint=args.server,
timeout=args.timeout,
username=args.username,
password=args.password,
verify=False if args.insecure else True,
)
# TODO: Improve client to be better at handling exceptions
play = client.get("/api/v1/plays/%s" % args.play_id)
if "detail" in play and play["detail"] == "Not found.":
self.log.error("Play not found: %s" % args.play_id)
sys.exit(1)
playbook = "(%s) %s" % (play["playbook"]["id"], play["playbook"]["name"] or play["playbook"]["path"])
play["report"] = "%s/playbooks/%s.html" % (args.server, play["playbook"]["id"])
play["playbook"] = playbook
# fmt: off
columns = (
"id",
"report",
"status",
"name",
"playbook",
"started",
"ended",
"duration",
"items",
)
# fmt: on
return (columns, ([play[column] for column in columns]))

View File

@ -83,6 +83,17 @@ Examples:
# List the plays for a specific playbook and format the result in json
ara play list --playbook 1 -f json
ara play show
-------------
.. command-output:: ara play show --help
Examples:
.. code-block:: bash
# Show a specific play and format the results as json
ara play show 9001 -f json
ara host list
-------------

View File

@ -39,6 +39,7 @@ ara.cli =
playbook show = ara.cli.playbook:PlaybookShow
playbook delete = ara.cli.playbook:PlaybookDelete
play list = ara.cli.play:PlayList
play show = ara.cli.play:PlayShow
host list = ara.cli.host:HostList
host show = ara.cli.host:HostShow
host delete = ara.cli.host:HostDelete