|
|
@ -255,16 +255,18 @@ def get_existing(module, args):
|
|
|
|
return existing, interface_exist
|
|
|
|
return existing, interface_exist
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def config_portchannel(proposed, mode, group):
|
|
|
|
def config_portchannel(proposed, mode, group, force):
|
|
|
|
commands = []
|
|
|
|
commands = []
|
|
|
|
|
|
|
|
# NOTE: Leading whitespace for force option is important
|
|
|
|
|
|
|
|
force = ' force' if force else ''
|
|
|
|
config_args = {
|
|
|
|
config_args = {
|
|
|
|
'mode': 'channel-group {group} mode {mode}',
|
|
|
|
'mode': 'channel-group {group}{force} mode {mode}',
|
|
|
|
'min_links': 'lacp min-links {min_links}',
|
|
|
|
'min_links': 'lacp min-links {min_links}',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for member in proposed.get('members', []):
|
|
|
|
for member in proposed.get('members', []):
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
|
commands.append(config_args.get('mode').format(group=group, mode=mode))
|
|
|
|
commands.append(config_args.get('mode').format(group=group, force=force, mode=mode))
|
|
|
|
|
|
|
|
|
|
|
|
min_links = proposed.get('min_links', None)
|
|
|
|
min_links = proposed.get('min_links', None)
|
|
|
|
if min_links:
|
|
|
|
if min_links:
|
|
|
@ -276,7 +278,7 @@ def config_portchannel(proposed, mode, group):
|
|
|
|
return commands
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_commands_to_add_members(proposed, existing, module):
|
|
|
|
def get_commands_to_add_members(proposed, existing, force, module):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
proposed_members = proposed['members']
|
|
|
|
proposed_members = proposed['members']
|
|
|
|
except KeyError:
|
|
|
|
except KeyError:
|
|
|
@ -290,11 +292,13 @@ def get_commands_to_add_members(proposed, existing, module):
|
|
|
|
members_to_add = list(set(proposed_members).difference(existing_members))
|
|
|
|
members_to_add = list(set(proposed_members).difference(existing_members))
|
|
|
|
|
|
|
|
|
|
|
|
commands = []
|
|
|
|
commands = []
|
|
|
|
|
|
|
|
# NOTE: Leading whitespace for force option is important
|
|
|
|
|
|
|
|
force = ' force' if force else ''
|
|
|
|
if members_to_add:
|
|
|
|
if members_to_add:
|
|
|
|
for member in members_to_add:
|
|
|
|
for member in members_to_add:
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
|
commands.append('channel-group {0} mode {1}'.format(
|
|
|
|
commands.append('channel-group {0}{1} mode {2}'.format(
|
|
|
|
existing['group'], proposed['mode']))
|
|
|
|
existing['group'], force, proposed['mode']))
|
|
|
|
|
|
|
|
|
|
|
|
return commands
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
|
@ -320,7 +324,7 @@ def get_commands_to_remove_members(proposed, existing, module):
|
|
|
|
return commands
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_commands_if_mode_change(proposed, existing, group, mode, module):
|
|
|
|
def get_commands_if_mode_change(proposed, existing, group, mode, force, module):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
proposed_members = proposed['members']
|
|
|
|
proposed_members = proposed['members']
|
|
|
|
except KeyError:
|
|
|
|
except KeyError:
|
|
|
@ -346,6 +350,8 @@ def get_commands_if_mode_change(proposed, existing, group, mode, module):
|
|
|
|
members_with_mode_change.append(interface)
|
|
|
|
members_with_mode_change.append(interface)
|
|
|
|
|
|
|
|
|
|
|
|
commands = []
|
|
|
|
commands = []
|
|
|
|
|
|
|
|
# NOTE: Leading whitespace for force option is important
|
|
|
|
|
|
|
|
force = ' force' if force else ''
|
|
|
|
if members_with_mode_change:
|
|
|
|
if members_with_mode_change:
|
|
|
|
for member in members_with_mode_change:
|
|
|
|
for member in members_with_mode_change:
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
@ -353,7 +359,7 @@ def get_commands_if_mode_change(proposed, existing, group, mode, module):
|
|
|
|
|
|
|
|
|
|
|
|
for member in members_with_mode_change:
|
|
|
|
for member in members_with_mode_change:
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
|
commands.append('interface {0}'.format(member))
|
|
|
|
commands.append('channel-group {0} mode {1}'.format(group, mode))
|
|
|
|
commands.append('channel-group {0}{1} mode {2}'.format(group, force, mode))
|
|
|
|
|
|
|
|
|
|
|
|
return commands
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
|
@ -388,7 +394,7 @@ def state_present(module, existing, proposed, interface_exist, force, warnings):
|
|
|
|
min_links = module.params['min_links']
|
|
|
|
min_links = module.params['min_links']
|
|
|
|
|
|
|
|
|
|
|
|
if not interface_exist:
|
|
|
|
if not interface_exist:
|
|
|
|
command = config_portchannel(proposed, mode, group)
|
|
|
|
command = config_portchannel(proposed, mode, group, force)
|
|
|
|
commands.append(command)
|
|
|
|
commands.append(command)
|
|
|
|
commands.insert(0, 'interface port-channel{0}'.format(group))
|
|
|
|
commands.insert(0, 'interface port-channel{0}'.format(group))
|
|
|
|
warnings.append("The proposed port-channel interface did not "
|
|
|
|
warnings.append("The proposed port-channel interface did not "
|
|
|
@ -400,10 +406,10 @@ def state_present(module, existing, proposed, interface_exist, force, warnings):
|
|
|
|
command = get_commands_to_remove_members(proposed, existing, module)
|
|
|
|
command = get_commands_to_remove_members(proposed, existing, module)
|
|
|
|
commands.append(command)
|
|
|
|
commands.append(command)
|
|
|
|
|
|
|
|
|
|
|
|
command = get_commands_to_add_members(proposed, existing, module)
|
|
|
|
command = get_commands_to_add_members(proposed, existing, force, module)
|
|
|
|
commands.append(command)
|
|
|
|
commands.append(command)
|
|
|
|
|
|
|
|
|
|
|
|
mode_command = get_commands_if_mode_change(proposed, existing, group, mode, module)
|
|
|
|
mode_command = get_commands_if_mode_change(proposed, existing, group, mode, force, module)
|
|
|
|
commands.insert(0, mode_command)
|
|
|
|
commands.insert(0, mode_command)
|
|
|
|
|
|
|
|
|
|
|
|
if min_links:
|
|
|
|
if min_links:
|
|
|
|