junos_linkagg aggregate and other minor fixes (#27855)
* junos_linkagg aggregate and other minor fixes * Minor change
This commit is contained in:
parent
43f6a97bdc
commit
49eb81d573
9 changed files with 96 additions and 76 deletions
|
@ -142,8 +142,6 @@ diff.prepared:
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
|
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
|
||||||
|
@ -189,7 +187,7 @@ def main():
|
||||||
active=dict(default=True, type='bool')
|
active=dict(default=True, type='bool')
|
||||||
)
|
)
|
||||||
|
|
||||||
aggregate_spec = copy(element_spec)
|
aggregate_spec = element_spec.copy()
|
||||||
aggregate_spec['name'] = dict(required=True)
|
aggregate_spec['name'] = dict(required=True)
|
||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
@ -238,7 +236,7 @@ def main():
|
||||||
|
|
||||||
requests = list()
|
requests = list()
|
||||||
for param in params:
|
for param in params:
|
||||||
item = copy(param)
|
item = param.copy()
|
||||||
state = item.get('state')
|
state = item.get('state')
|
||||||
item['disable'] = True if state == 'down' else False
|
item['disable'] = True if state == 'down' else False
|
||||||
|
|
||||||
|
|
|
@ -103,8 +103,6 @@ diff:
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
|
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
|
||||||
|
@ -130,7 +128,7 @@ def main():
|
||||||
active=dict(default=True, type='bool')
|
active=dict(default=True, type='bool')
|
||||||
)
|
)
|
||||||
|
|
||||||
aggregate_spec = copy(element_spec)
|
aggregate_spec = element_spec.copy()
|
||||||
aggregate_spec['name'] = dict(required=True)
|
aggregate_spec['name'] = dict(required=True)
|
||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
@ -174,7 +172,7 @@ def main():
|
||||||
|
|
||||||
requests = list()
|
requests = list()
|
||||||
for param in params:
|
for param in params:
|
||||||
item = copy(param)
|
item = param.copy()
|
||||||
if not item['ipv4'] and not item['ipv6']:
|
if not item['ipv4'] and not item['ipv6']:
|
||||||
module.fail_json(msg="one of the following is required: ipv4,ipv6")
|
module.fail_json(msg="one of the following is required: ipv4,ipv6")
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,12 @@ options:
|
||||||
description:
|
description:
|
||||||
description:
|
description:
|
||||||
- Description of Interface.
|
- Description of Interface.
|
||||||
|
aggregate:
|
||||||
|
description: List of link aggregation definitions.
|
||||||
|
purge:
|
||||||
|
description:
|
||||||
|
- Purge link aggregation groups not defined in the aggregates parameter.
|
||||||
|
default: no
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of the link aggregation group.
|
- State of the link aggregation group.
|
||||||
|
@ -156,7 +162,7 @@ import collections
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
|
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
||||||
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config, get_configuration
|
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config, get_configuration
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -178,15 +184,15 @@ def validate_min_links(value, module):
|
||||||
module.fail_json(msg='min_links must be between 1 and 8')
|
module.fail_json(msg='min_links must be between 1 and 8')
|
||||||
|
|
||||||
|
|
||||||
def validate_param_values(module, obj):
|
def validate_param_values(module, obj, item):
|
||||||
for key in obj:
|
for key in obj:
|
||||||
# validate the param value (if validator func exists)
|
# validate the param value (if validator func exists)
|
||||||
validator = globals().get('validate_%s' % key)
|
validator = globals().get('validate_%s' % key)
|
||||||
if callable(validator):
|
if callable(validator):
|
||||||
validator(module.params.get(key), module)
|
validator(item.get(key), module)
|
||||||
|
|
||||||
|
|
||||||
def configure_lag_params(module, warnings):
|
def configure_lag_params(module, requests, item):
|
||||||
top = 'interfaces/interface'
|
top = 'interfaces/interface'
|
||||||
param_lag_to_xpath_map = collections.OrderedDict()
|
param_lag_to_xpath_map = collections.OrderedDict()
|
||||||
param_lag_to_xpath_map.update([
|
param_lag_to_xpath_map.update([
|
||||||
|
@ -194,32 +200,29 @@ def configure_lag_params(module, warnings):
|
||||||
('description', 'description'),
|
('description', 'description'),
|
||||||
('min_links', {'xpath': 'minimum-links', 'top': 'aggregated-ether-options'}),
|
('min_links', {'xpath': 'minimum-links', 'top': 'aggregated-ether-options'}),
|
||||||
('disable', {'xpath': 'disable', 'tag_only': True}),
|
('disable', {'xpath': 'disable', 'tag_only': True}),
|
||||||
('mode', {'xpath': module.params['mode'], 'tag_only': True, 'top': 'aggregated-ether-options/lacp'}),
|
('mode', {'xpath': item['mode'], 'tag_only': True, 'top': 'aggregated-ether-options/lacp'}),
|
||||||
])
|
])
|
||||||
|
|
||||||
validate_param_values(module, param_lag_to_xpath_map)
|
validate_param_values(module, param_lag_to_xpath_map, item)
|
||||||
|
|
||||||
want = map_params_to_obj(module, param_lag_to_xpath_map)
|
want = map_params_to_obj(module, param_lag_to_xpath_map, param=item)
|
||||||
ele = map_obj_to_ele(module, want, top)
|
ele = map_obj_to_ele(module, want, top, param=item)
|
||||||
|
requests.append(ele)
|
||||||
|
|
||||||
diff = load_config(module, tostring(ele), warnings, action='replace')
|
if item['device_count']:
|
||||||
if module.params['device_count']:
|
|
||||||
top = 'chassis/aggregated-devices/ethernet'
|
top = 'chassis/aggregated-devices/ethernet'
|
||||||
device_count_to_xpath_map = {'device_count': {'xpath': 'device-count', 'leaf_only': True}}
|
device_count_to_xpath_map = {'device_count': {'xpath': 'device-count', 'leaf_only': True}}
|
||||||
|
|
||||||
validate_param_values(module, device_count_to_xpath_map)
|
validate_param_values(module, device_count_to_xpath_map, item)
|
||||||
|
|
||||||
want = map_params_to_obj(module, device_count_to_xpath_map)
|
want = map_params_to_obj(module, device_count_to_xpath_map, param=item)
|
||||||
ele = map_obj_to_ele(module, want, top)
|
ele = map_obj_to_ele(module, want, top, param=item)
|
||||||
|
requests.append(ele)
|
||||||
diff = load_config(module, tostring(ele), warnings, action='replace')
|
|
||||||
|
|
||||||
return diff
|
|
||||||
|
|
||||||
|
|
||||||
def configure_member_params(module, warnings, diff=None):
|
def configure_member_params(module, requests, item):
|
||||||
top = 'interfaces/interface'
|
top = 'interfaces/interface'
|
||||||
members = module.params['members']
|
members = item['members']
|
||||||
|
|
||||||
if members:
|
if members:
|
||||||
member_to_xpath_map = collections.OrderedDict()
|
member_to_xpath_map = collections.OrderedDict()
|
||||||
|
@ -229,36 +232,34 @@ def configure_member_params(module, warnings, diff=None):
|
||||||
])
|
])
|
||||||
|
|
||||||
# link aggregation bundle assigned to member
|
# link aggregation bundle assigned to member
|
||||||
module.params['bundle'] = module.params['name']
|
item['bundle'] = item['name']
|
||||||
|
|
||||||
for member in members:
|
for member in members:
|
||||||
|
|
||||||
if module.params['state'] == 'absent':
|
if item['state'] == 'absent':
|
||||||
# if link aggregate bundle is not assigned to member, trying to
|
# if link aggregate bundle is not assigned to member, trying to
|
||||||
# delete it results in rpc-reply error, hence if is not assigned
|
# delete it results in rpc-reply error, hence if is not assigned
|
||||||
# skip deleting it and continue to next member.
|
# skip deleting it and continue to next member.
|
||||||
resp = get_configuration(module)
|
resp = get_configuration(module)
|
||||||
bundle = resp.xpath("configuration/interfaces/interface[name='%s']/ether-options/"
|
bundle = resp.xpath("configuration/interfaces/interface[name='%s']/ether-options/"
|
||||||
"ieee-802.3ad[bundle='%s']" % (member, module.params['bundle']))
|
"ieee-802.3ad[bundle='%s']" % (member, item['bundle']))
|
||||||
if not bundle:
|
if not bundle:
|
||||||
continue
|
continue
|
||||||
# Name of member to be assigned to link aggregation bundle
|
# Name of member to be assigned to link aggregation bundle
|
||||||
module.params['name'] = member
|
item['name'] = member
|
||||||
|
|
||||||
validate_param_values(module, member_to_xpath_map)
|
validate_param_values(module, member_to_xpath_map, item)
|
||||||
|
|
||||||
want = map_params_to_obj(module, member_to_xpath_map)
|
want = map_params_to_obj(module, member_to_xpath_map, param=item)
|
||||||
ele = map_obj_to_ele(module, want, top)
|
ele = map_obj_to_ele(module, want, top, param=item)
|
||||||
diff = load_config(module, tostring(ele), warnings)
|
requests.append(ele)
|
||||||
|
|
||||||
return diff
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" main entry point for module execution
|
""" main entry point for module execution
|
||||||
"""
|
"""
|
||||||
argument_spec = dict(
|
element_spec = dict(
|
||||||
name=dict(required=True),
|
name=dict(),
|
||||||
mode=dict(default='on', type='str', choices=['on', 'off', 'active', 'passive']),
|
mode=dict(default='on', type='str', choices=['on', 'off', 'active', 'passive']),
|
||||||
members=dict(type='list'),
|
members=dict(type='list'),
|
||||||
min_links=dict(type='int'),
|
min_links=dict(type='int'),
|
||||||
|
@ -268,14 +269,32 @@ def main():
|
||||||
active=dict(default=True, type='bool')
|
active=dict(default=True, type='bool')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
aggregate_spec = element_spec.copy()
|
||||||
|
aggregate_spec['name'] = dict(required=True)
|
||||||
|
|
||||||
|
argument_spec = dict(
|
||||||
|
aggregate=dict(type='list', elements='dict', options=aggregate_spec),
|
||||||
|
purge=dict(default=False, type='bool')
|
||||||
|
)
|
||||||
|
|
||||||
|
argument_spec.update(element_spec)
|
||||||
argument_spec.update(junos_argument_spec)
|
argument_spec.update(junos_argument_spec)
|
||||||
required_one_of = [['name', 'collection']]
|
|
||||||
mutually_exclusive = [['name', 'collection']]
|
required_one_of = [['name', 'aggregate']]
|
||||||
|
|
||||||
|
mutually_exclusive = [['name', 'aggregate'],
|
||||||
|
['mode', 'aggregate'],
|
||||||
|
['members', 'aggregate'],
|
||||||
|
['min_links', 'aggregate'],
|
||||||
|
['device_count', 'aggregate'],
|
||||||
|
['description', 'aggregate'],
|
||||||
|
['state', 'aggregate'],
|
||||||
|
['active', 'aggregate']]
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=argument_spec,
|
module = AnsibleModule(argument_spec=argument_spec,
|
||||||
|
supports_check_mode=True,
|
||||||
required_one_of=required_one_of,
|
required_one_of=required_one_of,
|
||||||
mutually_exclusive=mutually_exclusive,
|
mutually_exclusive=mutually_exclusive)
|
||||||
supports_check_mode=True)
|
|
||||||
|
|
||||||
warnings = list()
|
warnings = list()
|
||||||
check_args(module, warnings)
|
check_args(module, warnings)
|
||||||
|
@ -285,23 +304,33 @@ def main():
|
||||||
if warnings:
|
if warnings:
|
||||||
result['warnings'] = warnings
|
result['warnings'] = warnings
|
||||||
|
|
||||||
state = module.params.get('state')
|
params = to_param_list(module)
|
||||||
module.params['disable'] = True if state == 'down' else False
|
requests = list()
|
||||||
|
for param in params:
|
||||||
|
item = param.copy()
|
||||||
|
|
||||||
if state in ('present', 'up', 'down'):
|
state = item.get('state')
|
||||||
module.params['state'] = 'present'
|
item['disable'] = True if state == 'down' else False
|
||||||
|
|
||||||
else:
|
if state in ('present', 'up', 'down'):
|
||||||
module.params['disable'] = True
|
item['state'] = 'present'
|
||||||
|
|
||||||
if module.params.get('mode') == 'off':
|
else:
|
||||||
module.params['mode'] = ''
|
item['disable'] = True
|
||||||
elif module.params.get('mode') == 'on':
|
|
||||||
module.params['mode'] = 'passive'
|
|
||||||
|
|
||||||
|
mode = item.get('mode')
|
||||||
|
if mode == 'off':
|
||||||
|
item['mode'] = ''
|
||||||
|
elif mode == 'on':
|
||||||
|
item['mode'] = 'passive'
|
||||||
|
|
||||||
|
configure_lag_params(module, requests, item)
|
||||||
|
configure_member_params(module, requests, item)
|
||||||
|
|
||||||
|
diff = None
|
||||||
with locked_config(module):
|
with locked_config(module):
|
||||||
diff = configure_lag_params(module, warnings)
|
for req in requests:
|
||||||
diff = configure_member_params(module, warnings, diff)
|
diff = load_config(module, tostring(req), warnings, action='replace')
|
||||||
|
|
||||||
commit = not module.check_mode
|
commit = not module.check_mode
|
||||||
if diff:
|
if diff:
|
||||||
|
|
|
@ -173,11 +173,13 @@ def main():
|
||||||
('disable', {'xpath': 'disable', 'tag_only': True, 'is_key': True})
|
('disable', {'xpath': 'disable', 'tag_only': True, 'is_key': True})
|
||||||
])
|
])
|
||||||
|
|
||||||
state = module.params.get('state')
|
item = module.params.copy()
|
||||||
module.params['disable'] = True if state in ('disabled', 'absent') else False
|
state = item.get('state')
|
||||||
|
|
||||||
|
item['disable'] = True if state in ('disabled', 'absent') else False
|
||||||
|
|
||||||
if state in ('enabled', 'disabled'):
|
if state in ('enabled', 'disabled'):
|
||||||
module.params['state'] = 'present'
|
item['state'] = 'present'
|
||||||
|
|
||||||
want = map_params_to_obj(module, param_to_xpath_map)
|
want = map_params_to_obj(module, param_to_xpath_map)
|
||||||
ele = map_obj_to_ele(module, want, top)
|
ele = map_obj_to_ele(module, want, top)
|
||||||
|
|
|
@ -142,11 +142,12 @@ def main():
|
||||||
('disable', {'xpath': 'disable', 'tag_only': True})
|
('disable', {'xpath': 'disable', 'tag_only': True})
|
||||||
])
|
])
|
||||||
|
|
||||||
state = module.params.get('state')
|
item = module.params.copy()
|
||||||
module.params['disable'] = True if state in ('disabled', 'absent') else False
|
state = item.get('state')
|
||||||
|
item['disable'] = True if state in ('disabled', 'absent') else False
|
||||||
|
|
||||||
if state in ('enabled', 'disabled'):
|
if state in ('enabled', 'disabled'):
|
||||||
module.params['state'] = 'present'
|
item['state'] = 'present'
|
||||||
|
|
||||||
want = map_params_to_obj(module, param_to_xpath_map)
|
want = map_params_to_obj(module, param_to_xpath_map)
|
||||||
ele = map_obj_to_ele(module, want, top)
|
ele = map_obj_to_ele(module, want, top)
|
||||||
|
|
|
@ -126,8 +126,6 @@ diff.prepared:
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
||||||
|
@ -222,7 +220,7 @@ def main():
|
||||||
|
|
||||||
requests = list()
|
requests = list()
|
||||||
for param in params:
|
for param in params:
|
||||||
item = copy(param)
|
item = param.copy()
|
||||||
dest = item.get('dest')
|
dest = item.get('dest')
|
||||||
if dest == 'console' and item.get('name'):
|
if dest == 'console' and item.get('name'):
|
||||||
module.fail_json(msg="%s and %s are mutually exclusive" % ('console', 'name'))
|
module.fail_json(msg="%s and %s are mutually exclusive" % ('console', 'name'))
|
||||||
|
|
|
@ -132,8 +132,6 @@ diff.prepared:
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
||||||
|
@ -160,7 +158,7 @@ def main():
|
||||||
active=dict(default=True, type='bool')
|
active=dict(default=True, type='bool')
|
||||||
)
|
)
|
||||||
|
|
||||||
aggregate_spec = copy(element_spec)
|
aggregate_spec = element_spec.copy()
|
||||||
aggregate_spec['address'] = dict(required=True)
|
aggregate_spec['address'] = dict(required=True)
|
||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
@ -208,7 +206,7 @@ def main():
|
||||||
requests = list()
|
requests = list()
|
||||||
|
|
||||||
for param in params:
|
for param in params:
|
||||||
item = copy(param)
|
item = param.copy()
|
||||||
if item['state'] == 'present':
|
if item['state'] == 'present':
|
||||||
if not item['address'] and item['next_hop']:
|
if not item['address'] and item['next_hop']:
|
||||||
module.fail_json(msg="parameters are required together: ['address', 'next_hop']")
|
module.fail_json(msg="parameters are required together: ['address', 'next_hop']")
|
||||||
|
|
|
@ -110,8 +110,6 @@ diff.prepared:
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
||||||
|
@ -151,7 +149,7 @@ def main():
|
||||||
state=dict(default='present', choices=['present', 'absent']),
|
state=dict(default='present', choices=['present', 'absent']),
|
||||||
active=dict(default=True, type='bool')
|
active=dict(default=True, type='bool')
|
||||||
)
|
)
|
||||||
aggregate_spec = copy(element_spec)
|
aggregate_spec = element_spec.copy()
|
||||||
aggregate_spec['name'] = dict(required=True)
|
aggregate_spec['name'] = dict(required=True)
|
||||||
aggregate_spec['vlan_id'] = dict(required=True, type='int')
|
aggregate_spec['vlan_id'] = dict(required=True, type='int')
|
||||||
|
|
||||||
|
@ -199,7 +197,7 @@ def main():
|
||||||
requests = list()
|
requests = list()
|
||||||
|
|
||||||
for param in params:
|
for param in params:
|
||||||
item = copy(param)
|
item = param.copy()
|
||||||
validate_param_values(module, param_to_xpath_map, param=item)
|
validate_param_values(module, param_to_xpath_map, param=item)
|
||||||
|
|
||||||
want = map_params_to_obj(module, param_to_xpath_map, param=item)
|
want = map_params_to_obj(module, param_to_xpath_map, param=item)
|
||||||
|
|
|
@ -164,8 +164,6 @@ diff.prepared:
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele, to_param_list
|
||||||
|
@ -192,7 +190,7 @@ def main():
|
||||||
active=dict(default=True, type='bool')
|
active=dict(default=True, type='bool')
|
||||||
)
|
)
|
||||||
|
|
||||||
aggregate_spec = copy(element_spec)
|
aggregate_spec = element_spec.copy()
|
||||||
aggregate_spec['name'] = dict(required=True)
|
aggregate_spec['name'] = dict(required=True)
|
||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
@ -241,7 +239,7 @@ def main():
|
||||||
requests = list()
|
requests = list()
|
||||||
|
|
||||||
for param in params:
|
for param in params:
|
||||||
item = copy(param)
|
item = param.copy()
|
||||||
|
|
||||||
item['type'] = 'vrf'
|
item['type'] = 'vrf'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue