2026-02-11 13:50:28 +03:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = r'''
|
|
|
|
|
---
|
|
|
|
|
module: decort_user
|
|
|
|
|
|
|
|
|
|
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home). # noqa: E501
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
from ansible.module_utils.decort_utils import DecortController
|
|
|
|
|
|
2026-06-01 18:27:15 +03:00
|
|
|
from dynamix_sdk import exceptions as sdk_exceptions
|
|
|
|
|
|
2026-02-11 13:50:28 +03:00
|
|
|
|
|
|
|
|
class DecortUser(DecortController):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__(AnsibleModule(**self.amodule_init_args))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def amodule_init_args(self) -> dict:
|
|
|
|
|
return self.pack_amodule_init_args(
|
|
|
|
|
argument_spec=dict(
|
|
|
|
|
api_methods=dict(
|
|
|
|
|
type='bool',
|
|
|
|
|
default=False,
|
|
|
|
|
),
|
|
|
|
|
objects_search=dict(
|
|
|
|
|
type='str',
|
|
|
|
|
),
|
|
|
|
|
resource_consumption=dict(
|
|
|
|
|
type='bool',
|
|
|
|
|
default=False,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
supports_check_mode=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@DecortController.handle_sdk_exceptions
|
|
|
|
|
def run(self):
|
|
|
|
|
self.get_info()
|
|
|
|
|
self.exit()
|
|
|
|
|
|
|
|
|
|
def get_info(self):
|
|
|
|
|
self.facts = self.usermanager_whoami_result
|
|
|
|
|
self.id = self.facts['name']
|
|
|
|
|
|
2026-06-01 18:27:15 +03:00
|
|
|
try:
|
|
|
|
|
user_model = self.api.cloudapi.user.get(user_name=self.id)
|
|
|
|
|
except sdk_exceptions.RequestException as e:
|
|
|
|
|
if (
|
|
|
|
|
e.orig_exception.response is not None
|
|
|
|
|
and e.orig_exception.response.status_code == 404
|
|
|
|
|
):
|
|
|
|
|
self.message(
|
|
|
|
|
self.MESSAGES.obj_not_found(
|
|
|
|
|
obj='user',
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.exit(fail=True)
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
self.facts.update(user_model.model_dump())
|
2026-02-11 13:50:28 +03:00
|
|
|
|
|
|
|
|
if self.aparams['resource_consumption']:
|
2026-06-01 18:27:15 +03:00
|
|
|
self.facts.update(
|
|
|
|
|
self.api.ca.user.get_resource_consumption().model_dump()
|
|
|
|
|
)
|
2026-02-11 13:50:28 +03:00
|
|
|
|
2026-06-01 18:27:15 +03:00
|
|
|
# Delete duplicate self.facts['name']
|
|
|
|
|
del self.facts['user_name']
|
2026-02-11 13:50:28 +03:00
|
|
|
|
2026-06-01 18:27:15 +03:00
|
|
|
if self.aparams['api_methods']:
|
|
|
|
|
self.facts['api_methods'] = (
|
|
|
|
|
self.api.cloudapi.user.api_list(user_name=self.id).model_dump()
|
|
|
|
|
)
|
2026-02-11 13:50:28 +03:00
|
|
|
search_string = self.aparams['objects_search']
|
|
|
|
|
if search_string:
|
|
|
|
|
self.facts['objects_search'] = self.user_objects_search(
|
|
|
|
|
search_string=search_string,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
DecortUser().run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|