mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-06 13:23:06 +00:00
Use proxy layer in identity_user_info
- Changes the module to get user through proxy layer - Adds a role to test the module - Renames the return value to drop openstack_ prefix Change-Id: I99e98a529ce74ff2ca77a67d09f188228e6a0e37
This commit is contained in:
committed by
Jakob Meng
parent
c83e0e39b1
commit
2df07f3523
@@ -25,6 +25,7 @@ options:
|
||||
- A dictionary of meta data to use for further filtering. Elements of
|
||||
this dictionary may be additional dictionaries.
|
||||
type: dict
|
||||
default: {}
|
||||
requirements:
|
||||
- "python >= 3.6"
|
||||
- "openstacksdk"
|
||||
@@ -39,7 +40,7 @@ EXAMPLES = '''
|
||||
cloud: awesomecloud
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_users }}"
|
||||
msg: "{{ result.users }}"
|
||||
|
||||
# Gather information about a previously created user by name
|
||||
- openstack.cloud.identity_user_info:
|
||||
@@ -47,7 +48,7 @@ EXAMPLES = '''
|
||||
name: demouser
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_users }}"
|
||||
msg: "{{ result.users }}"
|
||||
|
||||
# Gather information about a previously created user in a specific domain
|
||||
- openstack.cloud.identity_user_info:
|
||||
@@ -56,7 +57,7 @@ EXAMPLES = '''
|
||||
domain: admindomain
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_users }}"
|
||||
msg: "{{ result.users }}"
|
||||
|
||||
# Gather information about a previously created user in a specific domain with filter
|
||||
- openstack.cloud.identity_user_info:
|
||||
@@ -67,15 +68,16 @@ EXAMPLES = '''
|
||||
enabled: False
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.openstack_users }}"
|
||||
msg: "{{ result.users }}"
|
||||
'''
|
||||
|
||||
|
||||
RETURN = '''
|
||||
openstack_users:
|
||||
users:
|
||||
description: has all the OpenStack information about users
|
||||
returned: always, but can be null
|
||||
type: complex
|
||||
returned: always
|
||||
type: list
|
||||
elements: dict
|
||||
contains:
|
||||
id:
|
||||
description: Unique UUID.
|
||||
@@ -85,22 +87,39 @@ openstack_users:
|
||||
description: Username of the user.
|
||||
returned: success
|
||||
type: str
|
||||
enabled:
|
||||
description: Flag to indicate if the user is enabled
|
||||
returned: success
|
||||
type: bool
|
||||
domain_id:
|
||||
description: Domain ID containing the user
|
||||
returned: success
|
||||
type: str
|
||||
default_project_id:
|
||||
description: Default project ID of the user
|
||||
returned: success
|
||||
type: str
|
||||
domain_id:
|
||||
description: Domain ID containing the user
|
||||
returned: success
|
||||
type: str
|
||||
email:
|
||||
description: Email of the user
|
||||
returned: success
|
||||
type: str
|
||||
is_enabled:
|
||||
description: Flag to indicate if the user is enabled
|
||||
returned: success
|
||||
type: bool
|
||||
links:
|
||||
description: The links for the user resource
|
||||
returned: success
|
||||
type: complex
|
||||
contains:
|
||||
self:
|
||||
description: Link to this user resource
|
||||
returned: success
|
||||
type: str
|
||||
password:
|
||||
description: The default form of credential used during authentication.
|
||||
returned: success
|
||||
type: str
|
||||
password_expires_at:
|
||||
description: The date and time when the password expires. The time zone is UTC. A Null value means the password never expires.
|
||||
returned: success
|
||||
type: str
|
||||
username:
|
||||
description: Username with Identity API v2 (OpenStack Pike or earlier) else Null
|
||||
returned: success
|
||||
@@ -114,7 +133,7 @@ class IdentityUserInfoModule(OpenStackModule):
|
||||
argument_spec = dict(
|
||||
name=dict(required=False, default=None),
|
||||
domain=dict(required=False, default=None),
|
||||
filters=dict(required=False, type='dict', default=None),
|
||||
filters=dict(required=False, type='dict', default={}),
|
||||
)
|
||||
module_kwargs = dict(
|
||||
supports_check_mode=True
|
||||
@@ -128,21 +147,16 @@ class IdentityUserInfoModule(OpenStackModule):
|
||||
filters = self.params['filters']
|
||||
|
||||
if domain:
|
||||
try:
|
||||
# We assume admin is passing domain id
|
||||
dom = self.conn.get_domain(domain)['id']
|
||||
domain = dom
|
||||
except Exception:
|
||||
# If we fail, maybe admin is passing a domain name.
|
||||
# Note that domains have unique names, just like id.
|
||||
dom = self.conn.search_domains(filters={'name': domain})
|
||||
if dom:
|
||||
domain = dom[0]['id']
|
||||
else:
|
||||
self.fail_json(msg='Domain name or ID does not exist')
|
||||
dom_obj = self.conn.identity.find_domain(domain)
|
||||
if dom_obj is None:
|
||||
self.fail_json(
|
||||
msg="Domain name or ID '{0}' does not exist".format(domain))
|
||||
filters['domain_id'] = dom_obj.id
|
||||
|
||||
users = self.conn.search_users(name, filters, domain_id=domain)
|
||||
self.exit_json(changed=False, openstack_users=users)
|
||||
users = self.conn.identity.users(
|
||||
name=name, **filters)
|
||||
users = [user.to_dict(computed=False) for user in users]
|
||||
self.exit_json(changed=False, users=users)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user