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

This command retrieves and returns details about a specific task.

Change-Id: I3f28c9eb46b5e13922f9a38de0eb7c98f961e8b9
This commit is contained in:
David Moreau Simard 2020-07-21 19:55:55 -04:00
parent a2831d7a6c
commit 9e54b26a34
3 changed files with 65 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
@ -106,3 +108,54 @@ class TaskList(Lister):
)
)
# fmt: on
class TaskShow(ShowOne):
""" Returns a detailed view of a specified task """
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(TaskShow, self).get_parser(prog_name)
parser = global_arguments(parser)
# fmt: off
parser.add_argument(
"task_id",
metavar="<task-id>",
help="Task 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
task = client.get("/api/v1/tasks/%s" % args.task_id)
if "detail" in task and task["detail"] == "Not found.":
self.log.error("Task not found: %s" % args.task_id)
sys.exit(1)
task["report"] = "%s/playbooks/%s.html" % (args.server, task["playbook"]["id"])
columns = (
"id",
"report",
"name",
"action",
"status",
"path",
"lineno",
"started",
"ended",
"duration",
"tags",
"handler",
)
return (columns, ([task[column] for column in columns]))

View File

@ -205,6 +205,17 @@ Examples:
# Return tasks matching a name (partial or full)
ara task list --name install_apache
ara task show
-------------
.. command-output:: ara task show --help
Return detailed information about a specific task:
.. code-block:: bash
ara task show 9001
CLI: ara-manage (django)
========================

View File

@ -45,6 +45,7 @@ ara.cli =
result show = ara.cli.result:ResultShow
result delete = ara.cli.result:ResultDelete
task list = ara.cli.task:TaskList
task show = ara.cli.task:TaskShow
[extras]
server=