diff --git a/ara/cli/play.py b/ara/cli/play.py index d3c950a4..5f147cbb 100644 --- a/ara/cli/play.py +++ b/ara/cli/play.py @@ -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="", + 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])) diff --git a/doc/source/cli.rst b/doc/source/cli.rst index bd865936..bfa771ca 100644 --- a/doc/source/cli.rst +++ b/doc/source/cli.rst @@ -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 ------------- diff --git a/setup.cfg b/setup.cfg index c41604ee..8ad770e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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