Repository: libcloud Updated Branches: refs/heads/trunk b5592af8b -> 8a9ffd1df
openstack: add get_user method libcloud's OpenStack compute nodes have a "userId" value in node.extra. Add a new get_user() method to the OpenStackIdentityConnection v3 class to look up this user by the user ID value. This allows callers to discover more information about the user that created a node (for example). Signed-off-by: Quentin Pradet <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/72722703 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/72722703 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/72722703 Branch: refs/heads/trunk Commit: 72722703110fc66d4919d6779297e3b85f253174 Parents: b5592af Author: Ken Dreyer <[email protected]> Authored: Fri Jun 1 11:04:09 2018 -0600 Committer: Quentin Pradet <[email protected]> Committed: Fri Jul 6 10:15:42 2018 +0400 ---------------------------------------------------------------------- libcloud/common/openstack_identity.py | 14 ++++++++++++++ libcloud/test/common/test_openstack_identity.py | 11 +++++++++++ 2 files changed, 25 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/72722703/libcloud/common/openstack_identity.py ---------------------------------------------------------------------- diff --git a/libcloud/common/openstack_identity.py b/libcloud/common/openstack_identity.py index 4285933..3d09681 100644 --- a/libcloud/common/openstack_identity.py +++ b/libcloud/common/openstack_identity.py @@ -1130,6 +1130,20 @@ class OpenStackIdentity_3_0_Connection(OpenStackIdentityConnection): result = self._to_domain(data=response.object['domain']) return result + def get_user(self, user_id): + """ + Get a user account by ID. + + :param user_id: User's id. + :type name: ``str`` + + :return: Located user. + :rtype: :class:`.OpenStackIdentityUser` + """ + response = self.authenticated_request('/v3/users/%s' % user_id) + user = self._to_user(data=response.object['user']) + return user + def list_user_projects(self, user): """ Retrieve all the projects user belongs to. http://git-wip-us.apache.org/repos/asf/libcloud/blob/72722703/libcloud/test/common/test_openstack_identity.py ---------------------------------------------------------------------- diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py index c36f13a..916193f 100644 --- a/libcloud/test/common/test_openstack_identity.py +++ b/libcloud/test/common/test_openstack_identity.py @@ -366,6 +366,13 @@ class OpenStackIdentity_3_0_ConnectionTests(unittest.TestCase): domain = self.auth_instance.get_domain(domain_id='default') self.assertEqual(domain.name, 'Default') + def test_get_user(self): + user = self.auth_instance.get_user(user_id='a') + self.assertEqual(user.id, 'a') + self.assertEqual(user.domain_id, 'default') + self.assertEqual(user.enabled, True) + self.assertEqual(user.email, 'openstack-test@localhost') + def test_create_user(self): user = self.auth_instance.create_user(email='test2@localhost', password='test1', name='test2', domain_id='default') @@ -682,6 +689,10 @@ class OpenStackIdentity_3_0_MockHttp(MockHttp): raise NotImplementedError() def _v3_users_a(self, method, url, body, headers): + if method == 'GET': + # look up a user + body = self.fixtures.load('v3_users_a.json') + return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) if method == 'PATCH': # enable / disable user body = self.fixtures.load('v3_users_a.json')
