summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-12-07 06:11:19 +0000
committerGerrit Code Review <review@openstack.org>2017-12-07 06:11:19 +0000
commit22ae4cf93788c73ccdd639423989f70be339dbac (patch)
tree830ccae9fec431dbe6beb32dde6a5ad7a2546f15
parent8c4db024188f7e70ca70b0effd1584c947ce1825 (diff)
parent71a691ffaaf198969c70596a0e7083927c363658 (diff)
Merge "Add cluster-show to OSC"
-rw-r--r--releasenotes/notes/add-cluster-show-to-osc-5925431f5e94a746.yaml5
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_clusters.py38
-rw-r--r--troveclient/tests/osc/v1/test_database_clusters.py31
4 files changed, 75 insertions, 0 deletions
diff --git a/releasenotes/notes/add-cluster-show-to-osc-5925431f5e94a746.yaml b/releasenotes/notes/add-cluster-show-to-osc-5925431f5e94a746.yaml
new file mode 100644
index 0000000..e13e798
--- /dev/null
+++ b/releasenotes/notes/add-cluster-show-to-osc-5925431f5e94a746.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - The command ``trove cluster-show`` is now available to use in
4 the python-openstackclient CLI as ``openstack database cluster
5 show``
diff --git a/setup.cfg b/setup.cfg
index cb80903..d8aba3e 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -33,6 +33,7 @@ openstack.database.v1 =
33 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups 33 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups
34 database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup 34 database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup
35 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters 35 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
36 database_cluster_show = troveclient.osc.v1.database_clusters:ShowDatabaseCluster
36 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations 37 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
37 database_configuration_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfiguration 38 database_configuration_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfiguration
38 database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors 39 database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors
diff --git a/troveclient/osc/v1/database_clusters.py b/troveclient/osc/v1/database_clusters.py
index 13bad6c..7cd034b 100644
--- a/troveclient/osc/v1/database_clusters.py
+++ b/troveclient/osc/v1/database_clusters.py
@@ -14,10 +14,29 @@
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(cluster):
23 info = cluster._info.copy()
24 if hasattr(cluster, 'datastore'):
25 info['datastore'] = cluster.datastore['type']
26 info['datastore_version'] = cluster.datastore['version']
27 if hasattr(cluster, 'task'):
28 info['task_description'] = cluster.task['description']
29 info['task_name'] = cluster.task['name']
30 info.pop('task', None)
31 if hasattr(cluster, 'ip'):
32 info['ip'] = ', '.join(cluster.ip)
33 instances = info.pop('instances', None)
34 if instances:
35 info['instance_count'] = len(instances)
36 info.pop('links', None)
37 return info
38
39
21class ListDatabaseClusters(command.Lister): 40class ListDatabaseClusters(command.Lister):
22 41
23 _description = _("List database clusters") 42 _description = _("List database clusters")
@@ -59,3 +78,22 @@ class ListDatabaseClusters(command.Lister):
59 clusters = [utils.get_item_properties(c, self.columns) 78 clusters = [utils.get_item_properties(c, self.columns)
60 for c in clusters] 79 for c in clusters]
61 return self.columns, clusters 80 return self.columns, clusters
81
82
83class ShowDatabaseCluster(command.ShowOne):
84 _description = _("Shows details of a database cluster")
85
86 def get_parser(self, prog_name):
87 parser = super(ShowDatabaseCluster, self).get_parser(prog_name)
88 parser.add_argument(
89 'cluster',
90 metavar='<cluster>',
91 help=_('ID or name of the cluster'),
92 )
93 return parser
94
95 def take_action(self, parsed_args):
96 database_clusters = self.app.client_manager.database.clusters
97 cluster = utils.find_resource(database_clusters, parsed_args.cluster)
98 cluster = set_attributes_for_print_detail(cluster)
99 return zip(*sorted(six.iteritems(cluster)))
diff --git a/troveclient/tests/osc/v1/test_database_clusters.py b/troveclient/tests/osc/v1/test_database_clusters.py
index abd4bcf..ca13de9 100644
--- a/troveclient/tests/osc/v1/test_database_clusters.py
+++ b/troveclient/tests/osc/v1/test_database_clusters.py
@@ -46,3 +46,34 @@ class TestClusterList(TestClusters):
46 self.cluster_client.list.assert_called_once_with(**self.defaults) 46 self.cluster_client.list.assert_called_once_with(**self.defaults)
47 self.assertEqual(self.columns, columns) 47 self.assertEqual(self.columns, columns)
48 self.assertEqual([self.values], data) 48 self.assertEqual([self.values], data)
49
50
51class TestClusterShow(TestClusters):
52
53 values = ('2015-05-02T10:37:04', 'vertica', '7.1', 'cls-1234', 2,
54 'test-clstr', 'No tasks for the cluster.', 'NONE',
55 '2015-05-02T11:06:19')
56
57 def setUp(self):
58 super(TestClusterShow, self).setUp()
59 self.cmd = database_clusters.ShowDatabaseCluster(self.app, None)
60 self.data = self.fake_clusters.get_clusters_cls_1234()
61 self.cluster_client.get.return_value = self.data
62 self.columns = (
63 'created',
64 'datastore',
65 'datastore_version',
66 'id',
67 'instance_count',
68 'name',
69 'task_description',
70 'task_name',
71 'updated',
72 )
73
74 def test_show(self):
75 args = ['cls-1234']
76 parsed_args = self.check_parser(self.cmd, args, [])
77 columns, data = self.cmd.take_action(parsed_args)
78 self.assertEqual(self.columns, columns)
79 self.assertEqual(self.values, data)