You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
290 lines
10 KiB
290 lines
10 KiB
#!/usr/bin/python
|
|
|
|
# Copyright: ...
|
|
# ...
|
|
|
|
DOCUMENTATION = r'''
|
|
---
|
|
module: decort_account_info
|
|
|
|
version_added: "2.16"
|
|
|
|
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
|
'''
|
|
|
|
# EXAMPLES = r'''
|
|
# '''
|
|
|
|
# RETURN = r'''
|
|
# '''
|
|
|
|
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
|
from ansible.module_utils.decort_utils import DecortController
|
|
|
|
|
|
class DecortAccountInfo(DecortController):
|
|
def __init__(self):
|
|
amodule = AnsibleModule(**self.module_args, supports_check_mode=True)
|
|
|
|
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,
|
|
resource_consumption=amodule.params['resource_consumption'],
|
|
resource_groups_params=self.mapped_rg_params,
|
|
fail_if_not_found=True
|
|
)
|
|
|
|
@property
|
|
def module_args(self) -> dict:
|
|
return dict(
|
|
argument_spec=dict(
|
|
app_id=dict(
|
|
type='str',
|
|
fallback=(env_fallback, ['DECORT_APP_ID'])
|
|
),
|
|
app_secret=dict(
|
|
type='str',
|
|
fallback=(env_fallback, ['DECORT_APP_SECRET']),
|
|
no_log=True
|
|
),
|
|
authenticator=dict(
|
|
type='str',
|
|
required=True,
|
|
choices=['oauth2', 'jwt']
|
|
),
|
|
computes=dict(
|
|
type='dict',
|
|
options=dict(
|
|
filter=dict(
|
|
type='dict',
|
|
options=dict(
|
|
ext_net_id=dict(
|
|
type='int',
|
|
),
|
|
ext_net_name=dict(
|
|
type='str'
|
|
),
|
|
id=dict(
|
|
type='int',
|
|
),
|
|
ip=dict(
|
|
type='str'
|
|
),
|
|
name=dict(
|
|
type='str'
|
|
),
|
|
rg_id=dict(
|
|
type='int',
|
|
),
|
|
rg_name=dict(
|
|
type='str'
|
|
),
|
|
tech_status=dict(
|
|
type='str',
|
|
choices=self.COMPUTE_TECH_STATUSES,
|
|
),
|
|
),
|
|
),
|
|
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_COMPUTE_LIST,
|
|
required=True,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
controller_url=dict(
|
|
type='str',
|
|
required=True
|
|
),
|
|
id=dict(
|
|
type='int',
|
|
),
|
|
jwt=dict(
|
|
type='str',
|
|
fallback=(env_fallback, ['DECORT_JWT']),
|
|
no_log=True
|
|
),
|
|
name=dict(
|
|
type='str',
|
|
),
|
|
oauth2_url=dict(
|
|
type='str',
|
|
fallback=(env_fallback, ['DECORT_OAUTH2_URL'])
|
|
),
|
|
resource_groups=dict(
|
|
type='dict',
|
|
options=dict(
|
|
filter=dict(
|
|
type='dict',
|
|
options=dict(
|
|
id=dict(
|
|
type='int',
|
|
),
|
|
name=dict(
|
|
type='str'
|
|
),
|
|
status=dict(
|
|
type='str',
|
|
choices=self.RESOURCE_GROUP_STATUSES,
|
|
),
|
|
vins_id=dict(
|
|
type='int'
|
|
),
|
|
vm_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_RG_LIST,
|
|
required=True,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
resource_consumption=dict(
|
|
type='bool',
|
|
default=False
|
|
),
|
|
verify_ssl=dict(
|
|
type='bool',
|
|
default=True
|
|
),
|
|
),
|
|
mutually_exclusive=[
|
|
('id', 'name')
|
|
],
|
|
required_one_of=[
|
|
('id', 'name')
|
|
],
|
|
required_if=[
|
|
('authenticator', 'oauth2',
|
|
('oauth2_url', 'app_id', 'app_secret')),
|
|
('authenticator', 'jwt', ('jwt',))
|
|
]
|
|
)
|
|
|
|
@property
|
|
def mapped_computes_params(self) -> None | dict:
|
|
input_params = self.amodule.params['computes']
|
|
if not input_params:
|
|
return input_params
|
|
|
|
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']
|
|
|
|
return mapped_params
|
|
|
|
@property
|
|
def mapped_rg_params(self) -> None | dict:
|
|
input_params = self.amodule.params['resource_groups']
|
|
if not input_params:
|
|
return input_params
|
|
|
|
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']
|
|
|
|
return mapped_params
|
|
|
|
def exit(self):
|
|
self.result['facts'] = self.facts
|
|
self.amodule.exit_json(**self.result)
|
|
|
|
|
|
def main():
|
|
decort_account_info = DecortAccountInfo()
|
|
decort_account_info.exit()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|