summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangyao <wangyao@cmss.chinamobile.com>2017-12-01 17:02:27 +0800
committerwangyao <wangyao@cmss.chinamobile.com>2017-12-01 17:02:27 +0800
commit6a373890c360e37da29e616d97f6d276bbdf6d66 (patch)
tree2253a572cf558191d249797cf61d6daf1e27ed40
parent7e14c4f2b0a4a4243ff3977a4ca1ae280d2893b9 (diff)
Add flavor-show to OSC
This change adds database support to the python-openstackclient project for the flavor-show command. The trove command flavor-show is now: openstack database flavor show Change-Id: Ie91f81bad239869bba21e1358cc97e8efa7bf468 Partially-Implements: trove-support-in-python-openstackclient
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:15 +0000 Reviewed-on: https://review.openstack.org/524532 Project: openstack/python-troveclient Branch: refs/heads/master
-rw-r--r--releasenotes/notes/add-flavor-show-to-osc-16ab5640f144cab7.yaml5
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_flavors.py34
-rw-r--r--troveclient/tests/osc/v1/test_database_flavors.py23
4 files changed, 63 insertions, 0 deletions
diff --git a/releasenotes/notes/add-flavor-show-to-osc-16ab5640f144cab7.yaml b/releasenotes/notes/add-flavor-show-to-osc-16ab5640f144cab7.yaml
new file mode 100644
index 0000000..d0c400c
--- /dev/null
+++ b/releasenotes/notes/add-flavor-show-to-osc-16ab5640f144cab7.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - The command ``trove flavor-show`` is now available to use in
4 the python-openstackclient CLI as ``openstack database flavor
5 show``
diff --git a/setup.cfg b/setup.cfg
index bba3b9a..7dd8801 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -34,6 +34,7 @@ openstack.database.v1 =
34 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters 34 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
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_flavor_show = troveclient.osc.v1.database_flavors:ShowDatabaseFlavor
37 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances 38 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
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
diff --git a/troveclient/osc/v1/database_flavors.py b/troveclient/osc/v1/database_flavors.py
index f9fb3d0..33ef46f 100644
--- a/troveclient/osc/v1/database_flavors.py
+++ b/troveclient/osc/v1/database_flavors.py
@@ -14,11 +14,25 @@
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 import exceptions 19from troveclient import exceptions
19from troveclient.i18n import _ 20from troveclient.i18n import _
20 21
21 22
23def set_attributes_for_print_detail(flavor):
24 info = flavor._info.copy()
25 # Get rid of those ugly links
26 if info.get('links'):
27 del(info['links'])
28
29 # Fallback to str_id for flavors, where necessary
30 if hasattr(flavor, 'str_id'):
31 info['id'] = flavor.id
32 del(info['str_id'])
33 return info
34
35
22class ListDatabaseFlavors(command.Lister): 36class ListDatabaseFlavors(command.Lister):
23 37
24 _description = _("List database flavors") 38 _description = _("List database flavors")
@@ -61,3 +75,23 @@ class ListDatabaseFlavors(command.Lister):
61 _flavors.append(utils.get_item_properties(f, self.columns)) 75 _flavors.append(utils.get_item_properties(f, self.columns))
62 76
63 return self.columns, _flavors 77 return self.columns, _flavors
78
79
80class ShowDatabaseFlavor(command.ShowOne):
81 _description = _("Shows details of a database flavor")
82
83 def get_parser(self, prog_name):
84 parser = super(ShowDatabaseFlavor, self).get_parser(prog_name)
85 parser.add_argument(
86 'flavor',
87 metavar='<flavor>',
88 help=_('ID or name of the flavor'),
89 )
90 return parser
91
92 def take_action(self, parsed_args):
93 db_flavors = self.app.client_manager.database.flavors
94 flavor = utils.find_resource(db_flavors,
95 parsed_args.flavor)
96 flavor = set_attributes_for_print_detail(flavor)
97 return zip(*sorted(six.iteritems(flavor)))
diff --git a/troveclient/tests/osc/v1/test_database_flavors.py b/troveclient/tests/osc/v1/test_database_flavors.py
index 780abae..9a431d4 100644
--- a/troveclient/tests/osc/v1/test_database_flavors.py
+++ b/troveclient/tests/osc/v1/test_database_flavors.py
@@ -39,3 +39,26 @@ class TestFlavorList(TestFlavors):
39 self.flavor_client.list.assert_called_once_with() 39 self.flavor_client.list.assert_called_once_with()
40 self.assertEqual(self.columns, columns) 40 self.assertEqual(self.columns, columns)
41 self.assertEqual([self.values], values) 41 self.assertEqual([self.values], values)
42
43
44class TestFlavorShow(TestFlavors):
45
46 values = (1, 'm1.tiny', 512)
47
48 def setUp(self):
49 super(TestFlavorShow, self).setUp()
50 self.cmd = database_flavors.ShowDatabaseFlavor(self.app, None)
51 self.data = self.fake_flavors.get_flavors_1()
52 self.flavor_client.get.return_value = self.data
53 self.columns = (
54 'id',
55 'name',
56 'ram',
57 )
58
59 def test_flavor_show_defaults(self):
60 args = ['m1.tiny']
61 parsed_args = self.check_parser(self.cmd, args, [])
62 columns, data = self.cmd.take_action(parsed_args)
63 self.assertEqual(self.columns, columns)
64 self.assertEqual(self.values, data)