Skip to content

Commit

Permalink
eos_acls: Fixed typo and index out of range errors while handling pro…
Browse files Browse the repository at this point in the history
…tocol_options (#115)

eos_acls: Fixed typo and index out of range errors while handling protocol_options

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
GomathiselviS authored Sep 29, 2020
1 parent cfaa79e commit 111ad0e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/115-protocol-options-acls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fixed typo and index out of range errors while handling protocol_options. (https://github.com/ansible-collections/arista.eos/pull/115)
5 changes: 3 additions & 2 deletions plugins/module_utils/network/eos/config/acls/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,11 @@ def add_commands(want):
+ ace["protocol_options"][proto]["nexthop_group"]
)
elif proto == "tcp":
for flag, val in ace["prtocol_options"][proto][
for flag, val in ace["protocol_options"][proto][
"flags"
].items():
command = command + " " + val
if val:
command = command + " " + flag
if "hop_limit" in ace.keys():
for op, val in ace["hop_limit"].items():
command = command + " hop-limit " + op + " " + val
Expand Down
57 changes: 45 additions & 12 deletions plugins/module_utils/network/eos/facts/acls/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,16 @@ def render_config(self, spec, conf):
if seq:
ace_dict.update({"sequence": dev_config_remainder.pop(0)})
ace_dict.update({"grant": dev_config_remainder.pop(0)})
if dev_config_remainder[0] == "vlan":
if (
dev_config_remainder
and dev_config_remainder[0] == "vlan"
):
vlan_str = ""
dev_config_remainder.pop(0)
if dev_config_remainder[0] == "inner":
if (
dev_config_remainder
and dev_config_remainder[0] == "inner"
):
vlan_str = dev_config_remainder.pop(0) + " "
vlan_str = (
dev_config_remainder.pop(0)
Expand All @@ -176,12 +182,18 @@ def render_config(self, spec, conf):
src_address = re.search(
r"[a-z\d:\.]+", dev_config_remainder[0]
)
if dev_config_remainder[0] == "host":
if (
dev_config_remainder
and dev_config_remainder[0] == "host"
):
source_dict.update(
{"host": dev_config_remainder.pop(1)}
)
dev_config_remainder.pop(0)
elif dev_config_remainder[0] == "any":
elif (
dev_config_remainder
and dev_config_remainder[0] == "any"
):
source_dict.update({"any": True})
dev_config_remainder.pop(0)
elif src_prefix:
Expand All @@ -196,7 +208,10 @@ def render_config(self, spec, conf):
{"wildcard_bits": dev_config_remainder.pop(0)}
)
if dev_config_remainder:
if dev_config_remainder[0] in operator:
if (
dev_config_remainder
and dev_config_remainder[0] in operator
):
port_dict = {}
src_port = ""
src_opr = dev_config_remainder.pop(0)
Expand Down Expand Up @@ -232,10 +247,16 @@ def render_config(self, spec, conf):
dest_address = re.search(
r"[a-z\d:\.]+", dev_config_remainder[0]
)
if dev_config_remainder[0] == "host":
if (
dev_config_remainder
and dev_config_remainder[0] == "host"
):
dest_dict.update({"host": dev_config_remainder.pop(1)})
dev_config_remainder.pop(0)
elif dev_config_remainder[0] == "any":
elif (
dev_config_remainder
and dev_config_remainder[0] == "any"
):
dest_dict.update({"any": True})
dev_config_remainder.pop(0)
elif dest_prefix:
Expand Down Expand Up @@ -282,7 +303,10 @@ def render_config(self, spec, conf):
if protocol == "tcp" or "6":
protocol = "tcp"
flags_dict = {}
if dev_config_remainder[0] in flags:
if (
dev_config_remainder
and dev_config_remainder[0] in flags
):
flaglist = dev_config_remainder.copy()
for config_remainder in flaglist:
if config_remainder not in flags:
Expand All @@ -303,13 +327,19 @@ def render_config(self, spec, conf):
protocol = "icmp"
elif protocol == "58":
protocol = "icmpv6"
if dev_config_remainder[0] not in others:
if (
dev_config_remainder
and dev_config_remainder[0] not in others
):
icmp_dict.update({dev_config_remainder[0]: True})
dev_config_remainder.pop(0)
if bool(icmp_dict):
protocol_option_dict.update({protocol: icmp_dict})
if protocol == "ip" or "ipv6":
if dev_config_remainder[0] == "nexthop_group":
if protocol in ["ip", "ipv6"]:
if (
dev_config_remainder
and dev_config_remainder[0] == "nexthop_group"
):
dev_config_remainder.pop(0)
ip_dict.update(
{"nexthop_group": dev_config_remainder.pop(0)}
Expand All @@ -320,7 +350,10 @@ def render_config(self, spec, conf):
ace_dict.update(
{"protocol_options": protocol_option_dict}
)
if dev_config_remainder[0] == "ttl":
if (
dev_config_remainder
and dev_config_remainder[0] == "ttl"
):
dev_config_remainder.pop(0)
op = dev_config_remainder.pop(0)
ttl_dict = {op: dev_config_remainder.pop(0)}
Expand Down

0 comments on commit 111ad0e

Please sign in to comment.