9.0.0
This commit is contained in:
@@ -4,7 +4,7 @@ DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_user_info
|
||||
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home). # noqa: E501
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
@@ -33,9 +33,8 @@ class DecortUserInfo(DecortController):
|
||||
rights=dict(
|
||||
type='str',
|
||||
choices=[
|
||||
e.value
|
||||
for e in self.AccountUserRights
|
||||
],
|
||||
e.value for e in self.AccountUserRights
|
||||
],
|
||||
),
|
||||
id=dict(
|
||||
type='int',
|
||||
@@ -47,7 +46,7 @@ class DecortUserInfo(DecortController):
|
||||
type='str',
|
||||
choices=[
|
||||
e.value for e in self.AccountStatus
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -79,8 +78,8 @@ class DecortUserInfo(DecortController):
|
||||
type='str',
|
||||
choices=[
|
||||
e.value
|
||||
for e in self.AccountSortableField
|
||||
],
|
||||
for e in self.AccountSortableField
|
||||
],
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
@@ -186,6 +185,124 @@ class DecortUserInfo(DecortController):
|
||||
type='bool',
|
||||
default=False,
|
||||
),
|
||||
zones=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
filter=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
deletable=dict(
|
||||
type='bool',
|
||||
),
|
||||
description=dict(
|
||||
type='str',
|
||||
),
|
||||
grid_id=dict(
|
||||
type='int',
|
||||
),
|
||||
id=dict(
|
||||
type='int',
|
||||
),
|
||||
name=dict(
|
||||
type='str',
|
||||
),
|
||||
node_id=dict(
|
||||
type='int',
|
||||
),
|
||||
status=dict(
|
||||
type='str',
|
||||
choices=[
|
||||
e.value for e in self.ZoneStatus
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
pagination=dict(
|
||||
type='dict',
|
||||
apply_defaults=True,
|
||||
options=dict(
|
||||
number=dict(
|
||||
type='int',
|
||||
default=1,
|
||||
),
|
||||
size=dict(
|
||||
type='int',
|
||||
default=50,
|
||||
),
|
||||
),
|
||||
),
|
||||
sorting=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
asc=dict(
|
||||
type='bool',
|
||||
default=True,
|
||||
),
|
||||
field=dict(
|
||||
type='str',
|
||||
choices=self.ZoneField._member_names_,
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
trunks=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
filter=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
ids=dict(
|
||||
type='list',
|
||||
),
|
||||
account_ids=dict(
|
||||
type='list',
|
||||
),
|
||||
status=dict(
|
||||
type='str',
|
||||
choices=[
|
||||
e.value for e in self.TrunkStatus
|
||||
],
|
||||
),
|
||||
vlan_ids=dict(
|
||||
type='list',
|
||||
),
|
||||
),
|
||||
),
|
||||
pagination=dict(
|
||||
type='dict',
|
||||
apply_defaults=True,
|
||||
options=dict(
|
||||
number=dict(
|
||||
type='int',
|
||||
default=1,
|
||||
),
|
||||
size=dict(
|
||||
type='int',
|
||||
default=50,
|
||||
),
|
||||
),
|
||||
),
|
||||
sorting=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
asc=dict(
|
||||
type='bool',
|
||||
default=True,
|
||||
),
|
||||
field=dict(
|
||||
type='str',
|
||||
choices=[
|
||||
e.value
|
||||
for e in self.TrunksSortableField
|
||||
],
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
@@ -200,22 +317,38 @@ class DecortUserInfo(DecortController):
|
||||
check_error = False
|
||||
|
||||
match self.aparams['audits']:
|
||||
case {'filter': {'time':
|
||||
{'start': {'datetime': str() as dt_str}}
|
||||
}
|
||||
}:
|
||||
case {
|
||||
'filter': {'time': {'start': {'datetime': str() as dt_str}}}
|
||||
}:
|
||||
if self.dt_str_to_sec(dt_str=dt_str) is None:
|
||||
self.message(self.MESSAGES.str_not_parsed(string=dt_str))
|
||||
check_error = True
|
||||
match self.aparams['audits']:
|
||||
case {'filter': {'time':
|
||||
{'end': {'datetime': str() as dt_str}}
|
||||
}
|
||||
}:
|
||||
case {
|
||||
'filter': {'time': {'end': {'datetime': str() as dt_str}}}
|
||||
}:
|
||||
if self.dt_str_to_sec(dt_str=dt_str) is None:
|
||||
self.message(self.MESSAGES.str_not_parsed(string=dt_str))
|
||||
check_error = True
|
||||
|
||||
aparam_trunks = self.aparams['trunks']
|
||||
if (
|
||||
aparam_trunks is not None
|
||||
and aparam_trunks['filter'] is not None
|
||||
and aparam_trunks['filter']['vlan_ids'] is not None
|
||||
):
|
||||
for vlan_id in aparam_trunks['filter']['vlan_ids']:
|
||||
if not (
|
||||
self.TRUNK_VLAN_ID_MIN_VALUE
|
||||
<= vlan_id
|
||||
<= self.TRUNK_VLAN_ID_MAX_VALUE
|
||||
):
|
||||
check_error = True
|
||||
self.message(
|
||||
'Check for parameter "trunks.filter.vlan_ids" failed: '
|
||||
f'VLAN ID {vlan_id} must be in range 1-4095.'
|
||||
)
|
||||
|
||||
if check_error:
|
||||
self.exit(fail=True)
|
||||
|
||||
@@ -331,6 +464,94 @@ class DecortUserInfo(DecortController):
|
||||
|
||||
return mapped_args
|
||||
|
||||
@property
|
||||
def mapped_zones_args(self):
|
||||
"""
|
||||
Map the module argument `zones` to
|
||||
arguments dictionary for the method
|
||||
`DecortController.user_zones`.
|
||||
"""
|
||||
|
||||
input_args = self.aparams['zones']
|
||||
if not input_args:
|
||||
return input_args
|
||||
|
||||
mapped_args = {}
|
||||
|
||||
input_args_filter = input_args['filter']
|
||||
if input_args_filter:
|
||||
mapped_args.update(input_args_filter)
|
||||
|
||||
input_args_filter_status = input_args_filter['status']
|
||||
if input_args_filter_status:
|
||||
mapped_args['status'] = (
|
||||
self.ZoneStatus(input_args_filter_status)
|
||||
)
|
||||
|
||||
input_args_pagination = input_args['pagination']
|
||||
if input_args_pagination:
|
||||
mapped_args['page_number'] = input_args_pagination['number']
|
||||
mapped_args['page_size'] = input_args_pagination['size']
|
||||
|
||||
input_args_sorting = input_args['sorting']
|
||||
if input_args_sorting:
|
||||
mapped_args['sort_by_asc'] = input_args_sorting['asc']
|
||||
|
||||
input_args_sorting_field = input_args_sorting['field']
|
||||
if input_args_sorting_field:
|
||||
mapped_args['sort_by_field'] = (
|
||||
self.ZoneField._member_map_[input_args_sorting_field]
|
||||
)
|
||||
|
||||
return mapped_args
|
||||
|
||||
@property
|
||||
def mapped_trunks_args(self):
|
||||
"""
|
||||
Map the module argument `trunks` to
|
||||
arguments dictionary for the method
|
||||
`DecortController.user_trunks`.
|
||||
"""
|
||||
|
||||
input_args = self.aparams['trunks']
|
||||
if not input_args:
|
||||
return input_args
|
||||
|
||||
mapped_args = {}
|
||||
|
||||
input_args_filter = input_args['filter']
|
||||
if input_args_filter:
|
||||
mapped_args.update(input_args_filter)
|
||||
|
||||
input_args_filter_status = input_args_filter['status']
|
||||
if input_args_filter_status:
|
||||
mapped_args['status'] = (
|
||||
self.TrunkStatus(input_args_filter_status)
|
||||
)
|
||||
|
||||
input_args_filter_vlan_ids = input_args_filter['vlan_ids']
|
||||
if input_args_filter_vlan_ids is not None:
|
||||
mapped_args['vlan_ids'] = ', '.join(
|
||||
map(str, input_args_filter_vlan_ids)
|
||||
)
|
||||
|
||||
input_args_pagination = input_args['pagination']
|
||||
if input_args_pagination:
|
||||
mapped_args['page_number'] = input_args_pagination['number']
|
||||
mapped_args['page_size'] = input_args_pagination['size']
|
||||
|
||||
input_args_sorting = input_args['sorting']
|
||||
if input_args_sorting:
|
||||
mapped_args['sort_by_asc'] = input_args_sorting['asc']
|
||||
|
||||
input_args_sorting_field = input_args_sorting['field']
|
||||
if input_args_sorting_field:
|
||||
mapped_args['sort_by_field'] = (
|
||||
self.TrunksSortableField(input_args_sorting_field)
|
||||
)
|
||||
|
||||
return mapped_args
|
||||
|
||||
def run(self):
|
||||
self.get_info()
|
||||
self.exit()
|
||||
@@ -357,13 +578,34 @@ class DecortUserInfo(DecortController):
|
||||
if self.aparams['api_methods']:
|
||||
self.facts['api_methods'] = self.user_api_methods(id=self.id)
|
||||
|
||||
|
||||
search_string = self.aparams['objects_search']
|
||||
if search_string:
|
||||
self.facts['objects_search'] = self.user_objects_search(
|
||||
search_string=search_string,
|
||||
)
|
||||
|
||||
if self.aparams['zones']:
|
||||
self.facts['zones'] = self.user_zones(**self.mapped_zones_args)
|
||||
|
||||
if self.aparams['trunks']:
|
||||
self.facts['trunks'] = self.user_trunks(**self.mapped_trunks_args)
|
||||
for trunk_facts in self.facts['trunks']:
|
||||
trunk_facts['account_ids'] = trunk_facts.pop('accountIds')
|
||||
trunk_facts['created_timestamp'] = trunk_facts.pop(
|
||||
'created_at'
|
||||
)
|
||||
trunk_facts['deleted_timestamp'] = trunk_facts.pop(
|
||||
'deleted_at'
|
||||
)
|
||||
trunk_facts['updated_timestamp'] = trunk_facts.pop(
|
||||
'updated_at'
|
||||
)
|
||||
trunk_facts['native_vlan_id'] = trunk_facts.pop(
|
||||
'nativeVlanId'
|
||||
)
|
||||
trunk_facts['ovs_bridge'] = trunk_facts.pop('ovsBridge')
|
||||
trunk_facts['vlan_ids'] = trunk_facts.pop('trunkTags')
|
||||
|
||||
|
||||
def main():
|
||||
DecortUserInfo().run()
|
||||
|
||||
Reference in New Issue
Block a user