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
This commit is contained in:
Angus Salkeld
2013-12-12 13:18:11 +11:00
parent 89282eb2eb
commit b14697ea3f
4 changed files with 115 additions and 0 deletions

View File

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

View File

@@ -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
@@ -35,5 +36,7 @@ class Client(object):
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)

View File

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

View File

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