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
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- The command ``trove flavor-show`` is now available to use in
|
||||||
|
the python-openstackclient CLI as ``openstack database flavor
|
||||||
|
show``
|
@@ -34,6 +34,7 @@ openstack.database.v1 =
|
|||||||
database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
|
database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
|
||||||
database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
|
database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
|
||||||
database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors
|
database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors
|
||||||
|
database_flavor_show = troveclient.osc.v1.database_flavors:ShowDatabaseFlavor
|
||||||
database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
|
database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
|
||||||
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
|
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
|
||||||
database_list = troveclient.osc.v1.databases:ListDatabases
|
database_list = troveclient.osc.v1.databases:ListDatabases
|
||||||
|
@@ -14,11 +14,25 @@
|
|||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
import six
|
||||||
|
|
||||||
from troveclient import exceptions
|
from troveclient import exceptions
|
||||||
from troveclient.i18n import _
|
from troveclient.i18n import _
|
||||||
|
|
||||||
|
|
||||||
|
def set_attributes_for_print_detail(flavor):
|
||||||
|
info = flavor._info.copy()
|
||||||
|
# Get rid of those ugly links
|
||||||
|
if info.get('links'):
|
||||||
|
del(info['links'])
|
||||||
|
|
||||||
|
# Fallback to str_id for flavors, where necessary
|
||||||
|
if hasattr(flavor, 'str_id'):
|
||||||
|
info['id'] = flavor.id
|
||||||
|
del(info['str_id'])
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
class ListDatabaseFlavors(command.Lister):
|
class ListDatabaseFlavors(command.Lister):
|
||||||
|
|
||||||
_description = _("List database flavors")
|
_description = _("List database flavors")
|
||||||
@@ -61,3 +75,23 @@ class ListDatabaseFlavors(command.Lister):
|
|||||||
_flavors.append(utils.get_item_properties(f, self.columns))
|
_flavors.append(utils.get_item_properties(f, self.columns))
|
||||||
|
|
||||||
return self.columns, _flavors
|
return self.columns, _flavors
|
||||||
|
|
||||||
|
|
||||||
|
class ShowDatabaseFlavor(command.ShowOne):
|
||||||
|
_description = _("Shows details of a database flavor")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShowDatabaseFlavor, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'flavor',
|
||||||
|
metavar='<flavor>',
|
||||||
|
help=_('ID or name of the flavor'),
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
db_flavors = self.app.client_manager.database.flavors
|
||||||
|
flavor = utils.find_resource(db_flavors,
|
||||||
|
parsed_args.flavor)
|
||||||
|
flavor = set_attributes_for_print_detail(flavor)
|
||||||
|
return zip(*sorted(six.iteritems(flavor)))
|
||||||
|
@@ -39,3 +39,26 @@ class TestFlavorList(TestFlavors):
|
|||||||
self.flavor_client.list.assert_called_once_with()
|
self.flavor_client.list.assert_called_once_with()
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual([self.values], values)
|
self.assertEqual([self.values], values)
|
||||||
|
|
||||||
|
|
||||||
|
class TestFlavorShow(TestFlavors):
|
||||||
|
|
||||||
|
values = (1, 'm1.tiny', 512)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestFlavorShow, self).setUp()
|
||||||
|
self.cmd = database_flavors.ShowDatabaseFlavor(self.app, None)
|
||||||
|
self.data = self.fake_flavors.get_flavors_1()
|
||||||
|
self.flavor_client.get.return_value = self.data
|
||||||
|
self.columns = (
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'ram',
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_flavor_show_defaults(self):
|
||||||
|
args = ['m1.tiny']
|
||||||
|
parsed_args = self.check_parser(self.cmd, args, [])
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.values, data)
|
||||||
|
Reference in New Issue
Block a user