From 0ca339902656d7ca62e639ea1c6b1e871b496ec7 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 23 Jul 2024 17:53:45 +0300 Subject: [PATCH] Implement functionality of the API method `/cloudapi/account/listFlipGroups` --- CHANGELOG.md | 2 +- library/decort_account_info.py | 71 ++++++++++++++++++++++++++++++++++ module_utils/decort_utils.py | 59 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6e1bf..f77e8f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ | Идентификатор
задачи | Описание | | --- | --- | -| BANS-462
BANS-472
BANS-475
BANS-476
BANS-477
BANS-478
BANS-479 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:
• основная информация
• используемые и зарезервированные ресурсы
• ресурсные группы
• виртуальные машины
• внутренние сети
• диски
• образы | +| BANS-462
BANS-472
BANS-475
BANS-476
BANS-477
BANS-478
BANS-479
BANS-480 | Добавлен новый модуль **decort_account_info**, который позволяет получить следующую информацию об аккаунте:
• основная информация
• используемые и зарезервированные ресурсы
• ресурсные группы
• виртуальные машины
• внутренние сети
• диски
• образы
• группы с плавающим IP-адресом | ## Исправления diff --git a/library/decort_account_info.py b/library/decort_account_info.py index 4514347..f642b86 100644 --- a/library/decort_account_info.py +++ b/library/decort_account_info.py @@ -33,6 +33,7 @@ class DecortAccountInfo(DecortController): account_id=amodule.params['id'], computes_args=self.mapped_computes_args, disks_args=self.mapped_disks_args, + flip_groups_args=self.mapped_flip_groups_args, images_args=self.mapped_images_args, resource_consumption=amodule.params['resource_consumption'], resource_groups_args=self.mapped_rg_args, @@ -176,6 +177,47 @@ class DecortAccountInfo(DecortController): ), ), ), + flip_groups=dict( + type='dict', + options=dict( + filter=dict( + type='dict', + options=dict( + ext_net_id=dict( + type='int', + ), + id=dict( + type='int', + ), + ip=dict( + type='str', + ), + name=dict( + type='str', + ), + vins_id=dict( + type='int', + ), + vins_name=dict( + type='str', + ), + ), + ), + pagination=dict( + type='dict', + options=dict( + number=dict( + type='int', + default=1, + ), + size=dict( + type='int', + required=True, + ), + ), + ), + ), + ), id=dict( type='int', ), @@ -440,6 +482,35 @@ class DecortAccountInfo(DecortController): return mapped_args + @property + def mapped_flip_groups_args(self) -> None | dict: + """ + Map the module argument `flip_groups` to + arguments dictionary for the method + `DecortController.account_flip_groups` + (excluding for `account_id`). + """ + + input_args = self.amodule.params['flip_groups'] + if not input_args: + return input_args + + mapped_args = {} + if input_args['filter']: + mapped_args['ext_net_id'] = input_args['filter']['ext_net_id'] + mapped_args['flig_group_id'] = input_args['filter']['id'] + mapped_args['flig_group_ip'] = input_args['filter']['ip'] + mapped_args['flig_group_name'] = input_args['filter']['name'] + mapped_args['vins_id'] = input_args['filter']['vins_id'] + mapped_args['vins_name'] = input_args['filter']['vins_name'] + if input_args['pagination']: + mapped_args['page_number'] =\ + input_args['pagination']['number'] + mapped_args['page_size'] =\ + input_args['pagination']['size'] + + return mapped_args + @property def mapped_images_args(self) -> None | dict: """ diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 22c2f91..2e154b2 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -2079,6 +2079,7 @@ class DecortController(object): computes_args: None | dict = None, disks_args: None | dict = None, fail_if_not_found=False, + flip_groups_args: None | dict = None, images_args: None | dict = None, resource_consumption=False, resource_groups_args: None | dict = None, @@ -2108,6 +2109,12 @@ class DecortController(object): the method `self.amodule.fail_json(**self.result)` will be called if account is not found. + @param (None | dict) flip_groups_args: If dict is + specified, then the method `self.account_flip_groups` + will be called passing founded account ID + and `**flip_groups_args`. Result of the call will + be added to account info dict (key `flip_groups`). + @param (None | dict) images_args: If dict is specified, then the method `self.account_images` will be called passing founded account ID @@ -2242,6 +2249,13 @@ class DecortController(object): **images_args ) + if flip_groups_args is not None: + account_details['flip_groups'] =\ + self.account_flip_groups( + account_id=account_details['id'], + **flip_groups_args + ) + return account_details['id'], account_details @waypoint @@ -2586,6 +2600,51 @@ class DecortController(object): return images + @waypoint + def account_flip_groups( + self, + account_id: int, + ext_net_id: None | int = None, + flig_group_id: None | int = None, + flig_group_ip: None | str = None, + flig_group_name: None | str = None, + page_number: int = 1, + page_size: None | int = None, + vins_id: None | int = None, + vins_name: None | str = None, + ) -> list[dict]: + """ + Implementation of functionality of the API method + `/cloudapi/account/listFlipGroups`. + """ + + api_params = { + 'accountId': account_id, + 'byIp': flig_group_ip, + 'extnetId': ext_net_id, + 'flipGroupId': flig_group_id, + 'name': flig_group_name, + 'page': page_number if page_size else None, + 'size': page_size, + 'vinsId': vins_id, + 'vinsName': vins_name, + } + + api_resp = self.decort_api_call( + arg_req_function=requests.post, + arg_api_name='/restmachine/cloudapi/account/listFlipGroups', + arg_params=api_params, + ) + + flip_groups = api_resp.json()['data'] + + for fg in flip_groups: + fg['createdTime_readable'] = self.sec_to_dt_str(fg['createdTime']) + fg['deletedTime_readable'] = self.sec_to_dt_str(fg['deletedTime']) + fg['updatedTime_readable'] = self.sec_to_dt_str(fg['updatedTime']) + + return flip_groups + ################################### # GPU resource manipulation methods ###################################