Skip to content

Commit

Permalink
Bounce bridge port interfaces if bridge is bounced
Browse files Browse the repository at this point in the history
  • Loading branch information
jovial committed Sep 27, 2024
1 parent 4ecee7b commit 7d0b0af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
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 }}

0 comments on commit 7d0b0af

Please sign in to comment.