Improve naming of some methods and variable in library/decort_account_info.py and module_utils/decort_utils.py

main
Dmitriy Smirnov 7 months ago
parent ced031bba8
commit 8e4ce18d8a

@ -24,22 +24,22 @@ from ansible.module_utils.decort_utils import DecortController
class DecortAccountInfo(DecortController):
def __init__(self):
amodule = AnsibleModule(**self.module_args, supports_check_mode=True)
amodule = AnsibleModule(**self.amodule_init_args)
super().__init__(amodule)
self.id, self.facts = self.account_find(
account_name=amodule.params['name'],
account_id=amodule.params['id'],
computes_params=self.mapped_computes_params,
computes_args=self.mapped_computes_args,
resource_consumption=amodule.params['resource_consumption'],
resource_groups_params=self.mapped_rg_params,
vinses_params=self.mapped_vinses_params,
resource_groups_args=self.mapped_rg_args,
vinses_args=self.mapped_vinses_args,
fail_if_not_found=True
)
@property
def module_args(self) -> dict:
def amodule_init_args(self) -> dict:
return dict(
argument_spec=dict(
app_id=dict(
@ -261,116 +261,117 @@ class DecortAccountInfo(DecortController):
('authenticator', 'oauth2',
('oauth2_url', 'app_id', 'app_secret')),
('authenticator', 'jwt', ('jwt',))
]
],
supports_check_mode=True,
)
@property
def mapped_computes_params(self) -> None | dict:
def mapped_computes_args(self) -> None | dict:
"""
Map the module parameter `computes` to
parameters dictionary for the method
Map the module argument `computes` to
arguments dictionary for the method
`DecortController.account_computes`
(excluding for `account_id`).
"""
input_params = self.amodule.params['computes']
if not input_params:
return input_params
input_args = self.amodule.params['computes']
if not input_args:
return input_args
mapped_params = {}
if input_params['filter']:
mapped_params['compute_id'] = input_params['filter']['id']
mapped_params['compute_ip'] = input_params['filter']['ip']
mapped_params['compute_name'] = input_params['filter']['name']
mapped_params['compute_tech_status'] =\
input_params['filter']['tech_status']
mapped_params['ext_net_id'] = input_params['filter']['ext_net_id']
mapped_params['ext_net_name'] =\
input_params['filter']['ext_net_name']
mapped_params['rg_id'] = input_params['filter']['rg_id']
mapped_params['rg_name'] = input_params['filter']['rg_name']
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']
mapped_args = {}
if input_args['filter']:
mapped_args['compute_id'] = input_args['filter']['id']
mapped_args['compute_ip'] = input_args['filter']['ip']
mapped_args['compute_name'] = input_args['filter']['name']
mapped_args['compute_tech_status'] =\
input_args['filter']['tech_status']
mapped_args['ext_net_id'] = input_args['filter']['ext_net_id']
mapped_args['ext_net_name'] =\
input_args['filter']['ext_net_name']
mapped_args['rg_id'] = input_args['filter']['rg_id']
mapped_args['rg_name'] = input_args['filter']['rg_name']
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_params
return mapped_args
@property
def mapped_rg_params(self) -> None | dict:
def mapped_rg_args(self) -> None | dict:
"""
Map the module parameter `resource_groups` to
parameters dictionary for the method
Map the module argument `resource_groups` to
arguments dictionary for the method
`DecortController.account_resource_groups`
(excluding for `account_id`).
"""
input_params = self.amodule.params['resource_groups']
if not input_params:
return input_params
input_args = self.amodule.params['resource_groups']
if not input_args:
return input_args
mapped_params = {}
if input_params['filter']:
mapped_params['rg_id'] =\
input_params['filter']['id']
mapped_params['rg_name'] =\
input_params['filter']['name']
mapped_params['rg_status'] =\
input_params['filter']['status']
mapped_params['vins_id'] =\
input_params['filter']['vins_id']
mapped_params['vm_id'] =\
input_params['filter']['vm_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']
mapped_args = {}
if input_args['filter']:
mapped_args['rg_id'] =\
input_args['filter']['id']
mapped_args['rg_name'] =\
input_args['filter']['name']
mapped_args['rg_status'] =\
input_args['filter']['status']
mapped_args['vins_id'] =\
input_args['filter']['vins_id']
mapped_args['vm_id'] =\
input_args['filter']['vm_id']
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_params
return mapped_args
@property
def mapped_vinses_params(self) -> None | dict:
def mapped_vinses_args(self) -> None | dict:
"""
Map the module parameter `vinses` to
parameters dictionary for the method
Map the module argument `vinses` to
arguments dictionary for the method
`DecortController.account_vinses`
(excluding for `account_id`).
"""
input_params = self.amodule.params['vinses']
if not input_params:
return input_params
input_args = self.amodule.params['vinses']
if not input_args:
return input_args
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']
mapped_args = {}
if input_args['filter']:
mapped_args['vins_id'] = input_args['filter']['id']
mapped_args['vins_name'] = input_args['filter']['name']
mapped_args['ext_ip'] = input_args['filter']['ext_ip']
mapped_args['rg_id'] = input_args['filter']['rg_id']
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_params
return mapped_args
def exit(self):
self.result['facts'] = self.facts

@ -2026,9 +2026,9 @@ class DecortController(object):
def account_find(self, account_name: str, account_id=0,
resource_consumption=False,
resource_groups_params: None | dict = None,
computes_params: None | dict = None,
vinses_params: None | dict = None,
resource_groups_args: None | dict = None,
computes_args: None | dict = None,
vinses_args: None | dict = None,
fail_if_not_found=False):
"""
Find account specified by account ID or name and return
@ -2045,22 +2045,22 @@ class DecortController(object):
the call will be added to
account info dict (key `resource_consumption`).
@param (None | dict) resource_groups_params: If dict is
@param (None | dict) resource_groups_args: If dict is
specified, then the method `account_resource_groups`
will be called passing founded account ID
and `**resource_groups_params`. Result of the call will
and `**resource_groups_args`. Result of the call will
be added to account info dict (key `resource_groups`).
@param (None | dict) computes_params: If dict is
@param (None | dict) computes_args: If dict is
specified, then the method `account_computes`
will be called passing founded account ID
and `**computes_params`. Result of the call will
and `**computes_args`. Result of the call will
be added to account info dict (key `computes`).
@param (None | dict) vinses_params: If dict is
@param (None | dict) vinses_args: If dict is
specified, then the method `account_vinses`
will be called passing founded account ID
and `**vinses_params`. Result of the call will
and `**vinses_args`. Result of the call will
be added to account info dict (key `vinses`).
@param (bool) fail_if_not_found: If `True` is specified, then
@ -2143,24 +2143,24 @@ class DecortController(object):
account_details['resource_reserved'] =\
resource_consumption['Reserved']
if resource_groups_params is not None:
if resource_groups_args is not None:
account_details['resource_groups'] =\
self.account_resource_groups(
account_id=account_details['id'],
**resource_groups_params
**resource_groups_args
)
if computes_params is not None:
if computes_args is not None:
account_details['computes'] =\
self.account_computes(
account_id=account_details['id'],
**computes_params
**computes_args
)
if vinses_params is not None:
if vinses_args is not None:
account_details['vinses'] = self.account_vinses(
account_id=account_details['id'],
**vinses_params
**vinses_args
)
return account_details['id'], account_details

Loading…
Cancel
Save