mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -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
|
@ -87,6 +87,33 @@ EXAMPLES = """
|
|||
iosxr_interface:
|
||||
name: GigabitEthernet0/0/0/2
|
||||
enabled: False
|
||||
|
||||
- name: Create interface using aggregate
|
||||
iosxr_interface:
|
||||
aggregate:
|
||||
- name: GigabitEthernet0/0/0/3
|
||||
- name: GigabitEthernet0/0/0/2
|
||||
state: present
|
||||
|
||||
- name: Delete interface using aggregate
|
||||
iosxr_interface:
|
||||
aggregate:
|
||||
- name: GigabitEthernet0/0/0/3
|
||||
- name: GigabitEthernet0/0/0/2
|
||||
state: absent
|
||||
|
||||
- name: Check intent arguments
|
||||
iosxr_interface:
|
||||
name: GigabitEthernet0/0/0/5
|
||||
state: up
|
||||
delay: 20
|
||||
|
||||
- name: Config + intent
|
||||
iosxr_interface:
|
||||
name: GigabitEthernet0/0/0/5
|
||||
enabled: False
|
||||
state: down
|
||||
delay: 20
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
|
@ -103,13 +130,14 @@ commands:
|
|||
import re
|
||||
|
||||
from time import sleep
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.connection import exec_command
|
||||
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 conditional
|
||||
from ansible.module_utils.network_common import conditional, remove_default_spec
|
||||
|
||||
DEFAULT_DESCRIPTION = "configured by iosxr_interface"
|
||||
|
||||
|
@ -158,37 +186,19 @@ def map_params_to_obj(module):
|
|||
|
||||
aggregate = module.params.get('aggregate')
|
||||
if aggregate:
|
||||
for param in aggregate:
|
||||
validate_param_values(module, args, param)
|
||||
d = param.copy()
|
||||
for item in aggregate:
|
||||
for key in item:
|
||||
if item.get(key) is None:
|
||||
item[key] = module.params[key]
|
||||
|
||||
if 'name' not in d:
|
||||
module.fail_json(msg="missing required arguments: %s" % 'name')
|
||||
|
||||
# set default value
|
||||
for item in args:
|
||||
if item not in d:
|
||||
if item == 'description':
|
||||
d['description'] = DEFAULT_DESCRIPTION
|
||||
else:
|
||||
d[item] = None
|
||||
else:
|
||||
d[item] = str(d[item])
|
||||
|
||||
if not d.get('state'):
|
||||
d['state'] = module.params['state']
|
||||
|
||||
if d.get('enabled') is None:
|
||||
d['enabled'] = module.params['enabled']
|
||||
validate_param_values(module, item, item)
|
||||
d = item.copy()
|
||||
|
||||
if d['enabled']:
|
||||
d['disable'] = False
|
||||
else:
|
||||
d['disable'] = True
|
||||
|
||||
if d.get('delay') is None:
|
||||
d['delay'] = module.params['delay']
|
||||
|
||||
obj.append(d)
|
||||
|
||||
else:
|
||||
|
@ -342,7 +352,7 @@ def check_declarative_intent_params(module, want, result):
|
|||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
argument_spec = dict(
|
||||
element_spec = dict(
|
||||
name=dict(),
|
||||
description=dict(default=DEFAULT_DESCRIPTION),
|
||||
speed=dict(),
|
||||
|
@ -352,11 +362,21 @@ def main():
|
|||
tx_rate=dict(),
|
||||
rx_rate=dict(),
|
||||
delay=dict(default=10, type='int'),
|
||||
aggregate=dict(type='list'),
|
||||
state=dict(default='present',
|
||||
choices=['present', 'absent', 'up', 'down'])
|
||||
)
|
||||
|
||||
aggregate_spec = deepcopy(element_spec)
|
||||
aggregate_spec['name'] = dict(required=True)
|
||||
|
||||
# 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_one_of = [['name', 'aggregate']]
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -110,10 +110,12 @@ commands:
|
|||
- username ansible secret password group sysadmin
|
||||
- username admin secret admin
|
||||
"""
|
||||
|
||||
from functools import partial
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network_common import remove_default_spec
|
||||
from ansible.module_utils.iosxr import get_config, load_config
|
||||
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
|
||||
|
||||
|
@ -243,19 +245,27 @@ def map_params_to_obj(module):
|
|||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
argument_spec = dict(
|
||||
aggregate=dict(type='list', aliases=['users', 'collection']),
|
||||
element_spec = dict(
|
||||
name=dict(),
|
||||
|
||||
configured_password=dict(no_log=True),
|
||||
update_password=dict(default='always', choices=['on_create', 'always']),
|
||||
|
||||
group=dict(aliases=['role']),
|
||||
|
||||
purge=dict(type='bool', default=False),
|
||||
state=dict(default='present', choices=['present', 'absent'])
|
||||
)
|
||||
aggregate_spec = deepcopy(element_spec)
|
||||
aggregate_spec['name'] = dict(required=True)
|
||||
|
||||
# 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, aliases=['users', 'collection']),
|
||||
purge=dict(type='bool', default=False)
|
||||
)
|
||||
|
||||
argument_spec.update(element_spec)
|
||||
argument_spec.update(iosxr_argument_spec)
|
||||
mutually_exclusive = [('name', 'aggregate')]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue