Skip to content

Commit

Permalink
add playbook wrappers (#67)
Browse files Browse the repository at this point in the history
* rework of ACL interfaces
- fixed operation of replaced and deleted states
- edited test playbook
- added playbook wrapper
- unit tests: corrected to reflect change in config

* rework of acl module
- fixed minor bugs in facts gathering
- added playbook wrapper

* rework of user module
- minor correction of deleted state
- unit tests: changed to reflect change in config
- added playbook wrapper
  - changed original test playbook to follow
    test_init, test, functionality and added new tests

* playbook wrapper for lag_interfaces module
- awplus_lag_interfaces.yml: changed group 55 to group 66
  in test desciption

* playbook wrapper for static lag interfaces

* playbook wrapper for lldp interfaces

* playbook wrapper for l3 interfaces

* playbook wrapper for vlans

* playbook wrapper for vrfs

* playbook wrapper for lacp_interfaces

* playbook wrapper for interfaces

* playbook wrapper for banner

* playbook wrapper for ntp

* playbook wrapper for logging

* playbook wrapper for lldp global
  • Loading branch information
BenHoelker authored May 4, 2023
1 parent 4d1fcdb commit a5e317d
Show file tree
Hide file tree
Showing 35 changed files with 9,408 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def _state_replaced(self, want, have):
want_interfaces = self.get_structure_info(want)
have_interfaces = self.get_structure_info(have)

# iterates through all interfaces in want but not in have
for interface in list(set(want_interfaces.keys()).difference(set(have_interfaces.keys()))):
# add access-groups
commands.extend(self.generate_commands(interface, want_interfaces[interface], False))

# iterate through interfaces both in want and have
for interface in list(set(have_interfaces.keys()).intersection(set(want_interfaces.keys()))):
have_interfaces_set = set(have_interfaces[interface])
Expand Down Expand Up @@ -243,13 +248,8 @@ def _state_deleted(self, want, have):
have_interfaces_set = set(have_interfaces[interface])
want_interfaces_set = set(want_interfaces[interface])

if want_interfaces_set == set():
# If no acls specified in want,
# - remove all acls attached to said interface in have
removed_access_groups = have_interfaces[interface]
else:
# If access-groups isn't empty, remove only it's specified access-groups
removed_access_groups = list(have_interfaces_set.intersection(want_interfaces_set))
# If access-groups isn't empty, remove only it's specified access-groups
removed_access_groups = list(have_interfaces_set.intersection(want_interfaces_set))
commands.extend(self.generate_commands(interface, removed_access_groups, True))
return commands

Expand Down
2 changes: 0 additions & 2 deletions plugins/module_utils/network/awplus/config/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ def _state_deleted(self, want, have):
commands.append('username manager privilege 15 password friend')
if want:
commands.extend(self._clear_config(want, have))
else:
commands.extend(self._clear_config(have, have))
return commands

def _set_config(self, want, have):
Expand Down
32 changes: 26 additions & 6 deletions plugins/module_utils/network/awplus/facts/acl/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,29 @@ def render_ace_config(self, line, acl_type):

if re.search(r'icmp-type', line):
# handles icmp acls
acl_match = re.findall(r'(\d+) (permit|deny) (\S+) (\S+) (\S+) icmp-type (\d+)', line)
acl_match = re.findall(
r'(\d+) (permit|deny|copy-to-cpu|copy-to-mirror|send-to-mirror|send-to-cpu) '
r'(\S+) (\S+) (\S+) icmp-type (\d+)', line
)
elif re.search(r'(any)', line):
# if destination is any
acl_match = re.findall(r'(\d+) (permit|deny) (\S+) (\S+) (\S+) (\S+)', line)
acl_match = re.findall(
r'(\d+) (permit|deny|copy-to-cpu|copy-to-mirror|send-to-mirror|send-to-cpu) '
r'(\S+) (\S+) (\S+) (\S+)', line
)

else:
# if destination has address and wild card mask
acl_match = re.findall(r'(\d+) (permit|deny) (\S+) (\S+) (\S+) (\S+) (\S+)', line)
acl_match = re.findall(
r'(\d+) (permit|deny|copy-to-cpu|copy-to-mirror|send-to-mirror|send-to-cpu) '
r'(\S+) (\S+) (\S+) (\S+) (\S+)', line
)
if not acl_match:
# if the address prefix is used for addresses
acl_match = re.findall(r'(\d+) (permit|deny) (\S+) (\S+) (\S+)', line)
acl_match = re.findall(
r'(\d+) (permit|deny|copy-to-cpu|copy-to-mirror|send-to-mirror|send-to-cpu) '
r'(\S+) (\S+) (\S+)', line
)

if acl_match:
# assign parameters
Expand Down Expand Up @@ -239,9 +252,16 @@ def render_acl_config(self, data):
if re.search(r'access list', item):
acls_names.append(item)

for count, item in enumerate(acl_list):
temp_acl_list = acl_list
for count, item in enumerate(temp_acl_list):
for acl_name in acls_names:
if re.search(item[0], acl_name):
acl_name_match = re.search(r'(\S+) (IP|IPv6) access list (\d+|\S+)', acl_name)

item_name_match = re.search(r'(IP|IPv6) access list (\d+|\S+)', item[0])
check_acl_name = acl_name_match.group(3) if acl_name_match else None
item_name = item_name_match.group(2) if item_name_match else None

if check_acl_name == item_name and check_acl_name and item_name:
acl_list[count][0] = acl_name

# render each acl
Expand Down
Loading

0 comments on commit a5e317d

Please sign in to comment.