Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounce bridge port interfaces if bridge is bounced #165

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions filter_plugins/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,26 @@ def bond_check(context, interface):

return result

def select_changed_bridge_ports(port_results, bridges):
"""Selects bridge ports that need to be bounced

This is not a general purpose filter and is specific to the
code in bridge_configuration.yml

:param port_results: The Ansible result objects obtained from templating
the network interface configuration files
:param bridges: A list of bridges that have been changed.
:returns: port_results with filtering applied
"""
result = []
for pr in port_results:
bridge = pr["item"][0]["device"]
port = pr["item"][1]
if bridge in bridges:
result.append(port)
elif pr["changed"]:
result.append(port)
return result

class FilterModule(object):
"""Interface comparison filters."""
Expand All @@ -249,4 +269,5 @@ def filters(self):
'ether_check': ether_check,
'bridge_check': bridge_check,
'bond_check': bond_check,
'select_changed_bridge_ports': select_changed_bridge_ports
}
14 changes: 7 additions & 7 deletions tasks/bridge_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@
list) |
list }}

# bridge_interfaces_changed and bridge_port_interfaces_changed are used in the
# 'Bounce network devices' handler.
- name: Set facts containing changed bridge and bridge port devices
# bridge_interfaces_changed is used in the 'Bounce network devices' handler.
- name: Set facts containing changed bridge devices
set_fact:
# Select those tasks which changed, and map to a list of the corresponding
# bridge devices.
Expand All @@ -133,11 +132,12 @@
bridge_interfaces_with_all_ports_changed) |
unique |
list }}
# Select those tasks which changed, and map to a list of the corresponding
# bridge port devices.

# bridge_port_interfaces_changed is used in the 'Bounce network devices' handler.
- name: Set facts containing changed bridge port devices
set_fact:
bridge_port_interfaces_changed: >
{{ bridge_port_result.results |
select('changed') |
map(attribute='item.1') |
select_changed_bridge_ports(bridge_interfaces_changed) |
unique |
list }}