Add support for template-version-list command
DocImpact Implements bp: template-version-list Change-Id: I80ae69ced9305f1e6883e6ca4902b5cc018b5e83
This commit is contained in:

committed by
Sergey Kraynev

parent
868a116f17
commit
20adfe3780
@@ -89,3 +89,8 @@ class SimpleReadOnlyHeatClientTest(base.ClientTestBase):
|
||||
|
||||
def test_heat_version(self):
|
||||
self.heat('', flags='--version')
|
||||
|
||||
def test_heat_template_version_list(self):
|
||||
ret = self.heat('template-version-list')
|
||||
tmpl_types = self.parser.listing(ret)
|
||||
self.assertTableStruct(tmpl_types, ['version', 'type'])
|
||||
|
40
heatclient/tests/unit/test_template_versions.py
Normal file
40
heatclient/tests/unit/test_template_versions.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#
|
||||
# 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 testtools
|
||||
|
||||
from heatclient.v1 import template_versions
|
||||
|
||||
|
||||
class TemplateVersionManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TemplateVersionManagerTest, self).setUp()
|
||||
|
||||
def test_list_versions(self):
|
||||
expect = ('GET', '/template_versions')
|
||||
|
||||
class FakeResponse(object):
|
||||
def json(self):
|
||||
return {'template_versions': [{'version': '2013-05-23',
|
||||
'type': 'hot'}]}
|
||||
|
||||
class FakeClient(object):
|
||||
def get(self, *args, **kwargs):
|
||||
assert ('GET', args[0]) == expect
|
||||
return FakeResponse()
|
||||
|
||||
manager = template_versions.TemplateVersionManager(FakeClient())
|
||||
versions = manager.list()
|
||||
self.assertEqual('2013-05-23', getattr(versions[0], 'version'))
|
||||
self.assertEqual('hot', getattr(versions[0], 'type'))
|
@@ -23,6 +23,7 @@ from heatclient.v1 import services
|
||||
from heatclient.v1 import software_configs
|
||||
from heatclient.v1 import software_deployments
|
||||
from heatclient.v1 import stacks
|
||||
from heatclient.v1 import template_versions
|
||||
|
||||
|
||||
class Client(object):
|
||||
@@ -51,3 +52,5 @@ class Client(object):
|
||||
self.software_configs = software_configs.SoftwareConfigManager(
|
||||
self.http_client)
|
||||
self.services = services.ServiceManager(self.http_client)
|
||||
self.template_versions = template_versions.TemplateVersionManager(
|
||||
self.http_client)
|
||||
|
@@ -1392,3 +1392,10 @@ def do_service_list(hc, args=None):
|
||||
'topic', 'updated_at', 'status']
|
||||
services = hc.services.list()
|
||||
utils.print_list(services, fields, sortby_index=1)
|
||||
|
||||
|
||||
def do_template_version_list(hc, args):
|
||||
'''List the available template versions.'''
|
||||
versions = hc.template_versions.list()
|
||||
fields = ['version', 'type']
|
||||
utils.print_list(versions, fields, sortby_index=1)
|
||||
|
32
heatclient/v1/template_versions.py
Normal file
32
heatclient/v1/template_versions.py
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# 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.openstack.common.apiclient import base
|
||||
|
||||
|
||||
class TemplateVersion(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<TemplateVersion %s>" % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class TemplateVersionManager(base.BaseManager):
|
||||
resource_class = TemplateVersion
|
||||
|
||||
def list(self):
|
||||
"""Get a list of template versions.
|
||||
:rtype: list of :class:`TemplateVersion`
|
||||
"""
|
||||
return self._list('/template_versions', 'template_versions')
|
Reference in New Issue
Block a user