CLI: Port "ara record show" from ara 0.x
This allows to display details for a specific record. Change-Id: I33d0cd9b12be67939ba20f0f6351055dae8416b5
This commit is contained in:
parent
cabce63bae
commit
6c78cf1151
@ -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
|
||||
@ -81,3 +83,58 @@ class RecordList(Lister):
|
||||
)
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
|
||||
class RecordShow(ShowOne):
|
||||
""" Returns a detailed view of a specified record """
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RecordShow, self).get_parser(prog_name)
|
||||
parser = global_arguments(parser)
|
||||
# fmt: off
|
||||
parser.add_argument(
|
||||
"record_id",
|
||||
metavar="<record-id>",
|
||||
help="Record 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
|
||||
record = client.get("/api/v1/records/%s" % args.record_id)
|
||||
if "detail" in record and record["detail"] == "Not found.":
|
||||
self.log.error("Record not found: %s" % args.record_id)
|
||||
sys.exit(1)
|
||||
|
||||
playbook = "(%s) %s" % (record["playbook"]["id"], record["playbook"]["name"] or record["playbook"]["path"])
|
||||
record["report"] = "%s/playbooks/%s.html" % (args.server, record["playbook"]["id"])
|
||||
record["playbook"] = playbook
|
||||
|
||||
# fmt: off
|
||||
columns = (
|
||||
"id",
|
||||
"report",
|
||||
"playbook",
|
||||
"key",
|
||||
"value",
|
||||
"created",
|
||||
"updated",
|
||||
)
|
||||
# fmt: on
|
||||
return (columns, ([record[column] for column in columns]))
|
||||
|
@ -191,6 +191,18 @@ Examples:
|
||||
# List records for a specific playbook
|
||||
ara record list --playbook 9001
|
||||
|
||||
ara record show
|
||||
---------------
|
||||
|
||||
.. command-output:: ara record show --help
|
||||
|
||||
Examples:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Show a specific record and format the results as json
|
||||
ara record show 9001 -f json
|
||||
|
||||
ara result list
|
||||
---------------
|
||||
|
||||
|
@ -45,6 +45,7 @@ ara.cli =
|
||||
host show = ara.cli.host:HostShow
|
||||
host delete = ara.cli.host:HostDelete
|
||||
record list = ara.cli.record:RecordList
|
||||
record show = ara.cli.record:RecordShow
|
||||
result list = ara.cli.result:ResultList
|
||||
result show = ara.cli.result:ResultShow
|
||||
result delete = ara.cli.result:ResultDelete
|
||||
|
Loading…
Reference in New Issue
Block a user