Merge branch 'BANS-478' into 'dev_5.4.0'
Implement functionality of the API method `cloudapi/account/listDisks` See merge request rudecs/dev/decort-ansible!104
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
| Идентификатор<br>задачи | Описание |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| BANS-462<br>BANS-472<br>BANS-475<br>BANS-476<br>BANS-477 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:<br>• основная информация <br>• используемые и зарезервированные ресурсы<br>• ресурсные группы<br>• виртуальные машины<br>• внутренние сети |
|
| BANS-462<br>BANS-472<br>BANS-475<br>BANS-476<br>BANS-477<br>BANS-478 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:<br>• основная информация <br>• используемые и зарезервированные ресурсы<br>• ресурсные группы<br>• виртуальные машины<br>• внутренние сети<br>• диски |
|
||||||
|
|
||||||
## Исправления
|
## Исправления
|
||||||
|
|
||||||
|
|||||||
@@ -32,11 +32,12 @@ class DecortAccountInfo(DecortController):
|
|||||||
account_name=amodule.params['name'],
|
account_name=amodule.params['name'],
|
||||||
account_id=amodule.params['id'],
|
account_id=amodule.params['id'],
|
||||||
computes_args=self.mapped_computes_args,
|
computes_args=self.mapped_computes_args,
|
||||||
|
disks_args=self.mapped_disks_args,
|
||||||
resource_consumption=amodule.params['resource_consumption'],
|
resource_consumption=amodule.params['resource_consumption'],
|
||||||
resource_groups_args=self.mapped_rg_args,
|
resource_groups_args=self.mapped_rg_args,
|
||||||
vinses_args=self.mapped_vinses_args,
|
vinses_args=self.mapped_vinses_args,
|
||||||
fail_if_not_found=True
|
fail_if_not_found=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def amodule_init_args(self) -> dict:
|
def amodule_init_args(self) -> dict:
|
||||||
@@ -123,6 +124,57 @@ class DecortAccountInfo(DecortController):
|
|||||||
type='str',
|
type='str',
|
||||||
required=True
|
required=True
|
||||||
),
|
),
|
||||||
|
disks=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
filter=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
id=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
name=dict(
|
||||||
|
type='str',
|
||||||
|
),
|
||||||
|
size=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
type=dict(
|
||||||
|
type='str',
|
||||||
|
choices=['B', 'D'],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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_DISK_LIST,
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
id=dict(
|
id=dict(
|
||||||
type='int',
|
type='int',
|
||||||
),
|
),
|
||||||
@@ -303,6 +355,38 @@ class DecortAccountInfo(DecortController):
|
|||||||
|
|
||||||
return mapped_args
|
return mapped_args
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mapped_disks_args(self) -> None | dict:
|
||||||
|
"""
|
||||||
|
Map the module argument `disks` to
|
||||||
|
arguments dictionary for the method
|
||||||
|
`DecortController.account_disks`
|
||||||
|
(excluding for `account_id`).
|
||||||
|
"""
|
||||||
|
|
||||||
|
input_args = self.amodule.params['disks']
|
||||||
|
if not input_args:
|
||||||
|
return input_args
|
||||||
|
|
||||||
|
mapped_args = {}
|
||||||
|
if input_args['filter']:
|
||||||
|
mapped_args['disk_id'] = input_args['filter']['id']
|
||||||
|
mapped_args['disk_name'] = input_args['filter']['name']
|
||||||
|
mapped_args['disk_size'] = input_args['filter']['size']
|
||||||
|
mapped_args['disk_type'] = input_args['filter']['type']
|
||||||
|
if input_args['pagination']:
|
||||||
|
mapped_args['page_number'] =\
|
||||||
|
input_args['pagination']['number']
|
||||||
|
mapped_args['page_size'] =\
|
||||||
|
input_args['pagination']['size']
|
||||||
|
if input_args['sorting']:
|
||||||
|
mapped_args['sort_by_asc'] =\
|
||||||
|
input_args['sorting']['asc']
|
||||||
|
mapped_args['sort_by_field'] =\
|
||||||
|
input_args['sorting']['field']
|
||||||
|
|
||||||
|
return mapped_args
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mapped_rg_args(self) -> None | dict:
|
def mapped_rg_args(self) -> None | dict:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -63,6 +63,16 @@ class DecortController(object):
|
|||||||
'vinsConnected',
|
'vinsConnected',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
FIELDS_FOR_SORTING_ACCOUNT_DISK_LIST = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'pool',
|
||||||
|
'sepId',
|
||||||
|
'shareable',
|
||||||
|
'sizeMax',
|
||||||
|
'type',
|
||||||
|
]
|
||||||
|
|
||||||
FIELDS_FOR_SORTING_ACCOUNT_RG_LIST = [
|
FIELDS_FOR_SORTING_ACCOUNT_RG_LIST = [
|
||||||
'createdBy',
|
'createdBy',
|
||||||
'createdTime',
|
'createdTime',
|
||||||
@@ -2045,6 +2055,7 @@ class DecortController(object):
|
|||||||
account_id=0,
|
account_id=0,
|
||||||
account_name: str = '',
|
account_name: str = '',
|
||||||
computes_args: None | dict = None,
|
computes_args: None | dict = None,
|
||||||
|
disks_args: None | dict = None,
|
||||||
fail_if_not_found=False,
|
fail_if_not_found=False,
|
||||||
resource_consumption=False,
|
resource_consumption=False,
|
||||||
resource_groups_args: None | dict = None,
|
resource_groups_args: None | dict = None,
|
||||||
@@ -2064,6 +2075,12 @@ class DecortController(object):
|
|||||||
and `**computes_args`. Result of the call will
|
and `**computes_args`. Result of the call will
|
||||||
be added to account info dict (key `computes`).
|
be added to account info dict (key `computes`).
|
||||||
|
|
||||||
|
@param (None | dict) disks_args: If dict is
|
||||||
|
specified, then the method `self.account_disks`
|
||||||
|
will be called passing founded account ID
|
||||||
|
and `**disks_args`. Result of the call will
|
||||||
|
be added to account info dict (key `disks`).
|
||||||
|
|
||||||
@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.
|
||||||
@@ -2182,6 +2199,13 @@ class DecortController(object):
|
|||||||
**vinses_args
|
**vinses_args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if disks_args is not None:
|
||||||
|
account_details['disks'] =\
|
||||||
|
self.account_disks(
|
||||||
|
account_id=account_details['id'],
|
||||||
|
**disks_args
|
||||||
|
)
|
||||||
|
|
||||||
return account_details['id'], account_details
|
return account_details['id'], account_details
|
||||||
|
|
||||||
@waypoint
|
@waypoint
|
||||||
@@ -2406,6 +2430,57 @@ class DecortController(object):
|
|||||||
|
|
||||||
return vinses
|
return vinses
|
||||||
|
|
||||||
|
@waypoint
|
||||||
|
def account_disks(
|
||||||
|
self,
|
||||||
|
account_id: int,
|
||||||
|
disk_id: None | int = None,
|
||||||
|
disk_name: None | str = None,
|
||||||
|
disk_size: None | int = None,
|
||||||
|
disk_type: None | str = None,
|
||||||
|
page_number: int = 1,
|
||||||
|
page_size: None | int = None,
|
||||||
|
sort_by_asc=True,
|
||||||
|
sort_by_field: None | str = None,
|
||||||
|
) -> list[dict]:
|
||||||
|
"""
|
||||||
|
Implementation of functionality of the API method
|
||||||
|
`/cloudapi/account/listDisks`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
sort_by = None
|
||||||
|
if sort_by_field:
|
||||||
|
if not sort_by_field in self.FIELDS_FOR_SORTING_ACCOUNT_DISK_LIST:
|
||||||
|
self.result['msg'] = (
|
||||||
|
f'{sort_by_field} is not valid field for sorting'
|
||||||
|
f' account disks 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,
|
||||||
|
'diskId': disk_id,
|
||||||
|
'diskMaxSize': disk_size,
|
||||||
|
'name': disk_name,
|
||||||
|
'page': page_number if page_size else None,
|
||||||
|
'size': page_size,
|
||||||
|
'sortBy': sort_by,
|
||||||
|
'type': disk_type,
|
||||||
|
}
|
||||||
|
|
||||||
|
api_resp = self.decort_api_call(
|
||||||
|
arg_req_function=requests.post,
|
||||||
|
arg_api_name='/restmachine/cloudapi/account/listDisks',
|
||||||
|
arg_params=api_params,
|
||||||
|
)
|
||||||
|
|
||||||
|
disks = api_resp.json()['data']
|
||||||
|
|
||||||
|
return disks
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
# GPU resource manipulation methods
|
# GPU resource manipulation methods
|
||||||
###################################
|
###################################
|
||||||
|
|||||||
Reference in New Issue
Block a user