From dc541c6abf5c8c20c99b9e15656122a69300e1c9 Mon Sep 17 00:00:00 2001 From: tengqm Date: Mon, 8 Jun 2015 04:48:26 -0400 Subject: [PATCH] Revise webhook-create support in client This patch revised the client-side support to webhook creation. We now save users from manually input 'obj_type' which makes little to no sense to them. This is done by providing three separate arguments for users to choose from. Change-Id: I8f339af3007f5272f1259a933dd1ea1d8632b2db --- senlinclient/v1/shell.py | 45 +++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 7cafc295..56d713d4 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -326,28 +326,49 @@ def do_webhook_show(sc, args): _show_webhook(sc, webhook_id=args.id) -@utils.arg('-t', '--obj-type', metavar='', required=True, - help=_('Object type name used for this webhook.')) -@utils.arg('-i', '--obj-id', metavar='', required=True, - help=_('Object id used for this webhook.')) +@utils.arg('-c', '--cluster', metavar='', + help=_('Targeted cluster for this webhook.')) +@utils.arg('-n', '--node', metavar='', + help=_('Targeted node for this webhook.')) +@utils.arg('-p', '--policy', metavar='', + help=_('Targeted policy for this webhook.')) @utils.arg('-a', '--action', metavar='', required=True, - help=_('Name of action used for this webhook.')) -@utils.arg('-c', '--credential', metavar='', + help=_('Name of action to be triggered for this webhook.')) +@utils.arg('-C', '--credential', metavar='', required=True, - help=_('The credential used when triggering the webhook.'), + help=_('The credential to be used when the webhook is triggered.'), action='append') -@utils.arg('-p', '--params', metavar='', - help=_('A dictionary of parameters that will be passed to object ' - 'action when webhook is triggered.'), +@utils.arg('-P', '--params', metavar='', + help=_('A dictionary of parameters that will be passed to target ' + 'action when the webhook is triggered.'), action='append') @utils.arg('name', metavar='', help=_('Name of the webhook to create.')) def do_webhook_create(sc, args): '''Create a webhook.''' + + c = sum(x is not None for x in [args.cluster, args.node, args.policy]) + if c > 1: + msg = _("Only one of 'cluster', 'node' or 'policy' can be specified.") + raise exc.CommandError(msg) + elif c == 0: + msg = _("One of 'cluster', 'node' or 'policy' must be specified.") + raise exc.CommandError(msg) + + if args.cluster: + obj_type = 'cluster' + obj_id = args.cluster + elif args.node: + obj_type = 'node' + obj_id = args.node + else: + obj_type = 'policy' + obj_id = args.policy + params = { 'name': args.name, - 'obj_id': args.obj_id, - 'obj_type': args.obj_type, + 'obj_id': obj_id, + 'obj_type': obj_type, 'action': args.action, 'credential': utils.format_parameters(args.credential), 'params': utils.format_parameters(args.params)