Add user-update-attributes to OSC
This change adds database support to the python-openstackclient project for the user-update-attributes command. The trove command user-update-attributes is now: openstack database user update attributes Change-Id: I2acc85809cca4595c03a3d4252643a7806d5d791 Partially-Implements: blueprint trove-support-in-python-openstackclient
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The command ``trove user-update-attributes`` is now available to use in
|
||||||
|
the python-openstackclient CLI as
|
||||||
|
``openstack database user update attributes``
|
@@ -62,6 +62,7 @@ openstack.database.v1 =
|
|||||||
database_user_revoke_access = troveclient.osc.v1.database_users:RevokeDatabaseUserAccess
|
database_user_revoke_access = troveclient.osc.v1.database_users:RevokeDatabaseUserAccess
|
||||||
database_user_show = troveclient.osc.v1.database_users:ShowDatabaseUser
|
database_user_show = troveclient.osc.v1.database_users:ShowDatabaseUser
|
||||||
database_user_show_access = troveclient.osc.v1.database_users:ShowDatabaseUserAccess
|
database_user_show_access = troveclient.osc.v1.database_users:ShowDatabaseUserAccess
|
||||||
|
database_user_update_attributes = troveclient.osc.v1.database_users:UpdateDatabaseUserAttributes
|
||||||
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
|
||||||
datastore_version_list = troveclient.osc.v1.datastores:ListDatastoreVersions
|
datastore_version_list = troveclient.osc.v1.datastores:ListDatastoreVersions
|
||||||
|
@@ -274,3 +274,64 @@ class ShowDatabaseUserAccess(command.Lister):
|
|||||||
hostname=parsed_args.host)
|
hostname=parsed_args.host)
|
||||||
access = [utils.get_item_properties(n, self.columns) for n in names]
|
access = [utils.get_item_properties(n, self.columns) for n in names]
|
||||||
return self.columns, access
|
return self.columns, access
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateDatabaseUserAttributes(command.Command):
|
||||||
|
|
||||||
|
_description = _("Updates a user's attributes on an instance."
|
||||||
|
"At least one optional argument must be provided.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(UpdateDatabaseUserAttributes,
|
||||||
|
self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'instance',
|
||||||
|
metavar='<instance>',
|
||||||
|
help=_('ID or name of the instance.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'name',
|
||||||
|
metavar='<name>',
|
||||||
|
help=_('Name of user.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--host',
|
||||||
|
metavar='<host>',
|
||||||
|
default=None,
|
||||||
|
help=_('Optional host of user.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--new_name',
|
||||||
|
metavar='<new_name>',
|
||||||
|
default=None,
|
||||||
|
help=_('Optional new name of user.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--new_password',
|
||||||
|
metavar='<new_password>',
|
||||||
|
default=None,
|
||||||
|
help=_('Optional new password of user.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--new_host',
|
||||||
|
metavar='<new_host>',
|
||||||
|
default=None,
|
||||||
|
help=_('Optional new host of user.')
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
manager = self.app.client_manager.database
|
||||||
|
users = manager.users
|
||||||
|
instance = utils.find_resource(manager.instances,
|
||||||
|
parsed_args.instance)
|
||||||
|
new_attrs = {}
|
||||||
|
if parsed_args.new_name:
|
||||||
|
new_attrs['name'] = parsed_args.new_name
|
||||||
|
if parsed_args.new_password:
|
||||||
|
new_attrs['password'] = parsed_args.new_password
|
||||||
|
if parsed_args.new_host:
|
||||||
|
new_attrs['host'] = parsed_args.new_host
|
||||||
|
users.update_attributes(instance, parsed_args.name,
|
||||||
|
newuserattr=new_attrs,
|
||||||
|
hostname=parsed_args.host)
|
||||||
|
@@ -203,3 +203,31 @@ class TestDatabaseUserShowAccess(TestUsers):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.values, data)
|
self.assertEqual(self.values, data)
|
||||||
|
|
||||||
|
|
||||||
|
class TestDatabaseUserUpdateAttributes(TestUsers):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestDatabaseUserUpdateAttributes, self).setUp()
|
||||||
|
self.cmd = database_users.UpdateDatabaseUserAttributes(self.app, None)
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'find_resource')
|
||||||
|
def test_user__update_attributes(self, mock_find):
|
||||||
|
args = ['userinstance',
|
||||||
|
'user1',
|
||||||
|
'--host', '1.1.1.1',
|
||||||
|
'--new_name', 'user2',
|
||||||
|
'--new_password', '111111',
|
||||||
|
'--new_host', '1.1.1.2']
|
||||||
|
verifylist = [
|
||||||
|
('instance', 'userinstance'),
|
||||||
|
('name', 'user1'),
|
||||||
|
('host', '1.1.1.1'),
|
||||||
|
('new_name', 'user2'),
|
||||||
|
('new_password', '111111'),
|
||||||
|
('new_host', '1.1.1.2'),
|
||||||
|
]
|
||||||
|
mock_find.return_value = args[0]
|
||||||
|
parsed_args = self.check_parser(self.cmd, args, verifylist)
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
Reference in New Issue
Block a user