Implement functionality of the API method /cloudapi/account/audits in the module decort_account_info
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
| Идентификатор<br>задачи | Описание |
|
||||
| --- | --- |
|
||||
| BANS-462<br>BANS-472<br>BANS-475<br>BANS-476<br>BANS-477<br>BANS-478<br>BANS-479<br>BANS-480 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:<br>• основная информация <br>• используемые и зарезервированные ресурсы<br>• ресурсные группы<br>• виртуальные машины<br>• внутренние сети<br>• диски<br>• образы<br>• группы с плавающим IP-адресом |
|
||||
| BANS-462<br>BANS-472<br>BANS-475<br>BANS-476<br>BANS-477<br>BANS-478<br>BANS-479<br>BANS-480<br>BANS-481 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:<br>• основная информация <br>• используемые и зарезервированные ресурсы<br>• ресурсные группы<br>• виртуальные машины<br>• внутренние сети<br>• диски<br>• образы<br>• группы с плавающим IP-адресом<br>• аудиты |
|
||||
|
||||
## Исправления
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
###################################
|
||||
|
||||
Reference in New Issue
Block a user