CLI: Port "ara playbook show" command from ara 0.x

The command is used to return details about a playbook.

Change-Id: Ib35863ab436c515120aa2435ad1024a8e1f2f516
This commit is contained in:
David Moreau Simard 2020-07-10 11:46:05 -04:00
parent 201a8d95f4
commit 6136246505
No known key found for this signature in database
GPG Key ID: 7D4729EC4E64E8B7
3 changed files with 75 additions and 0 deletions

View File

@ -2,8 +2,10 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
import logging
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
@ -97,3 +99,57 @@ class PlaybookList(Lister):
)
)
# fmt: on
class PlaybookShow(ShowOne):
""" Returns a detailed view of a specified playbook """
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(PlaybookShow, self).get_parser(prog_name)
parser = global_arguments(parser)
# fmt: off
parser.add_argument(
"playbook_id",
metavar="<playbook-id>",
help="Playbook to show",
)
# fmt: on
return parser
def take_action(self, args):
# TODO: Render json properly in pretty tables
if args.formatter == "table":
self.log.warn("Rendering using default table formatter, use '-f yaml' or '-f json' for improved display.")
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
playbook = client.get("/api/v1/playbooks/%s" % args.playbook_id)
if "detail" in playbook and playbook["detail"] == "Not found.":
self.log.error("Playbook not found: %s" % args.playbook_id)
sys.exit(1)
playbook["report"] = "%s/playbooks/%s.html" % (args.server, args.playbook_id)
columns = (
"id",
"report",
"status",
"path",
"started",
"ended",
"duration",
"ansible_version",
"items",
"labels",
"arguments",
)
return (columns, ([playbook[column] for column in columns]))

View File

@ -37,6 +37,24 @@ Get a list of playbooks and format the results as json or yaml instead of pretty
ara playbook list -f json
ara playbook list -f yaml
ara playbook show
-----------------
.. command-output:: ara playbook show --help
Show details about a playbook from a running API server and format the result in json:
.. code-block:: bash
ara playbook show --client http --server https://api.demo.recordsansible.org 1 -f json
Show details about a playbook from a local installation using the default offline
API client and format the result in yaml:
.. code-block:: bash
ara playbook show 1 -f yaml
CLI: ara-manage (django)
========================

View File

@ -36,6 +36,7 @@ console_scripts =
ara.cli =
playbook list = ara.cli.playbook:PlaybookList
playbook show = ara.cli.playbook:PlaybookShow
[extras]
server=