summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Vanderwiel <vanderwl@us.ibm.com>2016-01-21 14:15:18 -0600
committerMark Vanderwiel <vanderwl@us.ibm.com>2016-02-09 11:59:26 -0600
commit6c8e03798cfee90980752123a1c6f23f25346145 (patch)
treef0531687f31e294c7288643295b3625913cb48f9
parentd1116972d53993b7d2dbef52a6d4c3d57e746d59 (diff)
downloadpython-heatclient-6c8e03798cfee90980752123a1c6f23f25346145.tar.gz
Add openstack client software config list
Add the openstack software config list command. Based from the existing heat commands: heat config-list Change-Id: I2016d859bbfcc4759a9032af73218e3cbc801594 Blueprint: heat-support-python-openstackclient
-rw-r--r--heatclient/osc/v1/software_config.py39
-rw-r--r--heatclient/tests/unit/osc/v1/test_sotware_config.py29
-rw-r--r--setup.cfg1
3 files changed, 69 insertions, 0 deletions
diff --git a/heatclient/osc/v1/software_config.py b/heatclient/osc/v1/software_config.py
index 033fc6d..c0ea931 100644
--- a/heatclient/osc/v1/software_config.py
+++ b/heatclient/osc/v1/software_config.py
@@ -16,7 +16,9 @@
import logging
from cliff import command
+from cliff import lister
from openstackclient.common import exceptions as exc
+from openstackclient.common import utils
from heatclient import exc as heat_exc
from heatclient.openstack.common._i18n import _
@@ -62,3 +64,40 @@ def _delete_config(heat_client, args):
'%(total)s software configs.') %
{'count': failure_count,
'total': len(args.id)})
+
+
+class ListConfig(lister.Lister):
+ """List software configs"""
+
+ log = logging.getLogger(__name__ + ".ListConfig")
+
+ def get_parser(self, prog_name):
+ parser = super(ListConfig, self).get_parser(prog_name)
+ parser.add_argument(
+ '--limit',
+ metavar='<LIMIT>',
+ help=_('Limit the number of configs returned')
+ )
+ parser.add_argument(
+ '--marker',
+ metavar='<ID>',
+ help=_('Return configs that appear after the given config ID')
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ self.log.debug("take_action(%s)", parsed_args)
+ heat_client = self.app.client_manager.orchestration
+ return _list_config(heat_client, parsed_args)
+
+
+def _list_config(heat_client, args):
+ kwargs = {}
+ if args.limit:
+ kwargs['limit'] = args.limit
+ if args.marker:
+ kwargs['marker'] = args.marker
+ scs = heat_client.software_configs.list(**kwargs)
+
+ columns = ['id', 'name', 'group', 'creation_time']
+ return (columns, (utils.get_item_properties(s, columns) for s in scs))
diff --git a/heatclient/tests/unit/osc/v1/test_sotware_config.py b/heatclient/tests/unit/osc/v1/test_sotware_config.py
index 6f01804..00260fa 100644
--- a/heatclient/tests/unit/osc/v1/test_sotware_config.py
+++ b/heatclient/tests/unit/osc/v1/test_sotware_config.py
@@ -18,6 +18,7 @@ from openstackclient.common import exceptions as exc
from heatclient import exc as heat_exc
from heatclient.osc.v1 import software_config
from heatclient.tests.unit.osc.v1 import fakes as orchestration_fakes
+from heatclient.v1 import software_configs
class TestConfig(orchestration_fakes.TestOrchestrationv1):
@@ -62,3 +63,31 @@ class TestDeleteConfig(TestConfig):
mock.call(config_id='id_789')])
self.assertEqual('Unable to delete 1 of the 3 software configs.',
str(error))
+
+
+class TestListConfig(TestConfig):
+
+ def setUp(self):
+ super(TestListConfig, self).setUp()
+ self.cmd = software_config.ListConfig(self.app, None)
+ self.mock_client.software_configs.list = mock.Mock(
+ return_value=[software_configs.SoftwareConfig(None, {})])
+
+ def test_config_list(self):
+ arglist = []
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+ self.cmd.take_action(parsed_args)
+ self.mock_client.software_configs.list.assert_called_once_with()
+
+ def test_config_list_limit(self):
+ arglist = ['--limit', '3']
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+ self.cmd.take_action(parsed_args)
+ self.mock_client.software_configs.list.assert_called_with(limit='3')
+
+ def test_config_list_marker(self):
+ arglist = ['--marker', 'id123']
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+ self.cmd.take_action(parsed_args)
+ self.mock_client.software_configs.list.assert_called_with(
+ marker='id123')
diff --git a/setup.cfg b/setup.cfg
index 9f32019..bea4662 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -33,6 +33,7 @@ openstack.orchestration.v1 =
orchestration_template_function_list = heatclient.osc.v1.template:FunctionList
orchestration_template_version_list = heatclient.osc.v1.template:VersionList
software_config_delete = heatclient.osc.v1.software_config:DeleteConfig
+ software_config_list = heatclient.osc.v1.software_config:ListConfig
software_deployment_delete = heatclient.osc.v1.software_deployment:DeleteDeployment
software_deployment_list = heatclient.osc.v1.software_deployment:ListDeployment
stack_abandon = heatclient.osc.v1.stack:AbandonStack