diff --git a/CHANGELOG.md b/CHANGELOG.md index f77e8f9..9b2acdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ | Идентификатор
задачи | Описание | | --- | --- | -| BANS-462
BANS-472
BANS-475
BANS-476
BANS-477
BANS-478
BANS-479
BANS-480 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:
• основная информация
• используемые и зарезервированные ресурсы
• ресурсные группы
• виртуальные машины
• внутренние сети
• диски
• образы
• группы с плавающим IP-адресом | +| BANS-462
BANS-472
BANS-475
BANS-476
BANS-477
BANS-478
BANS-479
BANS-480
BANS-481 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:
• основная информация
• используемые и зарезервированные ресурсы
• ресурсные группы
• виртуальные машины
• внутренние сети
• диски
• образы
• группы с плавающим IP-адресом
• аудиты | ## Исправления diff --git a/library/decort_account_info.py b/library/decort_account_info.py index f642b86..49cd1d1 100644 --- a/library/decort_account_info.py +++ b/library/decort_account_info.py @@ -31,6 +31,7 @@ class DecortAccountInfo(DecortController): self.id, self.facts = self.account_find( account_name=amodule.params['name'], account_id=amodule.params['id'], + audits=amodule.params['audits'], computes_args=self.mapped_computes_args, disks_args=self.mapped_disks_args, flip_groups_args=self.mapped_flip_groups_args, @@ -54,6 +55,10 @@ class DecortAccountInfo(DecortController): fallback=(env_fallback, ['DECORT_APP_SECRET']), no_log=True ), + audits=dict( + type='bool', + default=False + ), authenticator=dict( type='str', required=True, diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 2e154b2..470e8b4 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -2076,6 +2076,7 @@ class DecortController(object): self, account_id=0, account_name: str = '', + audits=False, computes_args: None | dict = None, disks_args: None | dict = None, fail_if_not_found=False, @@ -2093,6 +2094,12 @@ class DecortController(object): @param (string) account_name: name of the account to find. + @param (bool) audits: If `True` is specified, + then the method `self.account_audits` + will be called passing founded account ID and result of + the call will be added to + account info dict (key `audits`). + @param (None | dict) computes_args: If dict is specified, then the method `self.account_computes` will be called passing founded account ID @@ -2256,6 +2263,12 @@ class DecortController(object): **flip_groups_args ) + if audits: + account_details['audits'] = self.account_audits( + account_id=account_details['id'], + fail_if_not_found=True + ) + return account_details['id'], account_details @waypoint @@ -2645,6 +2658,41 @@ class DecortController(object): return flip_groups + @waypoint + def account_audits(self, account_id: int, + fail_if_not_found=False) -> None | list: + """ + Implementation of functionality of the API method + `/cloudapi/account/audits`. + + + @param (bool) fail_if_not_found: If `True` is specified, then + the method `self.amodule.fail_json(**self.result)` will be + called if account is not found. + """ + + api_resp = self.decort_api_call( + arg_req_function=requests.post, + arg_api_name='/restmachine/cloudapi/account/audits', + arg_params={'accountId': account_id}, + not_fail_codes=[404] + ) + + if api_resp.status_code != 200: + if fail_if_not_found: + self.result['msg'] = ("Current user does not have access to" + " the requested account or non-existent" + " account specified.") + self.amodule.fail_json(**self.result) + return + + audits = api_resp.json() + + for a in audits: + a['timestamp_readable'] = self.sec_to_dt_str(int(a['timestamp'])) + + return audits + ################################### # GPU resource manipulation methods ###################################