From a19bf3b78daa405fd88b7fd4a31a8e523d0b3c01 Mon Sep 17 00:00:00 2001 From: tengqm Date: Thu, 12 Feb 2015 15:21:22 +0800 Subject: [PATCH] Reworkd policy operations Now we support attach, detach, update, enable, disable, list operations on cluster policies --- senlinclient/v1/shell.py | 59 ++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 2f4e7e3b..dd62bcba 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -636,11 +636,11 @@ def do_cluster_policy_list(sc, args): @utils.arg('-p', '--policy', metavar='', required=True, help=_('ID or name of policy to be attached.')) -@utils.arg('-r', '--priority', metavar='', +@utils.arg('-r', '--priority', metavar='', default=50, help=_('An integer specifying the relative priority among ' 'all policies attached to a cluster. The lower the ' 'value, the higher the priority. Default is 50.')) -@utils.arg('-l', '--enforcement-level', metavar='', default=0, +@utils.arg('-l', '--enforcement-level', metavar='', default=50, help=_('An integer beteen 0 and 100 representing the enforcement ' 'level. Default to enforcement level of policy.')) @utils.arg('-c', '--cooldown', metavar='', default=0, @@ -655,15 +655,16 @@ def do_cluster_policy_attach(sc, args): '''Attach policy to cluster.''' params = { 'id': args.id, - 'action': 'attach_policy', + 'action': 'policy_attach', 'action_args': { 'policy_id': args.policy, 'priority': args.priority, 'level': args.enforcement_level, - 'enabled': args.enabled, 'cooldown': args.cooldown, + 'enabled': args.enabled, } } + resp = sc.action(models.Cluster, params) print('Request accepted by action %s' % resp['action']) @@ -676,37 +677,59 @@ def do_cluster_policy_detach(sc, args): '''Detach policy from cluster.''' params = { 'id': args.id, - 'action': 'detach_policy', + 'action': 'policy_detach', 'action_args': { 'policy_id': args.policy, } } + + resp = sc.action(models.Cluster, params) + print('Request accepted by action %s' % resp['action']) + + +@utils.arg('-p', '--policy', metavar='', required=True, + help=_('ID or name of policy to be updated.')) +@utils.arg('-r', '--priority', metavar='', + help=_('An integer specifying the relative priority among ' + 'all policies attached to a cluster. The lower the ' + 'value, the higher the priority. Default is 50.')) +@utils.arg('-l', '--enforcement-level', metavar='', + help=_('New enforcement level.')) +@utils.arg('-c', '--cooldown', metavar='', + help=_('Cooldown interval in seconds.')) +@utils.arg('-e', '--enabled', metavar='', + help=_('Whether the policy should be enabled.')) +@utils.arg('id', metavar='', + help=_('Name or ID of cluster to operate on.')) +def do_cluster_policy_update(sc, args): + '''Update a policy on cluster.''' + params = { + 'id': args.id, + 'action': 'policy_update', + 'action_args': { + 'policy_id': args.policy, + 'priority': args.priority, + 'level': args.enforcement_level, + 'cooldown': args.cooldown, + 'enabled': args.enabled, + } + } + resp = sc.action(models.Cluster, params) print('Request accepted by action %s' % resp['action']) @utils.arg('-p', '--policy', metavar='', required=True, help=_('ID or name of policy to be enabled.')) -@utils.arg('-r', '--priority', metavar='', - help=_('An integer specifying the relative priority among ' - 'all policies attached to a cluster. The lower the ' - 'value, the higher the priority. Default is 50.')) -@utils.arg('-l', '--level', metavar='', - help=_('New enforcement level.')) -@utils.arg('-c', '--cooldown', metavar='', - help=_('Cooldown interval in seconds.')) @utils.arg('id', metavar='', help=_('Name or ID of cluster to operate on.')) def do_cluster_policy_enable(sc, args): '''Enable a policy on cluster.''' params = { 'id': args.id, - 'action': 'enable_policy', + 'action': 'policy_enable', 'action_args': { 'policy_id': args.policy, - 'priority': args.priority, - 'level': args.enforcement_level, - 'cooldown': args.cooldown, } } resp = sc.action(models.Cluster, params) @@ -721,7 +744,7 @@ def do_cluster_policy_disable(sc, args): '''Disable a policy on a cluster.''' params = { 'id': args.id, - 'action': 'disable_policy', + 'action': 'policy_disable', 'action_args': { 'policy_id': args.policy, }