From f47cd8ef1746cb5fccb33350be29be0b36ab243e Mon Sep 17 00:00:00 2001 From: tengqm Date: Wed, 9 Dec 2015 01:57:51 -0500 Subject: [PATCH] Add PolicyType resource for clustering This proposes the PolicyType resource for clustering (senlin) service. Change-Id: I5857b301661409262af4054941a36f53633ff2aa --- openstack/cluster/v1/_proxy.py | 22 ++++++++++ openstack/cluster/v1/policy_type.py | 32 ++++++++++++++ .../tests/unit/cluster/v1/test_policy_type.py | 42 +++++++++++++++++++ openstack/tests/unit/cluster/v1/test_proxy.py | 8 ++++ 4 files changed, 104 insertions(+) create mode 100644 openstack/cluster/v1/policy_type.py create mode 100644 openstack/tests/unit/cluster/v1/test_policy_type.py diff --git a/openstack/cluster/v1/_proxy.py b/openstack/cluster/v1/_proxy.py index ca4de158f..d8435bfae 100644 --- a/openstack/cluster/v1/_proxy.py +++ b/openstack/cluster/v1/_proxy.py @@ -17,6 +17,7 @@ from openstack.cluster.v1 import cluster_policy as _cluster_policy from openstack.cluster.v1 import event as _event from openstack.cluster.v1 import node as _node from openstack.cluster.v1 import policy as _policy +from openstack.cluster.v1 import policy_type as _policy_type from openstack.cluster.v1 import profile as _profile from openstack.cluster.v1 import profile_type as _profile_type from openstack import proxy @@ -53,6 +54,27 @@ class Proxy(proxy.BaseProxy): """ return self._get(_profile_type.ProfileType, profile_type) + def policy_types(self, **query): + """Get a generator of policy types. + + :returns: A generator of objects that are of type + :class:`~openstack.cluster.v1.policy_type.PolicyType` + """ + return self._list(_policy_type.PolicyType, paginated=False, **query) + + def get_policy_type(self, policy_type): + """Get the details about a policy_type. + + :param policy_type: The name of a poicy_type or an object of + :class:`~openstack.cluster.v1.policy_type.PolicyType`. + + :returns: A :class:`~openstack.cluster.v1.policy_type.PolicyType` + object. + :raises: :class:`~openstack.exceptions.ResourceNotFound` when no + policy_type matching the name could be found. + """ + return self._get(_policy_type.PolicyType, policy_type) + def create_profile(self, **attrs): """Create a new profile from attributes. diff --git a/openstack/cluster/v1/policy_type.py b/openstack/cluster/v1/policy_type.py new file mode 100644 index 000000000..86b950e0c --- /dev/null +++ b/openstack/cluster/v1/policy_type.py @@ -0,0 +1,32 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.cluster import cluster_service +from openstack import resource + + +class PolicyType(resource.Resource): + id_attribute = 'name' + resource_key = 'policy_type' + resources_key = 'policy_types' + base_path = '/policy-types' + service = cluster_service.ClusterService() + + # Capabilities + allow_list = True + allow_retrieve = True + + # Properties + #: Name of policy type. + name = resource.prop('name') + #: The schema of the policy type. + schema = resource.prop('schema') diff --git a/openstack/tests/unit/cluster/v1/test_policy_type.py b/openstack/tests/unit/cluster/v1/test_policy_type.py new file mode 100644 index 000000000..eeff387cb --- /dev/null +++ b/openstack/tests/unit/cluster/v1/test_policy_type.py @@ -0,0 +1,42 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import testtools + +from openstack.cluster.v1 import policy_type + + +FAKE = { + 'name': 'FAKE_POLICY_TYPE', + 'schema': { + 'foo': 'bar' + } +} + + +class TestPolicyType(testtools.TestCase): + + def test_basic(self): + sot = policy_type.PolicyType() + self.assertEqual('name', sot.id_attribute) + self.assertEqual('policy_type', sot.resource_key) + self.assertEqual('policy_types', sot.resources_key) + self.assertEqual('/policy-types', sot.base_path) + self.assertEqual('clustering', sot.service.service_type) + self.assertTrue(sot.allow_retrieve) + self.assertTrue(sot.allow_list) + + def test_instantiate(self): + sot = policy_type.PolicyType(FAKE) + self.assertEqual(FAKE['name'], sot.id) + self.assertEqual(FAKE['name'], sot.name) + self.assertEqual(FAKE['schema'], sot.schema) diff --git a/openstack/tests/unit/cluster/v1/test_proxy.py b/openstack/tests/unit/cluster/v1/test_proxy.py index abd3726ba..8ed16eeef 100644 --- a/openstack/tests/unit/cluster/v1/test_proxy.py +++ b/openstack/tests/unit/cluster/v1/test_proxy.py @@ -18,6 +18,7 @@ from openstack.cluster.v1 import cluster_policy from openstack.cluster.v1 import event from openstack.cluster.v1 import node from openstack.cluster.v1 import policy +from openstack.cluster.v1 import policy_type from openstack.cluster.v1 import profile from openstack.cluster.v1 import profile_type from openstack.tests.unit import test_proxy_base @@ -41,6 +42,13 @@ class TestClusterProxy(test_proxy_base.TestProxyBase): self.verify_get(self.proxy.get_profile_type, profile_type.ProfileType) + def test_policy_types(self): + self.verify_list(self.proxy.policy_types, policy_type.PolicyType, + paginated=False) + + def test_policy_type_get(self): + self.verify_get(self.proxy.get_policy_type, policy_type.PolicyType) + def test_profile_create(self): self.verify_create(self.proxy.create_profile, profile.Profile)