Add OpenstackClient plugin for cluster policy binding show

This change implements the "openstack cluster policy binding show" command
  Based on the existing senlin command: senlin cluster-policy-show

Change-Id: I3637560cd07e574ae51d1a2be2f36fcdba8f5469
Blueprint: senlin-support-python-openstackclient
This commit is contained in:
dixiaoli
2016-02-27 21:50:21 +08:00
parent e7c7e3b439
commit 10793b97bf
3 changed files with 59 additions and 0 deletions

View File

@@ -13,8 +13,10 @@
"""Clustering v1 cluster policy action implementations"""
import logging
import six
from cliff import lister
from cliff import show
from openstackclient.common import utils
from senlinclient.common.i18n import _
@@ -83,3 +85,32 @@ class ClusterPolicyList(lister.Lister):
(utils.get_item_properties(p, columns, formatters=formatters)
for p in policies)
)
class ClusterPolicyShow(show.ShowOne):
"""Show a specific policy that is bound to the specified cluster."""
log = logging.getLogger(__name__ + ".ClusterPolicyShow")
def get_parser(self, prog_name):
parser = super(ClusterPolicyShow, self).get_parser(prog_name)
parser.add_argument(
'--policy',
metavar='<policy>',
required=True,
help=_('ID or name of the policy to query on')
)
parser.add_argument(
'cluster',
metavar='<cluster>',
help=_('ID or name of the cluster to query on')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
senlin_client = self.app.client_manager.clustering
policy = senlin_client.get_cluster_policy(parsed_args.policy,
parsed_args.cluster)
columns = list(six.iterkeys(policy))
return columns, utils.get_dict_properties(policy.to_dict(), columns)

View File

@@ -12,6 +12,7 @@
import mock
from openstack.cluster.v1 import cluster_policy as sdk_cluster_policy
from senlinclient.osc.v1 import cluster_policy as osc_cluster_policy
from senlinclient.tests.unit.osc.v1 import fakes
@@ -72,3 +73,29 @@ class TestClusterPolicyList(TestClusterPolicy):
name='my_policy',
**self.args)
self.assertEqual(self.columns, columns)
class TestClusterPolicyShow(TestClusterPolicy):
get_response = {"cluster_policy": {
"cluster_id": "7d85f602-a948-4a30-afd4-e84f47471c15",
"cluster_name": "my_cluster",
"enabled": True,
"id": "06be3a1f-b238-4a96-a737-ceec5714087e",
"policy_id": "714fe676-a08f-4196-b7af-61d52eeded15",
"policy_name": "my_policy",
"policy_type": "senlin.policy.deletion-1.0"
}}
def setUp(self):
super(TestClusterPolicyShow, self).setUp()
self.cmd = osc_cluster_policy.ClusterPolicyShow(self.app, None)
self.mock_client.get_cluster_policy = mock.Mock(
return_value=sdk_cluster_policy.ClusterPolicy(None,
self.get_response))
def test_cluster_policy_show(self):
arglist = ['--policy', 'my_policy', 'my_cluster']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.get_cluster_policy.assert_called_with('my_policy',
'my_cluster')

View File

@@ -31,6 +31,7 @@ openstack.cli.extension =
openstack.clustering.v1 =
cluster_policy_binding_list = senlinclient.osc.v1.cluster_policy:ClusterPolicyList
cluster_policy_binding_show = senlinclient.osc.v1.cluster_policy:ClusterPolicyShow
cluster_create = senlinclient.osc.v1.cluster:CreateCluster
cluster_delete = senlinclient.osc.v1.cluster:DeleteCluster
cluster_list = senlinclient.osc.v1.cluster:ListCluster