[python-heatclient/el6-havana] Add support for resource_types

Jakub Ruzicka jruzicka at fedoraproject.org
Mon Jan 6 17:11:39 UTC 2014


commit ce0ccbc5a519493dc7ff1d720af14e40c6a2a72c
Author: Jakub Ruzicka <jruzicka at redhat.com>
Date:   Mon Jan 6 18:10:56 2014 +0100

    Add support for resource_types

 0003-Add-support-for-resource_types.patch |  187 +++++++++++++++++++++++++++++
 python-heatclient.spec                    |    7 +-
 2 files changed, 193 insertions(+), 1 deletions(-)
---
diff --git a/0003-Add-support-for-resource_types.patch b/0003-Add-support-for-resource_types.patch
new file mode 100644
index 0000000..03ae14b
--- /dev/null
+++ b/0003-Add-support-for-resource_types.patch
@@ -0,0 +1,187 @@
+From 66bdba1971ef0ca48d2f8c5da63d34baf8a2fdb5 Mon Sep 17 00:00:00 2001
+From: Angus Salkeld <asalkeld at redhat.com>
+Date: Thu, 12 Dec 2013 13:18:11 +1100
+Subject: [PATCH] Add support for resource_types
+
+This adds the following commands:
+$ heat resource-type-list
+$ heat resource-type-show <resource type>
+
+Change-Id: Ifa70da5bc56a5f2979697a9ce2c41fa9a5c1f947
+Closes-bug: #1260130
+(cherry picked from commit b14697ea3fada6e9f6725fa14e9c669beebd8875)
+
+Conflicts:
+	heatclient/v1/client.py
+---
+ heatclient/tests/test_resource_types.py | 45 +++++++++++++++++++++++++++++++
+ heatclient/v1/client.py                 | 13 +++++----
+ heatclient/v1/resource_types.py         | 47 +++++++++++++++++++++++++++++++++
+ heatclient/v1/shell.py                  | 20 ++++++++++++++
+ 4 files changed, 120 insertions(+), 5 deletions(-)
+ create mode 100644 heatclient/tests/test_resource_types.py
+ create mode 100644 heatclient/v1/resource_types.py
+
+diff --git a/heatclient/tests/test_resource_types.py b/heatclient/tests/test_resource_types.py
+new file mode 100644
+index 0000000..4030fd8
+--- /dev/null
++++ b/heatclient/tests/test_resource_types.py
+@@ -0,0 +1,45 @@
++#
++#    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 mock
++import testtools
++
++from heatclient.v1.resource_types import ResourceTypeManager
++
++
++class ResourceTypeManagerTest(testtools.TestCase):
++
++    def test_list_types(self):
++        manager = ResourceTypeManager(None)
++        manager._list = mock.MagicMock()
++        manager.list()
++        manager._list.assert_called_once_with('/resource_types',
++                                              'resource_types')
++
++    def test_get(self):
++        resource_type = u'OS::Nova::KeyPair'
++
++        class FakeAPI(object):
++            """Fake API and ensure request url is correct."""
++            def __init__(self, *args, **kwargs):
++                self.requests = []
++
++            def json_request(self, *args, **kwargs):
++                self.requests.append(args)
++                return {}, {'attributes': [], 'properties': []}
++
++        test_api = FakeAPI()
++        manager = ResourceTypeManager(test_api)
++        manager.get(resource_type)
++        expect = ('GET', '/resource_types/OS%3A%3ANova%3A%3AKeyPair')
++        self.assertIn(expect, test_api.requests)
+diff --git a/heatclient/v1/client.py b/heatclient/v1/client.py
+index 3ec6be6..940a94a 100644
+--- a/heatclient/v1/client.py
++++ b/heatclient/v1/client.py
+@@ -16,6 +16,7 @@
+ from heatclient.common import http
+ from heatclient.v1 import actions
+ from heatclient.v1 import events
++from heatclient.v1 import resource_types
+ from heatclient.v1 import resources
+ from heatclient.v1 import stacks
+ 
+@@ -32,8 +33,10 @@ class Client(http.HTTPClient):
+ 
+     def __init__(self, *args, **kwargs):
+         """Initialize a new client for the Heat v1 API."""
+-        super(Client, self).__init__(*args, **kwargs)
+-        self.stacks = stacks.StackManager(self)
+-        self.resources = resources.ResourceManager(self)
+-        self.events = events.EventManager(self)
+-        self.actions = actions.ActionManager(self)
++        self.http_client = http.HTTPClient(*args, **kwargs)
++        self.stacks = stacks.StackManager(self.http_client)
++        self.resources = resources.ResourceManager(self.http_client)
++        self.resource_types = resource_types.ResourceTypeManager(
++            self.http_client)
++        self.events = events.EventManager(self.http_client)
++        self.actions = actions.ActionManager(self.http_client)
+diff --git a/heatclient/v1/resource_types.py b/heatclient/v1/resource_types.py
+new file mode 100644
+index 0000000..2600197
+--- /dev/null
++++ b/heatclient/v1/resource_types.py
+@@ -0,0 +1,47 @@
++#
++#    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 heatclient.common import base
++from heatclient.openstack.common.py3kcompat import urlutils
++from heatclient.openstack.common import strutils
++
++
++class ResourceType(base.Resource):
++    def __repr__(self):
++        return "<ResourceType %s>" % self._info
++
++    def data(self, **kwargs):
++        return self.manager.data(self, **kwargs)
++
++    def _add_details(self, info):
++        self.resource_type = info
++
++
++class ResourceTypeManager(base.Manager):
++    resource_class = ResourceType
++
++    def list(self):
++        """Get a list of resource types.
++        :rtype: list of :class:`ResourceType`
++        """
++        return self._list('/resource_types', 'resource_types')
++
++    def get(self, resource_type):
++        """Get the details for a specific resource_type.
++
++        :param resource_type: name of the resource type to get the details for
++        """
++        url_str = '/resource_types/%s' % (
++                  urlutils.quote(strutils.safe_encode(resource_type), ''))
++        resp, body = self.api.json_request('GET', url_str)
++        return body
+diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py
+index d98b6a7..c3e6396 100644
+--- a/heatclient/v1/shell.py
++++ b/heatclient/v1/shell.py
+@@ -293,6 +293,26 @@ def do_stack_list(hc, args={}):
+     utils.print_list(stacks, fields, sortby=3)
+ 
+ 
++def do_resource_type_list(hc, args={}):
++    '''List the available resource types.'''
++    kwargs = {}
++    types = hc.resource_types.list(**kwargs)
++    utils.print_list(types, ['resource_type'])
++
++
++ at utils.arg('resource_type', metavar='<RESOURCE_TYPE>',
++           help='Resource Type to get the details for.')
++def do_resource_type_show(hc, args={}):
++    '''Show the resource type.'''
++    try:
++        resource_type = hc.resource_types.get(args.resource_type)
++    except exc.HTTPNotFound:
++        raise exc.CommandError(
++            'Resource Type not found: %s' % args.resource_type)
++    else:
++        print(json.dumps(resource_type, indent=2))
++
++
+ @utils.arg('id', metavar='<NAME or ID>',
+            help='Name or ID of stack to get the template for.')
+ def do_gettemplate(hc, args):
diff --git a/python-heatclient.spec b/python-heatclient.spec
index 66e981a..c426a19 100644
--- a/python-heatclient.spec
+++ b/python-heatclient.spec
@@ -1,6 +1,6 @@
 Name:    python-heatclient
 Version: 0.2.6
-Release: 1%{?dist}
+Release: 2%{?dist}
 Summary: Python API and CLI for OpenStack Heat
 
 Group:   Development/Languages
@@ -13,6 +13,7 @@ Source0: http://tarballs.openstack.org/%{name}/%{name}-%{version}.tar.gz
 #
 Patch0001: 0001-Nuke-pbr-requirements-handling.patch
 Patch0002: 0002-Remove-runtime-dependency-on-python-pbr.patch
+Patch0003: 0003-Add-support-for-resource_types.patch
 
 BuildArch: noarch
 
@@ -52,6 +53,7 @@ This package contains auto-generated documentation.
 
 %patch0001 -p1
 %patch0002 -p1
+%patch0003 -p1
 
 # We provide version like this in order to remove runtime dep on pbr.
 sed -i s/REDHATHEATCLIENTVERSION/%{version}/ heatclient/__init__.py
@@ -82,6 +84,9 @@ rm -fr html/.doctrees html/.buildinfo
 %doc html
 
 %changelog
+* Mon Jan 06 2014 Jakub Ruzicka <jruzicka at redhat.com> 0.2.6-2
+- Add support for resource_types
+
 * Tue Dec 10 2013 Jakub Ruzicka <jruzicka at redhat.com> 0.2.6-1
 - Update to upstream 0.2.6
 - New dependency: python-six


More information about the scm-commits mailing list