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:
parent
201a8d95f4
commit
6136246505
|
@ -2,8 +2,10 @@
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
from cliff.lister import Lister
|
from cliff.lister import Lister
|
||||||
|
from cliff.show import ShowOne
|
||||||
|
|
||||||
from ara.cli.base import global_arguments
|
from ara.cli.base import global_arguments
|
||||||
from ara.clients.utils import get_client
|
from ara.clients.utils import get_client
|
||||||
|
@ -97,3 +99,57 @@ class PlaybookList(Lister):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# fmt: on
|
# 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]))
|
||||||
|
|
|
@ -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 json
|
||||||
ara playbook list -f yaml
|
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)
|
CLI: ara-manage (django)
|
||||||
========================
|
========================
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue