mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
iosxr modules aggregate check and other minor refactor (#28360)
* iosxr aggregate validation * vyos_user, junos_user minor changes * Aggregated documentation
This commit is contained in:
parent
ceef4f97ed
commit
9ab9945cf3
7 changed files with 150 additions and 71 deletions
|
@ -46,10 +46,6 @@ options:
|
|||
default: debugging
|
||||
aggregate:
|
||||
description: List of logging definitions.
|
||||
purge:
|
||||
description:
|
||||
- Purge logging not defined in the aggregates parameter.
|
||||
default: no
|
||||
state:
|
||||
description:
|
||||
- State of the logging configuration.
|
||||
|
@ -63,24 +59,41 @@ EXAMPLES = """
|
|||
dest: hostnameprefix
|
||||
name: 172.16.0.1
|
||||
state: present
|
||||
|
||||
- name: remove hostnameprefix logging configuration
|
||||
iosxr_logging:
|
||||
dest: hostnameprefix
|
||||
name: 172.16.0.1
|
||||
state: absent
|
||||
|
||||
- name: configure console logging level and facility
|
||||
iosxr_logging:
|
||||
dest: console
|
||||
facility: local7
|
||||
level: debugging
|
||||
state: present
|
||||
|
||||
- name: enable logging to all
|
||||
iosxr_logging:
|
||||
dest : on
|
||||
|
||||
- name: configure buffer size
|
||||
iosxr_logging:
|
||||
dest: buffered
|
||||
size: 5000
|
||||
|
||||
- name: Configure logging using aggregate
|
||||
iosxr_logging:
|
||||
aggregate:
|
||||
- { dest: console, level: warning }
|
||||
- { dest: buffered, size: 4800000 }
|
||||
|
||||
- name: Delete logging using aggregate
|
||||
iosxr_logging:
|
||||
aggregate:
|
||||
- { dest: console, level: warning }
|
||||
- { dest: buffered, size: 4800000 }
|
||||
state: absent
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
|
@ -95,14 +108,17 @@ commands:
|
|||
|
||||
import re
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.iosxr import get_config, load_config
|
||||
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
|
||||
from ansible.module_utils.network_common import remove_default_spec
|
||||
|
||||
|
||||
def validate_size(value, module):
|
||||
if value:
|
||||
if not int(307200) <= value <= int(125000000):
|
||||
if value and not int(307200) <= value <= int(125000000):
|
||||
module.fail_json(msg='size must be between 307200 and 125000000')
|
||||
else:
|
||||
return value
|
||||
|
@ -238,22 +254,22 @@ def map_config_to_obj(module):
|
|||
return obj
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
def map_params_to_obj(module, required_if=None):
|
||||
obj = []
|
||||
|
||||
if 'aggregate' in module.params and module.params['aggregate']:
|
||||
for c in module.params['aggregate']:
|
||||
d = c.copy()
|
||||
aggregate = module.params.get('aggregate')
|
||||
if aggregate:
|
||||
for item in aggregate:
|
||||
for key in item:
|
||||
if item.get(key) is None:
|
||||
item[key] = module.params[key]
|
||||
|
||||
module._check_required_if(required_if, item)
|
||||
d = item.copy()
|
||||
|
||||
if d['dest'] != 'hostnameprefix':
|
||||
d['name'] = None
|
||||
|
||||
if 'state' not in d:
|
||||
d['state'] = module.params['state']
|
||||
if 'facility' not in d:
|
||||
d['facility'] = module.params['facility']
|
||||
if 'level' not in d:
|
||||
d['level'] = module.params['level']
|
||||
|
||||
if d['dest'] == 'buffered':
|
||||
if 'size' in d:
|
||||
d['size'] = str(validate_size(d['size'], module))
|
||||
|
@ -303,17 +319,25 @@ def map_params_to_obj(module):
|
|||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
argument_spec = dict(
|
||||
element_spec = dict(
|
||||
dest=dict(type='str', choices=['on', 'hostnameprefix', 'console', 'monitor', 'buffered']),
|
||||
name=dict(type='str'),
|
||||
size=dict(type='int'),
|
||||
facility=dict(type='str', default='local7'),
|
||||
level=dict(type='str', default='debugging'),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
aggregate=dict(type='list'),
|
||||
purge=dict(default=False, type='bool')
|
||||
)
|
||||
|
||||
aggregate_spec = deepcopy(element_spec)
|
||||
|
||||
# remove default in aggregate spec, to handle common arguments
|
||||
remove_default_spec(aggregate_spec)
|
||||
|
||||
argument_spec = dict(
|
||||
aggregate=dict(type='list', elements='dict', options=aggregate_spec),
|
||||
)
|
||||
|
||||
argument_spec.update(element_spec)
|
||||
argument_spec.update(iosxr_argument_spec)
|
||||
|
||||
required_if = [('dest', 'hostnameprefix', ['name'])]
|
||||
|
@ -327,7 +351,7 @@ def main():
|
|||
|
||||
result = {'changed': False}
|
||||
|
||||
want = map_params_to_obj(module)
|
||||
want = map_params_to_obj(module, required_if=required_if)
|
||||
have = map_config_to_obj(module)
|
||||
commands = map_obj_to_commands((want, have), module)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue