Add PolicyType resource for clustering

This proposes the PolicyType resource for clustering (senlin) service.

Change-Id: I5857b301661409262af4054941a36f53633ff2aa
This commit is contained in:
tengqm 2015-12-09 01:57:51 -05:00
parent 0f3efa3ca0
commit f47cd8ef17
4 changed files with 104 additions and 0 deletions

View File

@ -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.

View File

@ -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')

View File

@ -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)

View File

@ -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)