summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangyao <wangyao@cmss.chinamobile.com>2017-11-28 15:18:44 +0800
committerwangyao <wangyao@cmss.chinamobile.com>2017-12-03 21:19:52 +0800
commit1c1efa56d3c415215c5811b674d591584fbdab59 (patch)
tree9e85e0ea73db181034f09bbdee159fe8857779a3
parentdc48bc08359cdf0f1cccce02112218718979315e (diff)
Add show to OSC
This change adds database support to the python-openstackclient project for the show command. The trove command show is now: openstack database instance show Change-Id: I18580a7cc3394cecede18c15dc2fa9027ea842ba
Notes
Notes (review): Code-Review+2: Manoj Kumar <manoj@linux.vnet.ibm.com> Workflow+1: Manoj Kumar <manoj@linux.vnet.ibm.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 06 Dec 2017 19:15:14 +0000 Reviewed-on: https://review.openstack.org/523314 Project: openstack/python-troveclient Branch: refs/heads/master
-rw-r--r--releasenotes/notes/add-instance-show-to-osc-d97cac1c697dcbdd.yaml4
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_instances.py52
-rw-r--r--troveclient/tests/osc/v1/test_database_instances.py30
4 files changed, 87 insertions, 0 deletions
diff --git a/releasenotes/notes/add-instance-show-to-osc-d97cac1c697dcbdd.yaml b/releasenotes/notes/add-instance-show-to-osc-d97cac1c697dcbdd.yaml
new file mode 100644
index 0000000..306f3f6
--- /dev/null
+++ b/releasenotes/notes/add-instance-show-to-osc-d97cac1c697dcbdd.yaml
@@ -0,0 +1,4 @@
1---
2features:
3 - The command ``trove show`` is now available to use in
4 the python-openstackclient CLI as ``openstack database instance show``
diff --git a/setup.cfg b/setup.cfg
index bba3b9a..974446f 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -35,6 +35,7 @@ openstack.database.v1 =
35 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations 35 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
36 database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors 36 database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors
37 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances 37 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
38 database_instance_show = troveclient.osc.v1.database_instances:ShowDatabaseInstance
38 database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits 39 database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
39 database_list = troveclient.osc.v1.databases:ListDatabases 40 database_list = troveclient.osc.v1.databases:ListDatabases
40 database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers 41 database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py
index 43a8353..e5fef9d 100644
--- a/troveclient/osc/v1/database_instances.py
+++ b/troveclient/osc/v1/database_instances.py
@@ -14,6 +14,7 @@
14 14
15from osc_lib.command import command 15from osc_lib.command import command
16from osc_lib import utils as osc_utils 16from osc_lib import utils as osc_utils
17import six
17 18
18from troveclient.i18n import _ 19from troveclient.i18n import _
19 20
@@ -33,6 +34,38 @@ def set_attributes_for_print(instances):
33 return instances 34 return instances
34 35
35 36
37def set_attributes_for_print_detail(instance):
38 info = instance._info.copy()
39 info['flavor'] = instance.flavor['id']
40 if hasattr(instance, 'volume'):
41 info['volume'] = instance.volume['size']
42 if 'used' in instance.volume:
43 info['volume_used'] = instance.volume['used']
44 if hasattr(instance, 'ip'):
45 info['ip'] = ', '.join(instance.ip)
46 if hasattr(instance, 'datastore'):
47 info['datastore'] = instance.datastore['type']
48 info['datastore_version'] = instance.datastore['version']
49 if hasattr(instance, 'configuration'):
50 info['configuration'] = instance.configuration['id']
51 if hasattr(instance, 'replica_of'):
52 info['replica_of'] = instance.replica_of['id']
53 if hasattr(instance, 'replicas'):
54 replicas = [replica['id'] for replica in instance.replicas]
55 info['replicas'] = ', '.join(replicas)
56 if hasattr(instance, 'networks'):
57 info['networks'] = instance.networks['name']
58 info['networks_id'] = instance.networks['id']
59 if hasattr(instance, 'fault'):
60 info.pop('fault', None)
61 info['fault'] = instance.fault['message']
62 info['fault_date'] = instance.fault['created']
63 if 'details' in instance.fault and instance.fault['details']:
64 info['fault_details'] = instance.fault['details']
65 info.pop('links', None)
66 return info
67
68
36class ListDatabaseInstances(command.Lister): 69class ListDatabaseInstances(command.Lister):
37 70
38 _description = _("List database instances") 71 _description = _("List database instances")
@@ -81,3 +114,22 @@ class ListDatabaseInstances(command.Lister):
81 instances = [osc_utils.get_item_properties(i, self.columns) 114 instances = [osc_utils.get_item_properties(i, self.columns)
82 for i in instances] 115 for i in instances]
83 return self.columns, instances 116 return self.columns, instances
117
118
119class ShowDatabaseInstance(command.ShowOne):
120 _description = _("Show instance details")
121
122 def get_parser(self, prog_name):
123 parser = super(ShowDatabaseInstance, self).get_parser(prog_name)
124 parser.add_argument(
125 'instance',
126 metavar='<instance>',
127 help=_('Instance (name or ID)'),
128 )
129 return parser
130
131 def take_action(self, parsed_args):
132 db_instances = self.app.client_manager.database.instances
133 instance = osc_utils.find_resource(db_instances, parsed_args.instance)
134 instance = set_attributes_for_print_detail(instance)
135 return zip(*sorted(six.iteritems(instance)))
diff --git a/troveclient/tests/osc/v1/test_database_instances.py b/troveclient/tests/osc/v1/test_database_instances.py
index d05abf7..7cabf63 100644
--- a/troveclient/tests/osc/v1/test_database_instances.py
+++ b/troveclient/tests/osc/v1/test_database_instances.py
@@ -47,3 +47,33 @@ class TestInstanceList(TestInstances):
47 self.instance_client.list.assert_called_once_with(**self.defaults) 47 self.instance_client.list.assert_called_once_with(**self.defaults)
48 self.assertEqual(self.columns, columns) 48 self.assertEqual(self.columns, columns)
49 self.assertEqual([self.values], data) 49 self.assertEqual([self.values], data)
50
51
52class TestInstanceShow(TestInstances):
53
54 values = ('mysql', '5.6', '02', '1234', '10.0.0.13',
55 'test-member-1', 'regionOne', 'ACTIVE', 2)
56
57 def setUp(self):
58 super(TestInstanceShow, self).setUp()
59 self.cmd = database_instances.ShowDatabaseInstance(self.app, None)
60 self.data = self.fake_instances.get_instances_1234()
61 self.instance_client.get.return_value = self.data
62 self.columns = (
63 'datastore',
64 'datastore_version',
65 'flavor',
66 'id',
67 'ip',
68 'name',
69 'region',
70 'status',
71 'volume',
72 )
73
74 def test_show(self):
75 args = ['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)