Skip to content

Commit

Permalink
fix remarks behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
KB-perByte committed Oct 9, 2023
1 parent 6e7edbc commit 7d9741b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 62 deletions.
23 changes: 14 additions & 9 deletions plugins/module_utils/network/ios/facts/acls/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ def __init__(self, module):
self._module = module
self.argument_spec = AclsArgs.argument_spec

# def get_acl_data(self, connection):
# # Get the access-lists from the ios router
# # Get the remarks on access-lists from the ios router
# # alternate command 'sh run partition access-list' but has a lot of ordering issues
# # and incomplete ACLs are not viewed correctly
# _acl_data = connection.get("show access-list")
# _remarks_data = connection.get("show running-config | include ip(v6)* access-list|remark")
# if _remarks_data:
# _acl_data += "\n" + _remarks_data
# return _acl_data

def get_acl_data(self, connection):
# Get the access-lists from the ios router
# Get the remarks on access-lists from the ios router
# alternate command 'sh run partition access-list' but has a lot of ordering issues
# and incomplete ACLs are not viewed correctly
_acl_data = connection.get("show access-list")
_remarks_data = connection.get("show running-config | include ip(v6)* access-list|remark")
if _remarks_data:
_acl_data += "\n" + _remarks_data
return _acl_data
# Removed the show access-list
# Removed the show running-config | include ip(v6)* access-list|remark
return connection.get("sh running-config | section access-list")

def sanitize_data(self, data):
"""removes matches or extra config info that is added on acl match"""
Expand Down
85 changes: 32 additions & 53 deletions plugins/module_utils/network/ios/rm_templates/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,98 +122,79 @@ def __init__(self, lines=None):
{
"name": "acls_name",
"getval": re.compile(
r"""^(?P<acl_type>Standard|Extended|Reflexive)*
\s*(?P<afi>IP|IPv6)*
\s*access*
\s*list*
\s*(?P<acl_name>.+)*
r"""^(?P<afi>ip|ipv6|mac)
(\s(access-list))
(\s(?P<acl_type>standard|extended|reflexive))?
(\s(?P<acl_name>\S+))
$""",
re.VERBOSE,
),
"compval": "name",
"setval": "name",
"result": {
"acls": {
"{{ acl_name|d() }}": {
"name": "{{ acl_name }}",
"acl_type": "{{ acl_type.lower() if acl_type is defined }}",
"afi": "{{ 'ipv4' if afi == 'IP' else 'ipv6' }}",
"afi": "{{ 'ipv4' if afi == 'ip' else 'ipv6' }}",
},
},
},
"shared": True,
},
{
"name": "_acls_name",
"name": "remarks_ipv4",
"getval": re.compile(
r"""^(ip|ipv6)
(\s(access-list))
(\s(standard|extended))
(\s(?P<acl_name_r>\S+))
$""",
re.VERBOSE,
),
"compval": "name",
"setval": "ip access-list",
"result": {},
"shared": True,
},
{
"name": "_mac_acls_name", # mac acls to be removed
"getval": re.compile(
r"""^(?P<acl_type>Standard|Extended|Reflexive)
(\s(?P<afi>MAC))
(\saccess\slist)
(\s(?P<acl_name>.+))
r"""\s*((?P<sequence>\d+))
(\sremark\s(?P<remarks>.+))
$""",
re.VERBOSE,
),
"compval": "name",
"setval": "",
"setval": "remark {{ remarks }}",
"result": {
"acls": {
"{{ acl_name|d() }}": {
"name": "{{ acl_name }}",
"acl_type": "{{ acl_type.lower() if acl_type is defined }}",
"afi": "{{ afi }}",
"{{ sequence }}": [
"{{ remarks }}",
],
},
},
},
"shared": True,
},
{
"name": "remarks",
"name": "remarks_ipv4_no_seq",
"getval": re.compile(
r"""\s+remark
(\s(?P<remarks>.+))?
$""",
r"""\s*^remark\s(?P<remarks>.+)$""",
re.VERBOSE,
),
"setval": "remark {{ remarks }}",
"result": {
"acls": {
"{{ acl_name_r|d() }}": {
"name": "{{ acl_name_r }}",
"aces": [{"remarks": "{{ remarks }}"}],
"{{ acl_name|d() }}": {
"name": "{{ acl_name }}",
"remarks": [
"{{ remarks }}",
],
},
},
},
},
{
"name": "remarks_type_linear",
"name": "remarks_ipv6",
"getval": re.compile(
r"""^(access-list)
(\s(?P<acl_name_linear>\S+))
r"""\s*(sequence\s(?P<sequence>\d+))
(\sremark\s(?P<remarks>.+))
$""",
re.VERBOSE,
),
"setval": "remark {{ remarks }}",
"result": {
"acls": {
"{{ acl_name_linear|d() }}": {
"name": "{{ acl_name_linear }}",
"aces": [{"remarks": "{{ remarks }}"}],
"{{ acl_name|d() }}": {
"name": "{{ acl_name }}",
"{{ sequence }}": [
"{{ remarks }}",
],
},
},
},
Expand All @@ -222,11 +203,10 @@ def __init__(self, lines=None):
"name": "aces_ipv4_standard",
"getval": re.compile(
r"""\s*(?P<sequence>\d+)*
\s(?P<grant>deny|permit)?
(\s+(?P<address>(?!ahp|any|eigrp|esp|gre|icmp|igmp|ipv6|ipinip|ip|nos|object-group|ospf|pcp|pim|sctp|tcp|udp)\S+|\S+,))?
(\s(?P<grant>deny|permit))
(\s+(?P<address>((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))?
(\s(?P<wildcard>((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))?
(\s*(?P<any>any))?
(\swildcard\sbits\s(?P<wildcard>\S+))?
(\shost\s(?P<host>\S+))?
(\s(?P<log>log))?
$""",
re.VERBOSE,
Expand All @@ -244,7 +224,6 @@ def __init__(self, lines=None):
"address": "{{ address }}",
"wildcard_bits": "{{ wildcard }}",
"any": "{{ not not any }}",
"host": "{{ host }}",
},
"log": {"set": "{{ not not log }}"},
},
Expand All @@ -256,11 +235,12 @@ def __init__(self, lines=None):
{
"name": "aces",
"getval": re.compile(
r"""\s*((?P<sequence>\d+))?
r"""(\s*(?P<sequence>\d+))?
(\s*sequence\s(?P<sequence_ipv6>\d+))?
(\s*(?P<grant>deny|permit))
(\sevaluate\s(?P<evaluate>\S+))?
(\s(?P<protocol_num>\d+))?
(\s(?P<protocol>ahp|eigrp|esp|gre|icmp|igmp|ipv6|ipinip|ip|nos|ospf|pcp|pim|sctp|tcp|udp))?
(\s*(?P<protocol>ahp|eigrp|esp|gre|icmp|igmp|ipv6|ipinip|ip|nos|ospf|pcp|pim|sctp|tcp|udp))?
((\s(?P<source_any>any))|
(\sobject-group\s(?P<source_obj_grp>\S+))|
(\shost\s(?P<source_host>\S+))|
Expand Down Expand Up @@ -294,7 +274,6 @@ def __init__(self, lines=None):
(\sttl\sgt\s(?P<ttl_gt>\d+))?
(\sttl\slt\s(?P<ttl_lt>\d+))?
(\sttl\sneg\s(?P<ttl_neg>\d+))?
(\ssequence\s(?P<sequence_ipv6>\d+))?
""",
re.VERBOSE,
),
Expand Down

0 comments on commit 7d9741b

Please sign in to comment.