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

[ios_acls] enhance remarks behaviour #941

Merged
merged 28 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7d9741b
fix remarks behaviour
KB-perByte Oct 9, 2023
13fb97f
update remarks facts code
KB-perByte Oct 10, 2023
a7d1c1f
Merge branch 'main' into acl_order_remark
KB-perByte Oct 10, 2023
c23a6c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
d4f6018
fix config side code
KB-perByte Oct 12, 2023
a96989f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 12, 2023
e84227d
acls first cleanup
KB-perByte Oct 12, 2023
5845cb7
half test fix
KB-perByte Oct 16, 2023
47e6e5e
doc fixes
KB-perByte Oct 17, 2023
04792b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2023
5073eef
update tests and doc
KB-perByte Oct 17, 2023
1596acf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2023
1e8a0be
update doc
KB-perByte Oct 17, 2023
5d84af2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2023
b751f38
Merge branch 'main' into acl_order_remark
KB-perByte Oct 25, 2023
6ed8a6a
Merge branch 'main' into acl_order_remark
KB-perByte Oct 26, 2023
98bb74e
add changelog
KB-perByte Oct 26, 2023
34886ef
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
f5e37b4
lint issues
KB-perByte Oct 26, 2023
eaf1dc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
75cf9b7
fix edge remarks case
KB-perByte Oct 27, 2023
5831139
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2023
bc75936
update docs
KB-perByte Oct 27, 2023
eb9986a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2023
0c154ed
fix tests
KB-perByte Oct 27, 2023
1e7cd1f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2023
ee59724
use to_text
KB-perByte Oct 27, 2023
07fc540
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2023
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
4 changes: 4 additions & 0 deletions changelogs/fragments/acl_remaks_fresh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
minor_changes:
- "ios_acls - make remarks ordered and to be applied per ace basis."
- "ios_acls - remarks in replaced and overridden state to be negated once per ace."
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_acl_interfaces_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Examples
# ip access-group 123 out

# Using DELETED without any config passed
#"(NOTE: This will delete all of configured resource module attributes from each configured interface)"
# "(NOTE: This will delete all of configured resource module attributes from each configured interface)"

# Before state:
# -------------
Expand Down
496 changes: 409 additions & 87 deletions docs/cisco.ios.ios_acls_module.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_banner_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Examples
- name: Configure banner from file
cisco.ios.ios_banner:
banner: motd
text: "{{ lookup('file', './config_partial/raw_banner.cfg') }}" # Use unix formatted text files (LF not CRLF) to avoid idempotency issues.
text: "{{ lookup('file', './config_partial/raw_banner.cfg') }}" # Use unix formatted text files (LF not CRLF) to avoid idempotency issues.
state: present

- name: Configure the login banner using delimiter
Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_hostname_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Examples
# Before state:
# -------------

#router-ios#show running-config | section ^hostname
# router-ios#show running-config | section ^hostname
# hostname RouterTest

# Gathered play:
Expand Down
4 changes: 2 additions & 2 deletions docs/cisco.ios.ios_lag_interfaces_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Examples
- name: Port-channel20
members:
- member: GigabitEthernet0/3
mode: on
mode: "on"
- name: Port-channel30
members:
- member: GigabitEthernet0/4
Expand Down Expand Up @@ -461,7 +461,7 @@ Examples
# channel-group 30 mode active

# Using Deleted without any config passed
#"(NOTE: This will delete all of configured LLDP module attributes)"
# "(NOTE: This will delete all of configured LLDP module attributes)"

#
# Before state:
Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_linkagg_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Examples
- name: Create aggregate of linkagg definitions
cisco.ios.ios_linkagg:
aggregate:
- { group: 3, mode: on, members: [GigabitEthernet0/1] }
- { group: 3, mode: "on", members: [GigabitEthernet0/1] }
- { group: 100, mode: passive, members: [GigabitEthernet0/2] }


Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_lldp_global_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Examples
# lldp reinit 5

# Using Deleted without any config passed
#"(NOTE: This will delete all of configured LLDP module attributes)"
# "(NOTE: This will delete all of configured LLDP module attributes)"

# Before state:
# -------------
Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_logging_global_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ Examples
# Before state:
# -------------

#router-ios#show running-config | section logging
# router-ios#show running-config | section logging
# logging exception 4099
# logging message-counter log
# logging userinfo
Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_ntp_global_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ Examples
# Before state:
# -------------

#router-ios#show running-config | section ^ntp
# router-ios#show running-config | section ^ntp
# ntp max-associations 34
# ntp logging
# ntp allow mode control 4
Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_ospfv2_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4633,7 +4633,7 @@ Examples
passive_interfaces:
default: true
interface:
set_interface: False
set_interface: false
name:
- GigabitEthernet0/1
- GigabitEthernet0/2
Expand Down
2 changes: 0 additions & 2 deletions docs/cisco.ios.ios_prefix_lists_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ Examples
- afi: ipv4
state: deleted



# Task Output
# -------------
# before:
Expand Down
4 changes: 2 additions & 2 deletions docs/cisco.ios.ios_service_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,8 @@ Examples
# prompt: true
# slave_log: true

#·After·state:
#·------------
# After state:
# ------------
#
# router-ios#show running-config all | section ^service
# service slave-log
Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_snmp_server_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9371,7 +9371,7 @@ Examples
# Before state:
# -------------

#router-ios#show running-config | section ^snmp-server
# router-ios#show running-config | section ^snmp-server
# snmp-server engineID remote 172.16.0.12 udp-port 25 AB0C5342FF0F
# snmp-server user userPaul dev v1 access 24
# snmp-server group mergedGroup v3 auth
Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_vlans_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ Examples
# 1005 trnet 101005 1500 - - - ibm - 0 0

# Using Deleted without any config passed
#"(NOTE: This will delete all of configured vlans attributes)"
# "(NOTE: This will delete all of configured vlans attributes)"

# Before state:
# -------------
Expand Down
92 changes: 72 additions & 20 deletions plugins/module_utils/network/ios/config/acls/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

__metaclass__ = type

from ansible.module_utils._text import to_text
from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import (
ResourceModule,
Expand Down Expand Up @@ -149,11 +150,28 @@ def add_afi(entry, afi):
entry["afi"] = afi
return entry

def pop_remark(r_entry, afi):
"""Takes out remarks from ace entry as remarks not same
does not mean the ace entry to be re-introduced
"""
if r_entry.get("remarks"):
return r_entry.pop("remarks")
else:
return {}

for wseq, wentry in iteritems(want):
hentry = have.pop(wseq, {})
rem_hentry, rem_wentry = {}, {}

if hentry:
hentry = self.sanitize_protocol_options(wentry, hentry)
if hentry != wentry:

if hentry != wentry: # will let in if ace is same but remarks is not same
if hentry:
rem_hentry["remarks"] = pop_remark(hentry, afi)
if wentry:
rem_wentry["remarks"] = pop_remark(wentry, afi)

if hentry:
if self.state == "merged":
self._module.fail_json(
Expand All @@ -164,24 +182,51 @@ def add_afi(entry, afi):
),
)
else: # other action states
if hentry.get("remarks"): # remove remark if not in want
for rems in hentry.get("remarks"):
if rems not in wentry.get("remarks", {}):
self.addcmd({"remarks": rems}, "remarks", negate=True)
else: # remove ace if not in want
if rem_hentry.get("remarks"): # remove remark if not in want
for k_hrems, hrems in rem_hentry.get("remarks").items():
if k_hrems not in rem_wentry.get("remarks", {}).keys():
if self.state in ["replaced", "overridden"]:
self.addcmd(
{
"remarks": hrems,
"sequence": hentry.get("sequence", ""),
},
"remarks_no_data",
negate=True,
)
break
else:
self.addcmd(
{
"remarks": hrems,
"sequence": hentry.get("sequence", ""),
},
"remarks",
negate=True,
)
# remove ace if not in want
if hentry != wentry:
self.addcmd(add_afi(hentry, afi), "aces", negate=True)
if wentry.get("remarks"): # add remark if not in have
for rems in wentry.get("remarks"):
if rems not in hentry.get("remarks", {}):
self.addcmd({"remarks": rems}, "remarks")
else: # add ace if not in have
if rem_wentry.get("remarks"): # add remark if not in have
for k_wrems, wrems in rem_wentry.get("remarks").items():
if k_wrems not in rem_hentry.get("remarks", {}).keys():
self.addcmd(
{"remarks": wrems, "sequence": hentry.get("sequence", "")},
"remarks",
)
# add ace if not in have
if hentry != wentry:
self.addcmd(add_afi(wentry, afi), "aces")

# remove remaining entries from have aces list
for hseq in have.values():
if hseq.get("remarks"): # remove remarks that are extra in have
for rems in hseq.get("remarks"):
self.addcmd({"remarks": rems}, "remarks", negate=True)
for krems, rems in hseq.get("remarks").items():
self.addcmd(
{"remarks": rems, "sequence": hseq.get("sequence", "")},
"remarks",
negate=True,
)
else: # remove extra aces
self.addcmd(add_afi(hseq, afi), "aces", negate=True)

Expand Down Expand Up @@ -225,7 +270,7 @@ def list_to_dict(self, param):
for acl in each.get("acls"): # check each acl for aces
temp_aces = {}
if acl.get("aces"):
temp_rem = [] # remarks if defined in an ace
rem_idx = 0 # remarks if defined in an ace
for ace in acl.get("aces"): # each ace turned to dict
if (
ace.get("destination")
Expand Down Expand Up @@ -258,18 +303,25 @@ def list_to_dict(self, param):
),
)

if ace.get("remarks"):
en_name = str(acl.get("name")) + "remark"
temp_rem.extend(ace.pop("remarks"))
if ace.get(
"remarks",
): # index aces inside of each ace don't cluster them all
rem_ace = {}
# en_name = str(acl.get("name")) + "remark"
# temp_rem.extend(ace.pop("remarks"))
for remks in ace.get("remarks"):
rem_ace[remks.replace(" ", "_")] = remks
rem_idx += 1
ace["remarks"] = rem_ace

if ace.get("sequence"):
temp_aces.update({ace.get("sequence"): ace})
elif ace:
count += 1
temp_aces.update({"_" + str(count): ace})
temp_aces.update({"_" + to_text(count): ace})

if temp_rem: # add remarks to the temp ace
temp_aces.update({en_name: {"remarks": temp_rem}})
# if temp_rem: # add remarks to the temp ace
# temp_aces.update({en_name: {"remarks": temp_rem}})

if acl.get("acl_type"): # update acl dict with req info
temp_acls.update(
Expand Down
Loading
Loading