Merge branch 'BANS-477' into 'dev_5.4.0'
Implement functionality of the API method `cloudapi/account/listVins` in... See merge request rudecs/dev/decort-ansible!103
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
| Идентификатор<br>задачи | Описание |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| BANS-462<br>BANS-472<br>BANS-475<br>BANS-476 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:<br>• основная информация <br>• используемые и зарезервированные ресурсы<br>• ресурсные группы<br>• виртуальные машины |
|
| BANS-462<br>BANS-472<br>BANS-475<br>BANS-476<br>BANS-477 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:<br>• основная информация <br>• используемые и зарезервированные ресурсы<br>• ресурсные группы<br>• виртуальные машины<br>• внутренние сети |
|
||||||
|
|
||||||
## Исправления
|
## Исправления
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class DecortAccountInfo(DecortController):
|
|||||||
computes_params=self.mapped_computes_params,
|
computes_params=self.mapped_computes_params,
|
||||||
resource_consumption=amodule.params['resource_consumption'],
|
resource_consumption=amodule.params['resource_consumption'],
|
||||||
resource_groups_params=self.mapped_rg_params,
|
resource_groups_params=self.mapped_rg_params,
|
||||||
|
vinses_params=self.mapped_vinses_params,
|
||||||
fail_if_not_found=True
|
fail_if_not_found=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -199,6 +200,56 @@ class DecortAccountInfo(DecortController):
|
|||||||
type='bool',
|
type='bool',
|
||||||
default=True
|
default=True
|
||||||
),
|
),
|
||||||
|
vinses=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
filter=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
ext_ip=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
id=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
name=dict(
|
||||||
|
type='str'
|
||||||
|
),
|
||||||
|
rg_id=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
pagination=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
number=dict(
|
||||||
|
type='int',
|
||||||
|
default=1,
|
||||||
|
),
|
||||||
|
size=dict(
|
||||||
|
type='int',
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
sorting=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
asc=dict(
|
||||||
|
type='bool',
|
||||||
|
default=True,
|
||||||
|
),
|
||||||
|
field=dict(
|
||||||
|
type='str',
|
||||||
|
choices=\
|
||||||
|
self.FIELDS_FOR_SORTING_ACCOUNT_VINS_LIST,
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
mutually_exclusive=[
|
mutually_exclusive=[
|
||||||
('id', 'name')
|
('id', 'name')
|
||||||
@@ -275,6 +326,31 @@ class DecortAccountInfo(DecortController):
|
|||||||
|
|
||||||
return mapped_params
|
return mapped_params
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mapped_vinses_params(self) -> None | dict:
|
||||||
|
input_params = self.amodule.params['vinses']
|
||||||
|
if not input_params:
|
||||||
|
return input_params
|
||||||
|
|
||||||
|
mapped_params = {}
|
||||||
|
if input_params['filter']:
|
||||||
|
mapped_params['vins_id'] = input_params['filter']['id']
|
||||||
|
mapped_params['vins_name'] = input_params['filter']['name']
|
||||||
|
mapped_params['ext_ip'] = input_params['filter']['ext_ip']
|
||||||
|
mapped_params['rg_id'] = input_params['filter']['rg_id']
|
||||||
|
if input_params['pagination']:
|
||||||
|
mapped_params['page_number'] =\
|
||||||
|
input_params['pagination']['number']
|
||||||
|
mapped_params['page_size'] =\
|
||||||
|
input_params['pagination']['size']
|
||||||
|
if input_params['sorting']:
|
||||||
|
mapped_params['sort_by_asc'] =\
|
||||||
|
input_params['sorting']['asc']
|
||||||
|
mapped_params['sort_by_field'] =\
|
||||||
|
input_params['sorting']['field']
|
||||||
|
|
||||||
|
return mapped_params
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
self.result['facts'] = self.facts
|
self.result['facts'] = self.facts
|
||||||
self.amodule.exit_json(**self.result)
|
self.amodule.exit_json(**self.result)
|
||||||
|
|||||||
@@ -77,6 +77,26 @@ class DecortController(object):
|
|||||||
'vinses',
|
'vinses',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
FIELDS_FOR_SORTING_ACCOUNT_VINS_LIST = [
|
||||||
|
'computes',
|
||||||
|
'createdBy',
|
||||||
|
'createdTime',
|
||||||
|
'deletedBy',
|
||||||
|
'deletedTime',
|
||||||
|
'externalIP',
|
||||||
|
'extnetId',
|
||||||
|
'freeIPs',
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'network',
|
||||||
|
'priVnfDevId',
|
||||||
|
'rgId',
|
||||||
|
'rgName',
|
||||||
|
'status',
|
||||||
|
'updatedBy',
|
||||||
|
'updatedTime',
|
||||||
|
]
|
||||||
|
|
||||||
COMPUTE_TECH_STATUSES = [
|
COMPUTE_TECH_STATUSES = [
|
||||||
'BACKUP_RUNNING',
|
'BACKUP_RUNNING',
|
||||||
'BACKUP_STOPPED',
|
'BACKUP_STOPPED',
|
||||||
@@ -2008,6 +2028,7 @@ class DecortController(object):
|
|||||||
resource_consumption=False,
|
resource_consumption=False,
|
||||||
resource_groups_params: None | dict = None,
|
resource_groups_params: None | dict = None,
|
||||||
computes_params: None | dict = None,
|
computes_params: None | dict = None,
|
||||||
|
vinses_params: None | dict = None,
|
||||||
fail_if_not_found=False):
|
fail_if_not_found=False):
|
||||||
"""
|
"""
|
||||||
Find account specified by account ID or name and return
|
Find account specified by account ID or name and return
|
||||||
@@ -2036,6 +2057,12 @@ class DecortController(object):
|
|||||||
and `**computes_params`. Result of the call will
|
and `**computes_params`. Result of the call will
|
||||||
be added to account info dict (key `computes`).
|
be added to account info dict (key `computes`).
|
||||||
|
|
||||||
|
@param (None | dict) vinses_params: If dict is
|
||||||
|
specified, then the method `account_vinses`
|
||||||
|
will be called passing founded account ID
|
||||||
|
and `**vinses_params`. Result of the call will
|
||||||
|
be added to account info dict (key `vinses`).
|
||||||
|
|
||||||
@param (bool) fail_if_not_found: If `True` is specified, then
|
@param (bool) fail_if_not_found: If `True` is specified, then
|
||||||
the method `self.amodule.fail_json(**self.result)` will be
|
the method `self.amodule.fail_json(**self.result)` will be
|
||||||
called if account is not found.
|
called if account is not found.
|
||||||
@@ -2091,6 +2118,7 @@ class DecortController(object):
|
|||||||
return 0, None
|
return 0, None
|
||||||
|
|
||||||
account_details['computes_amount'] = account_details.pop('computes')
|
account_details['computes_amount'] = account_details.pop('computes')
|
||||||
|
account_details['vinses_amount'] = account_details.pop('vinses')
|
||||||
|
|
||||||
account_details['createdTime_readable'] = self.sec_to_dt_str(
|
account_details['createdTime_readable'] = self.sec_to_dt_str(
|
||||||
account_details['createdTime']
|
account_details['createdTime']
|
||||||
@@ -2129,6 +2157,12 @@ class DecortController(object):
|
|||||||
**computes_params
|
**computes_params
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if vinses_params is not None:
|
||||||
|
account_details['vinses'] = self.account_vinses(
|
||||||
|
account_id=account_details['id'],
|
||||||
|
**vinses_params
|
||||||
|
)
|
||||||
|
|
||||||
return account_details['id'], account_details
|
return account_details['id'], account_details
|
||||||
|
|
||||||
@waypoint
|
@waypoint
|
||||||
@@ -2277,6 +2311,57 @@ class DecortController(object):
|
|||||||
|
|
||||||
return computes
|
return computes
|
||||||
|
|
||||||
|
@waypoint
|
||||||
|
def account_vinses(
|
||||||
|
self,
|
||||||
|
account_id: int,
|
||||||
|
ext_ip: None | str = None,
|
||||||
|
page_number: int = 1,
|
||||||
|
page_size: None | int = None,
|
||||||
|
rg_id: None | int = None,
|
||||||
|
sort_by_asc=True,
|
||||||
|
sort_by_field: None | str = None,
|
||||||
|
vins_id: None | int = None,
|
||||||
|
vins_name: None | str = None,
|
||||||
|
) -> list[dict]:
|
||||||
|
sort_by = None
|
||||||
|
if sort_by_field:
|
||||||
|
if not sort_by_field in self.FIELDS_FOR_SORTING_ACCOUNT_VINS_LIST:
|
||||||
|
self.result['msg'] = (
|
||||||
|
f'{sort_by_field} is not valid field for sorting'
|
||||||
|
f' account vins list.'
|
||||||
|
)
|
||||||
|
self.amodule.fail_json(**self.result)
|
||||||
|
|
||||||
|
sort_by_prefix = '+' if sort_by_asc else '-'
|
||||||
|
sort_by = f'{sort_by_prefix}{sort_by_field}'
|
||||||
|
|
||||||
|
api_params = {
|
||||||
|
'accountId': account_id,
|
||||||
|
'extIp': ext_ip,
|
||||||
|
'name': vins_name,
|
||||||
|
'page': page_number if page_size else None,
|
||||||
|
'rgId': rg_id,
|
||||||
|
'size': page_size,
|
||||||
|
'sortBy': sort_by,
|
||||||
|
'vinsId': vins_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
api_resp = self.decort_api_call(
|
||||||
|
arg_req_function=requests.post,
|
||||||
|
arg_api_name='/restmachine/cloudapi/account/listVins',
|
||||||
|
arg_params=api_params,
|
||||||
|
)
|
||||||
|
|
||||||
|
vinses = api_resp.json()['data']
|
||||||
|
|
||||||
|
for v in vinses:
|
||||||
|
v['createdTime_readable'] = self.sec_to_dt_str(v['createdTime'])
|
||||||
|
v['deletedTime_readable'] = self.sec_to_dt_str(v['deletedTime'])
|
||||||
|
v['updatedTime_readable'] = self.sec_to_dt_str(v['updatedTime'])
|
||||||
|
|
||||||
|
return vinses
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
# GPU resource manipulation methods
|
# GPU resource manipulation methods
|
||||||
###################################
|
###################################
|
||||||
|
|||||||
Reference in New Issue
Block a user