Add support for template-function-list command

Example:
  heat template-function-list <template_version>

DocImpact

Implements bp: template-function-list

Change-Id: I80fdd94c10be49f80bd8dab1288ad336d185f55d
This commit is contained in:
Tetiana Lashchova 2015-06-24 16:06:43 +03:00
parent 6c4d183f6e
commit a7067fbde7
4 changed files with 48 additions and 0 deletions

View File

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

View File

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

View File

@ -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='<TEMPLATE_VERSION>',
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'])

View File

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