|
|
|
@ -51,6 +51,12 @@ options:
|
|
|
|
|
description:
|
|
|
|
|
description:
|
|
|
|
|
- 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:
|
|
|
|
|
description:
|
|
|
|
|
- State of the link aggregation group.
|
|
|
|
@ -156,7 +162,7 @@ import collections
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -178,15 +184,15 @@ def validate_min_links(value, module):
|
|
|
|
|
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:
|
|
|
|
|
# validate the param value (if validator func exists)
|
|
|
|
|
validator = globals().get('validate_%s' % key)
|
|
|
|
|
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'
|
|
|
|
|
param_lag_to_xpath_map = collections.OrderedDict()
|
|
|
|
|
param_lag_to_xpath_map.update([
|
|
|
|
@ -194,32 +200,29 @@ def configure_lag_params(module, warnings):
|
|
|
|
|
('description', 'description'),
|
|
|
|
|
('min_links', {'xpath': 'minimum-links', 'top': 'aggregated-ether-options'}),
|
|
|
|
|
('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)
|
|
|
|
|
ele = map_obj_to_ele(module, want, top)
|
|
|
|
|
want = map_params_to_obj(module, param_lag_to_xpath_map, param=item)
|
|
|
|
|
ele = map_obj_to_ele(module, want, top, param=item)
|
|
|
|
|
requests.append(ele)
|
|
|
|
|
|
|
|
|
|
diff = load_config(module, tostring(ele), warnings, action='replace')
|
|
|
|
|
if module.params['device_count']:
|
|
|
|
|
if item['device_count']:
|
|
|
|
|
top = 'chassis/aggregated-devices/ethernet'
|
|
|
|
|
device_count_to_xpath_map = {'device_count': {'xpath': 'device-count', 'leaf_only': True}}
|
|
|
|
|
|
|
|
|
|
validate_param_values(module, device_count_to_xpath_map)
|
|
|
|
|
|
|
|
|
|
want = map_params_to_obj(module, device_count_to_xpath_map)
|
|
|
|
|
ele = map_obj_to_ele(module, want, top)
|
|
|
|
|
validate_param_values(module, device_count_to_xpath_map, item)
|
|
|
|
|
|
|
|
|
|
diff = load_config(module, tostring(ele), warnings, action='replace')
|
|
|
|
|
want = map_params_to_obj(module, device_count_to_xpath_map, param=item)
|
|
|
|
|
ele = map_obj_to_ele(module, want, top, param=item)
|
|
|
|
|
requests.append(ele)
|
|
|
|
|
|
|
|
|
|
return diff
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def configure_member_params(module, warnings, diff=None):
|
|
|
|
|
def configure_member_params(module, requests, item):
|
|
|
|
|
top = 'interfaces/interface'
|
|
|
|
|
members = module.params['members']
|
|
|
|
|
members = item['members']
|
|
|
|
|
|
|
|
|
|
if members:
|
|
|
|
|
member_to_xpath_map = collections.OrderedDict()
|
|
|
|
@ -229,36 +232,34 @@ def configure_member_params(module, warnings, diff=None):
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
# link aggregation bundle assigned to member
|
|
|
|
|
module.params['bundle'] = module.params['name']
|
|
|
|
|
item['bundle'] = item['name']
|
|
|
|
|
|
|
|
|
|
for member in members:
|
|
|
|
|
|
|
|
|
|
if module.params['state'] == 'absent':
|
|
|
|
|
if item['state'] == 'absent':
|
|
|
|
|
# if link aggregate bundle is not assigned to member, trying to
|
|
|
|
|
# delete it results in rpc-reply error, hence if is not assigned
|
|
|
|
|
# skip deleting it and continue to next member.
|
|
|
|
|
resp = get_configuration(module)
|
|
|
|
|
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:
|
|
|
|
|
continue
|
|
|
|
|
# Name of member to be assigned to link aggregation bundle
|
|
|
|
|
module.params['name'] = member
|
|
|
|
|
|
|
|
|
|
validate_param_values(module, member_to_xpath_map)
|
|
|
|
|
item['name'] = member
|
|
|
|
|
|
|
|
|
|
want = map_params_to_obj(module, member_to_xpath_map)
|
|
|
|
|
ele = map_obj_to_ele(module, want, top)
|
|
|
|
|
diff = load_config(module, tostring(ele), warnings)
|
|
|
|
|
validate_param_values(module, member_to_xpath_map, item)
|
|
|
|
|
|
|
|
|
|
return diff
|
|
|
|
|
want = map_params_to_obj(module, member_to_xpath_map, param=item)
|
|
|
|
|
ele = map_obj_to_ele(module, want, top, param=item)
|
|
|
|
|
requests.append(ele)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
""" main entry point for module execution
|
|
|
|
|
"""
|
|
|
|
|
argument_spec = dict(
|
|
|
|
|
name=dict(required=True),
|
|
|
|
|
element_spec = dict(
|
|
|
|
|
name=dict(),
|
|
|
|
|
mode=dict(default='on', type='str', choices=['on', 'off', 'active', 'passive']),
|
|
|
|
|
members=dict(type='list'),
|
|
|
|
|
min_links=dict(type='int'),
|
|
|
|
@ -268,14 +269,32 @@ def main():
|
|
|
|
|
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)
|
|
|
|
|
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,
|
|
|
|
|
supports_check_mode=True,
|
|
|
|
|
required_one_of=required_one_of,
|
|
|
|
|
mutually_exclusive=mutually_exclusive,
|
|
|
|
|
supports_check_mode=True)
|
|
|
|
|
mutually_exclusive=mutually_exclusive)
|
|
|
|
|
|
|
|
|
|
warnings = list()
|
|
|
|
|
check_args(module, warnings)
|
|
|
|
@ -285,23 +304,33 @@ def main():
|
|
|
|
|
if warnings:
|
|
|
|
|
result['warnings'] = warnings
|
|
|
|
|
|
|
|
|
|
state = module.params.get('state')
|
|
|
|
|
module.params['disable'] = True if state == 'down' else False
|
|
|
|
|
params = to_param_list(module)
|
|
|
|
|
requests = list()
|
|
|
|
|
for param in params:
|
|
|
|
|
item = param.copy()
|
|
|
|
|
|
|
|
|
|
state = item.get('state')
|
|
|
|
|
item['disable'] = True if state == 'down' else False
|
|
|
|
|
|
|
|
|
|
if state in ('present', 'up', 'down'):
|
|
|
|
|
item['state'] = 'present'
|
|
|
|
|
|
|
|
|
|
if state in ('present', 'up', 'down'):
|
|
|
|
|
module.params['state'] = 'present'
|
|
|
|
|
else:
|
|
|
|
|
item['disable'] = True
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
module.params['disable'] = True
|
|
|
|
|
mode = item.get('mode')
|
|
|
|
|
if mode == 'off':
|
|
|
|
|
item['mode'] = ''
|
|
|
|
|
elif mode == 'on':
|
|
|
|
|
item['mode'] = 'passive'
|
|
|
|
|
|
|
|
|
|
if module.params.get('mode') == 'off':
|
|
|
|
|
module.params['mode'] = ''
|
|
|
|
|
elif module.params.get('mode') == 'on':
|
|
|
|
|
module.params['mode'] = 'passive'
|
|
|
|
|
configure_lag_params(module, requests, item)
|
|
|
|
|
configure_member_params(module, requests, item)
|
|
|
|
|
|
|
|
|
|
diff = None
|
|
|
|
|
with locked_config(module):
|
|
|
|
|
diff = configure_lag_params(module, warnings)
|
|
|
|
|
diff = configure_member_params(module, warnings, diff)
|
|
|
|
|
for req in requests:
|
|
|
|
|
diff = load_config(module, tostring(req), warnings, action='replace')
|
|
|
|
|
|
|
|
|
|
commit = not module.check_mode
|
|
|
|
|
if diff:
|
|
|
|
|