summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--heatclient/osc/v1/template.py37
-rw-r--r--heatclient/tests/unit/osc/v1/test_template.py33
-rw-r--r--setup.cfg1
3 files changed, 71 insertions, 0 deletions
diff --git a/heatclient/osc/v1/template.py b/heatclient/osc/v1/template.py
index c6e24b9..57d4964 100644
--- a/heatclient/osc/v1/template.py
+++ b/heatclient/osc/v1/template.py
@@ -17,6 +17,9 @@ import logging
from cliff import lister
from openstackclient.common import utils
+from heatclient import exc
+from heatclient.openstack.common._i18n import _
+
class VersionList(lister.Lister):
"""List the available template versions."""
@@ -35,3 +38,37 @@ class VersionList(lister.Lister):
fields,
(utils.get_item_properties(s, fields) for s in versions)
)
+
+
+class FunctionList(lister.Lister):
+ """List the available functions."""
+
+ log = logging.getLogger(__name__ + '.FunctionList')
+
+ def get_parser(self, prog_name):
+ parser = super(FunctionList, self).get_parser(prog_name)
+ parser.add_argument(
+ 'template_version',
+ metavar='<TEMPLATE_VERSION>',
+ help=_('Template version to get the functions for')
+ )
+
+ return parser
+
+ def take_action(self, parsed_args):
+ self.log.debug('take_action(%s)', parsed_args)
+
+ client = self.app.client_manager.orchestration
+
+ version = parsed_args.template_version
+ try:
+ functions = client.template_versions.get(version)
+ except exc.HTTPNotFound:
+ msg = _('Template version not found: %s') % version
+ raise exc.CommandError(msg)
+
+ fields = ['functions', 'description']
+ return (
+ fields,
+ (utils.get_item_properties(s, fields) for s in functions)
+ )
diff --git a/heatclient/tests/unit/osc/v1/test_template.py b/heatclient/tests/unit/osc/v1/test_template.py
index f5d0169..17b14e7 100644
--- a/heatclient/tests/unit/osc/v1/test_template.py
+++ b/heatclient/tests/unit/osc/v1/test_template.py
@@ -14,6 +14,7 @@
import mock
+from heatclient import exc
from heatclient.osc.v1 import template
from heatclient.tests.unit.osc.v1 import fakes
from heatclient.v1 import template_versions
@@ -47,3 +48,35 @@ class TestTemplateVersionList(TestTemplate):
self.assertEqual(['version', 'type'], columns)
self.assertEqual([('HOT123', 'hot'), ('CFN456', 'cfn')], list(data))
+
+
+class TestTemplateFunctionList(TestTemplate):
+
+ defaults = [
+ {'functions': 'func1', 'description': 'Function 1'},
+ {'functions': 'func2', 'description': 'Function 2'}
+ ]
+
+ def setUp(self):
+ super(TestTemplateFunctionList, self).setUp()
+ tv1 = template_versions.TemplateVersion(None, self.defaults[0])
+ tv2 = template_versions.TemplateVersion(None, self.defaults[1])
+ self.template_versions.get = mock.MagicMock(return_value=[tv1, tv2])
+ self.cmd = template.FunctionList(self.app, None)
+
+ def test_function_list(self):
+ arglist = ['version1']
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.assertEqual(['functions', 'description'], columns)
+ self.assertEqual([('func1', 'Function 1'), ('func2', 'Function 2')],
+ list(data))
+
+ def test_function_list_not_found(self):
+ arglist = ['bad_version']
+ self.template_versions.get.side_effect = exc.HTTPNotFound
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+
+ self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
diff --git a/setup.cfg b/setup.cfg
index 9d07cb1..417287a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -41,6 +41,7 @@ openstack.orchestration.v1 =
stack_adopt = heatclient.osc.v1.stack:AdoptStack
stack_abandon = heatclient.osc.v1.stack:AbandonStack
orchestration_template_version_list = heatclient.osc.v1.template:VersionList
+ orchestration_template_function_list = heatclient.osc.v1.template:FunctionList
[global]