11.0.0
This commit is contained in:
@@ -8,565 +8,46 @@ description: See L(Module Documentation,https://repository.basistech.ru/BASIS/de
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.decort_utils import DecortController
|
||||
|
||||
|
||||
class DecortAccountInfo(DecortController):
|
||||
def __init__(self):
|
||||
super().__init__(AnsibleModule(**self.amodule_init_args))
|
||||
|
||||
@property
|
||||
def amodule_init_args(self) -> dict:
|
||||
return self.pack_amodule_init_args(
|
||||
argument_spec=dict(
|
||||
audits=dict(
|
||||
type='bool',
|
||||
default=False
|
||||
),
|
||||
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, # noqa: E501
|
||||
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=self.DISK_TYPES,
|
||||
),
|
||||
),
|
||||
),
|
||||
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, # noqa: E501
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
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',
|
||||
),
|
||||
images=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
filter=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
id=dict(
|
||||
type='int',
|
||||
),
|
||||
name=dict(
|
||||
type='str',
|
||||
),
|
||||
type=dict(
|
||||
type='str',
|
||||
choices=self.IMAGE_TYPES,
|
||||
),
|
||||
),
|
||||
),
|
||||
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_IMAGE_LIST, # noqa: E501
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
name=dict(
|
||||
type='str',
|
||||
),
|
||||
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, # noqa: E501
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
resource_consumption=dict(
|
||||
type='bool',
|
||||
default=False
|
||||
),
|
||||
vinses=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
filter=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
ext_ip=dict(
|
||||
type='str',
|
||||
),
|
||||
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, # noqa: E501
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
mutually_exclusive=[
|
||||
('id', 'name')
|
||||
],
|
||||
required_one_of=[
|
||||
('id', 'name')
|
||||
],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
@property
|
||||
def mapped_computes_args(self) -> None | dict:
|
||||
"""
|
||||
Map the module argument `computes` to
|
||||
arguments dictionary for the method
|
||||
`DecortController.account_computes`
|
||||
(excluding for `account_id`).
|
||||
"""
|
||||
|
||||
input_args = self.aparams['computes']
|
||||
if not input_args:
|
||||
return input_args
|
||||
|
||||
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_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.aparams['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
|
||||
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.aparams['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:
|
||||
"""
|
||||
Map the module argument `images` to
|
||||
arguments dictionary for the method
|
||||
`DecortController.account_images`
|
||||
(excluding for `account_id`).
|
||||
"""
|
||||
|
||||
input_args = self.aparams['images']
|
||||
if not input_args:
|
||||
return input_args
|
||||
|
||||
mapped_args = {}
|
||||
if input_args['filter']:
|
||||
mapped_args['image_id'] = input_args['filter']['id']
|
||||
mapped_args['image_name'] = input_args['filter']['name']
|
||||
mapped_args['image_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
|
||||
def mapped_rg_args(self) -> None | dict:
|
||||
"""
|
||||
Map the module argument `resource_groups` to
|
||||
arguments dictionary for the method
|
||||
`DecortController.account_resource_groups`
|
||||
(excluding for `account_id`).
|
||||
"""
|
||||
|
||||
input_args = self.aparams['resource_groups']
|
||||
if not input_args:
|
||||
return input_args
|
||||
|
||||
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_args
|
||||
|
||||
@property
|
||||
def mapped_vinses_args(self) -> None | dict:
|
||||
"""
|
||||
Map the module argument `vinses` to
|
||||
arguments dictionary for the method
|
||||
`DecortController.account_vinses`
|
||||
(excluding for `account_id`).
|
||||
"""
|
||||
|
||||
input_args = self.aparams['vinses']
|
||||
if not input_args:
|
||||
return input_args
|
||||
|
||||
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_args
|
||||
|
||||
def run(self):
|
||||
self.get_info()
|
||||
self.exit()
|
||||
|
||||
def get_info(self):
|
||||
self.id, self.facts = self.account_find(
|
||||
account_name=self.aparams['name'],
|
||||
account_id=self.aparams['id'],
|
||||
audits=self.aparams['audits'],
|
||||
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=self.aparams['resource_consumption'],
|
||||
resource_groups_args=self.mapped_rg_args,
|
||||
vinses_args=self.mapped_vinses_args,
|
||||
fail_if_not_found=True,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
DecortAccountInfo().run()
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
app_id=dict(type='raw'),
|
||||
app_secret=dict(type='raw'),
|
||||
authenticator=dict(type='raw'),
|
||||
controller_url=dict(type='raw'),
|
||||
domain=dict(type='raw'),
|
||||
jwt=dict(type='raw'),
|
||||
oauth2_url=dict(type='raw'),
|
||||
password=dict(type='raw'),
|
||||
username=dict(type='raw'),
|
||||
verify_ssl=dict(type='raw'),
|
||||
ignore_api_compatibility=dict(type='raw'),
|
||||
ignore_sdk_version_check=dict(type='raw'),
|
||||
audits=dict(type='raw'),
|
||||
computes=dict(type='raw'),
|
||||
disks=dict(type='raw'),
|
||||
flip_groups=dict(type='raw'),
|
||||
id=dict(type='raw'),
|
||||
images=dict(type='raw'),
|
||||
name=dict(type='raw'),
|
||||
resource_groups=dict(type='raw'),
|
||||
resource_consumption=dict(type='raw'),
|
||||
vinses=dict(type='raw'),
|
||||
),
|
||||
)
|
||||
|
||||
module.fail_json(
|
||||
msg=(
|
||||
'The functionality of the module has been moved to the modules '
|
||||
'"decort_disk_list", "decort_rg_list", "decort_vm_list", '
|
||||
'"decort_vins_list", "decort_image_list", '
|
||||
'"decort_flip_group_list", "decort_account".'
|
||||
'\nPlease use the new modules to get information about the objects'
|
||||
' available to the account.'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user