summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-12-07 03:48:09 +0000
committerGerrit Code Review <review@openstack.org>2017-12-07 03:48:09 +0000
commit336b50b165512a975f7abce6c28e478982ab6a48 (patch)
tree19182a5f6926e3dd4faf49ac8bab21234b62de0e
parentbef72db102f3465f8900ddcdb78c6ba4bad6d6c1 (diff)
parent2db7bf24e4a23888f8b281927e9365ec1ce8a32c (diff)
Merge "Add datastore-show to OSC"
-rw-r--r--releasenotes/notes/add-datastore-show-to-osc-79a855d2e026ae80.yaml4
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/datastores.py36
-rw-r--r--troveclient/tests/osc/v1/test_datastores.py24
4 files changed, 65 insertions, 0 deletions
diff --git a/releasenotes/notes/add-datastore-show-to-osc-79a855d2e026ae80.yaml b/releasenotes/notes/add-datastore-show-to-osc-79a855d2e026ae80.yaml
new file mode 100644
index 0000000..a1ebd23
--- /dev/null
+++ b/releasenotes/notes/add-datastore-show-to-osc-79a855d2e026ae80.yaml
@@ -0,0 +1,4 @@
1---
2features:
3 - The command ``trove datastore-show`` is now available to use in
4 the python-openstackclient CLI as ``openstack datastore show``
diff --git a/setup.cfg b/setup.cfg
index d01ec4e..9def235 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -42,6 +42,7 @@ openstack.database.v1 =
42 database_list = troveclient.osc.v1.databases:ListDatabases 42 database_list = troveclient.osc.v1.databases:ListDatabases
43 database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers 43 database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
44 datastore_list = troveclient.osc.v1.datastores:ListDatastores 44 datastore_list = troveclient.osc.v1.datastores:ListDatastores
45 datastore_show = troveclient.osc.v1.datastores:ShowDatastore
45 46
46 47
47[build_sphinx] 48[build_sphinx]
diff --git a/troveclient/osc/v1/datastores.py b/troveclient/osc/v1/datastores.py
index eb63dc8..c28624c 100644
--- a/troveclient/osc/v1/datastores.py
+++ b/troveclient/osc/v1/datastores.py
@@ -14,10 +14,26 @@
14 14
15from osc_lib.command import command 15from osc_lib.command import command
16from osc_lib import utils 16from osc_lib import utils
17import six
17 18
18from troveclient.i18n import _ 19from troveclient.i18n import _
19 20
20 21
22def set_attributes_for_print_detail(datastore):
23 info = datastore._info.copy()
24 versions = info.get('versions', [])
25 versions_str = "\n".join(
26 [ver['name'] + " (" + ver['id'] + ")" for ver in versions])
27 info['versions (id)'] = versions_str
28 info.pop('versions', None)
29 info.pop('links', None)
30 if hasattr(datastore, 'default_version'):
31 def_ver_id = getattr(datastore, 'default_version')
32 info['default_version'] = [
33 ver['name'] for ver in versions if ver['id'] == def_ver_id][0]
34 return info
35
36
21class ListDatastores(command.Lister): 37class ListDatastores(command.Lister):
22 38
23 _description = _("List available datastores") 39 _description = _("List available datastores")
@@ -28,3 +44,23 @@ class ListDatastores(command.Lister):
28 datastores = datastore_client.list() 44 datastores = datastore_client.list()
29 ds = [utils.get_item_properties(d, self.columns) for d in datastores] 45 ds = [utils.get_item_properties(d, self.columns) for d in datastores]
30 return self.columns, ds 46 return self.columns, ds
47
48
49class ShowDatastore(command.ShowOne):
50 _description = _("Shows details of a datastore")
51
52 def get_parser(self, prog_name):
53 parser = super(ShowDatastore, self).get_parser(prog_name)
54 parser.add_argument(
55 'datastore',
56 metavar='<datastore>',
57 help=_('ID of the datastore'),
58 )
59 return parser
60
61 def take_action(self, parsed_args):
62 datastore_client = self.app.client_manager.database.datastores
63 datastore = utils.find_resource(datastore_client,
64 parsed_args.datastore)
65 datastore = set_attributes_for_print_detail(datastore)
66 return zip(*sorted(six.iteritems(datastore)))
diff --git a/troveclient/tests/osc/v1/test_datastores.py b/troveclient/tests/osc/v1/test_datastores.py
index 13e2c2f..a675175 100644
--- a/troveclient/tests/osc/v1/test_datastores.py
+++ b/troveclient/tests/osc/v1/test_datastores.py
@@ -39,3 +39,27 @@ class TestDatastoreList(TestDatastores):
39 self.datastore_client.list.assert_called_once_with() 39 self.datastore_client.list.assert_called_once_with()
40 self.assertEqual(self.columns, columns) 40 self.assertEqual(self.columns, columns)
41 self.assertEqual([self.values], data) 41 self.assertEqual([self.values], data)
42
43
44class TestDatastoreShow(TestDatastores):
45
46 values = ('5.6', 'd-123', 'mysql', '5.6 (v-56)')
47
48 def setUp(self):
49 super(TestDatastoreShow, self).setUp()
50 self.cmd = datastores.ShowDatastore(self.app, None)
51 self.data = self.fake_datastores.get_datastores_d_123()
52 self.datastore_client.get.return_value = self.data
53 self.columns = (
54 'default_version',
55 'id',
56 'name',
57 'versions (id)',
58 )
59
60 def test_show(self):
61 args = ['mysql']
62 parsed_args = self.check_parser(self.cmd, args, [])
63 columns, data = self.cmd.take_action(parsed_args)
64 self.assertEqual(self.columns, columns)
65 self.assertEqual(self.values, data)