Implement functionality of the API method /cloudapi/account/audits in the module decort_account_info

This commit is contained in:
2024-07-24 14:23:35 +03:00
parent fe1e8a32f9
commit 3c6ce85dba
3 changed files with 54 additions and 1 deletions

View File

@@ -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
###################################