Add user-show to OSC
This change adds database support to the python-openstackclient project for the user-show command. The trove command user-show is now: openstack database user show Change-Id: I92455f1606c8a20b477fdbe66daf98e59cc19fd7 Partially-Implements: trove-support-in-python-openstackclient
This commit is contained in:
parent
22ae4cf937
commit
854d3e2a31
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- The command ``trove user-show`` is now available to use in
|
||||||
|
the python-openstackclient CLI as ``openstack database user
|
||||||
|
show``
|
|
@ -43,6 +43,7 @@ openstack.database.v1 =
|
||||||
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
|
||||||
database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
|
database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
|
||||||
|
database_user_show = troveclient.osc.v1.database_users:ShowDatabaseUser
|
||||||
datastore_list = troveclient.osc.v1.datastores:ListDatastores
|
datastore_list = troveclient.osc.v1.datastores:ListDatastores
|
||||||
datastore_show = troveclient.osc.v1.datastores:ShowDatastore
|
datastore_show = troveclient.osc.v1.datastores:ShowDatastore
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
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.i18n import _
|
from troveclient.i18n import _
|
||||||
|
|
||||||
|
@ -44,3 +45,33 @@ class ListDatabaseUsers(command.Lister):
|
||||||
user.databases = ', '.join(db_names)
|
user.databases = ', '.join(db_names)
|
||||||
users = [utils.get_item_properties(u, self.columns) for u in users]
|
users = [utils.get_item_properties(u, self.columns) for u in users]
|
||||||
return self.columns, users
|
return self.columns, users
|
||||||
|
|
||||||
|
|
||||||
|
class ShowDatabaseUser(command.ShowOne):
|
||||||
|
|
||||||
|
_description = _("Shows details of a database user of an instance.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShowDatabaseUser, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'instance',
|
||||||
|
metavar='<instance>',
|
||||||
|
help=_('ID of the instance.'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'name',
|
||||||
|
metavar='<name>',
|
||||||
|
help=_('Name of user.'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--host",
|
||||||
|
metavar="<host>",
|
||||||
|
help=_("Optional host of user."),
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
db_users = self.app.client_manager.database.users
|
||||||
|
user = db_users.get(parsed_args.instance, parsed_args.name,
|
||||||
|
hostname=parsed_args.host)
|
||||||
|
return zip(*sorted(six.iteritems(user._info)))
|
||||||
|
|
|
@ -40,3 +40,25 @@ class TestUserList(TestUsers):
|
||||||
self.user_client.list.assert_called_once_with(*args)
|
self.user_client.list.assert_called_once_with(*args)
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual([self.values], data)
|
self.assertEqual([self.values], data)
|
||||||
|
|
||||||
|
|
||||||
|
class TestUserShow(TestUsers):
|
||||||
|
values = ([{'name': 'db1'}], '%', 'harry')
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestUserShow, self).setUp()
|
||||||
|
self.cmd = database_users.ShowDatabaseUser(self.app, None)
|
||||||
|
self.data = self.fake_users.get_instances_1234_users_harry()
|
||||||
|
self.user_client.get.return_value = self.data
|
||||||
|
self.columns = (
|
||||||
|
'databases',
|
||||||
|
'host',
|
||||||
|
'name',
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_user_show_defaults(self):
|
||||||
|
args = ['my_instance', 'harry']
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in New Issue