Merge branch 'BANS-472' into 'dev_5.4.0'

Implement functionality of `/cloudapi/account/getResourceConsumption` API method

See merge request rudecs/dev/decort-ansible!100
main
commit 734408ab10

@ -6,7 +6,7 @@
| Идентификатор<br>задачи | Описание | | Идентификатор<br>задачи | Описание |
| --- | --- | | --- | --- |
| BANS-471 | Добавлен новый модуль **decort_account_info**, который позволяет получить основную информацию об аккаунте. | | BANS-462<br>BANS-472 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:<br>&bull; основная информация <br>&bull; используемые и зарезервированные ресурсы |
## Исправления ## Исправления

@ -64,6 +64,11 @@ class DecortAccountInfo(DecortController):
required=False, required=False,
fallback=(env_fallback, ['DECORT_OAUTH2_URL']) fallback=(env_fallback, ['DECORT_OAUTH2_URL'])
), ),
resource_consumption=dict(
type='bool',
required=False,
default=False
),
verify_ssl=dict( verify_ssl=dict(
type='bool', type='bool',
required=False, required=False,
@ -91,6 +96,7 @@ class DecortAccountInfo(DecortController):
self.id, self.facts = self.account_find( self.id, self.facts = self.account_find(
account_name=amodule.params['name'], account_name=amodule.params['name'],
account_id=amodule.params['id'], account_id=amodule.params['id'],
resource_consumption=amodule.params['resource_consumption'],
fail_if_not_found=True fail_if_not_found=True
) )

@ -1930,7 +1930,7 @@ class DecortController(object):
return return
def account_find(self, account_name, account_id=0, def account_find(self, account_name, account_id=0,
fail_if_not_found=False): resource_consumption=False, fail_if_not_found=False):
"""Find cloud account specified by the name and return facts about the account. Knowing account is """Find cloud account specified by the name and return facts about the account. Knowing account is
required for certain cloud resource management tasks (e.g. creating new RG). required for certain cloud resource management tasks (e.g. creating new RG).
@ -1995,6 +1995,16 @@ class DecortController(object):
account_details['updatedTime'] account_details['updatedTime']
) )
if resource_consumption:
resource_consumption = self.account_resource_consumption(
account_id=account_details['id'],
fail_if_not_found=True
)
account_details['resource_consumed'] =\
resource_consumption['Consumed']
account_details['resource_reserved'] =\
resource_consumption['Reserved']
return account_details['id'], account_details return account_details['id'], account_details
else: else:
if fail_if_not_found: if fail_if_not_found:
@ -2005,6 +2015,25 @@ class DecortController(object):
else: else:
return 0, None return 0, None
def account_resource_consumption(self, account_id: int,
fail_if_not_found=False) -> None | dict:
self.result['waypoints'] += f' -> account_resource_consumption'
api_resp = self.decort_api_call(
arg_req_function=requests.post,
arg_api_name='/restmachine/cloudapi/account/getResourceConsumption',
arg_params={'accountId': account_id},
not_fail_codes=[404]
)
if api_resp.status_code == 200:
return api_resp.json()
else:
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)
################################### ###################################
# GPU resource manipulation methods # GPU resource manipulation methods
################################### ###################################

Loading…
Cancel
Save