diff --git a/heatclient/tests/functional/test_readonly_heat.py b/heatclient/tests/functional/test_readonly_heat.py index 63e25884..e49c1e9a 100644 --- a/heatclient/tests/functional/test_readonly_heat.py +++ b/heatclient/tests/functional/test_readonly_heat.py @@ -94,3 +94,9 @@ class SimpleReadOnlyHeatClientTest(base.ClientTestBase): ret = self.heat('template-version-list') tmpl_types = self.parser.listing(ret) self.assertTableStruct(tmpl_types, ['version', 'type']) + + def test_heat_template_function_list(self): + ret = self.heat('template-function-list ' + 'heat_template_version.2013-05-23') + tmpl_functions = self.parser.listing(ret) + self.assertTableStruct(tmpl_functions, ['functions', 'description']) diff --git a/heatclient/tests/unit/test_template_versions.py b/heatclient/tests/unit/test_template_versions.py index 0582f45e..fe3cd098 100644 --- a/heatclient/tests/unit/test_template_versions.py +++ b/heatclient/tests/unit/test_template_versions.py @@ -38,3 +38,20 @@ class TemplateVersionManagerTest(testtools.TestCase): versions = manager.list() self.assertEqual('2013-05-23', getattr(versions[0], 'version')) self.assertEqual('hot', getattr(versions[0], 'type')) + + def test_get(self): + expect = ('GET', '/template_versions/heat_template_version.2015-04-30' + '/functions') + + class FakeResponse(object): + def json(self): + return {'template_functions': [{'function': 'get_attr'}]} + + class FakeClient(object): + def get(self, *args, **kwargs): + assert ('GET', args[0]) == expect + return FakeResponse() + + manager = template_versions.TemplateVersionManager(FakeClient()) + functions = manager.get('heat_template_version.2015-04-30') + self.assertEqual('get_attr', getattr(functions[0], 'function')) diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index fd26316d..cde8d54a 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -1404,3 +1404,16 @@ def do_template_version_list(hc, args): versions = hc.template_versions.list() fields = ['version', 'type'] utils.print_list(versions, fields, sortby_index=1) + + +@utils.arg('template_version', metavar='', + help=_('Template version to get the functions for.')) +def do_template_function_list(hc, args): + '''List the available functions.''' + try: + functions = hc.template_versions.get(args.template_version) + except exc.HTTPNotFound: + raise exc.CommandError( + _('Template version not found: %s') % args.template_version) + else: + utils.print_list(functions, ['functions', 'description']) diff --git a/heatclient/v1/template_versions.py b/heatclient/v1/template_versions.py index 9b764b52..3ba4c630 100644 --- a/heatclient/v1/template_versions.py +++ b/heatclient/v1/template_versions.py @@ -11,6 +11,9 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_utils import encodeutils +from six.moves.urllib import parse + from heatclient.openstack.common.apiclient import base @@ -30,3 +33,12 @@ class TemplateVersionManager(base.BaseManager): :rtype: list of :class:`TemplateVersion` """ return self._list('/template_versions', 'template_versions') + + def get(self, template_version): + """Get a list of functions for a specific resource_type. + + :param template_version: template version to get the functions for + """ + url_str = '/template_versions/%s/functions' % ( + parse.quote(encodeutils.safe_encode(template_version), '')) + return self._list(url_str, 'template_functions')