summaryrefslogtreecommitdiff
path: root/plugins/module_utils
diff options
context:
space:
mode:
authorGaige B Paulsen <gaige@cluetrust.com>2025-02-01 19:27:36 -0500
committerGitHub <noreply@github.com>2025-02-01 19:27:36 -0500
commit8b52367a05885ad11f3aae41f2e1228261d8db7e (patch)
treeaea7bad8626b8530821a3457d175dfb1311d60d9 /plugins/module_utils
parent5e12a15b2ed6dfa4cc598153b00d240bf64d6fa2 (diff)
parent563ee2480aeb3378ea05e1bed4d042afeb9b6e69 (diff)
downloadvyos.vyos-dependabot/github_actions/actions/setup-python-5.tar.gz
vyos.vyos-dependabot/github_actions/actions/setup-python-5.zip
Merge branch 'main' into dependabot/github_actions/actions/setup-python-5dependabot/github_actions/actions/setup-python-5
Diffstat (limited to 'plugins/module_utils')
-rw-r--r--plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py18
-rw-r--r--plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py29
-rw-r--r--plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py48
3 files changed, 20 insertions, 75 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py
index 74fa9c12..6ae17585 100644
--- a/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py
@@ -217,24 +217,6 @@ class Firewall_rulesArgs(object): # pylint: disable=R0903
},
"type": "dict",
},
- "p2p": {
- "elements": "dict",
- "options": {
- "application": {
- "choices": [
- "all",
- "applejuice",
- "bittorrent",
- "directconnect",
- "edonkey",
- "gnutella",
- "kazaa",
- ],
- "type": "str",
- },
- },
- "type": "list",
- },
"packet_length": {
"elements": "dict",
"options": {"length": {"type": "str"}},
diff --git a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
index 68ceff80..2942b191 100644
--- a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
@@ -406,8 +406,6 @@ class Firewall_rules(ConfigBase):
and not self._is_del(l_set, h)
):
commands.append(self._add_r_base_attrib(rs_id, key, w, opr=opr))
- elif key == "p2p":
- commands.extend(self._add_p2p(key, w, h, cmd, opr))
elif key == "tcp":
commands.extend(self._add_tcp(key, w, h, cmd, opr))
elif key == "time":
@@ -430,31 +428,6 @@ class Firewall_rules(ConfigBase):
commands.extend(self._add_interface(key, w, h, cmd, opr))
return commands
- def _add_p2p(self, attr, w, h, cmd, opr):
- """
- This function forms the set/delete commands based on the 'opr' type
- for p2p applications attributes.
- :param want: desired config.
- :param have: target config.
- :return: generated commands list.
- """
- commands = []
- have = []
- if w:
- want = w.get(attr) or []
- if h:
- have = h.get(attr) or []
- if want:
- if opr:
- applications = list_diff_want_only(want, have)
- for app in applications:
- commands.append(cmd + (" " + attr + " " + app["application"]))
- elif not opr and have:
- applications = list_diff_want_only(want, have)
- for app in applications:
- commands.append(cmd + (" " + attr + " " + app["application"]))
- return commands
-
def _add_state(self, attr, w, h, cmd, opr):
"""
This function forms the command for 'state' attributes based on the 'opr'.
@@ -805,7 +778,7 @@ class Firewall_rules(ConfigBase):
if opr and not (
h_limit
and self._is_w_same(rate, h_limit, "unit")
- and self.is_w_same(rate, h_limit, "number")
+ and self._is_w_same(rate, h_limit, "number")
):
commands.append(
cmd
diff --git a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
index 3da70891..a6b56345 100644
--- a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
@@ -224,7 +224,6 @@ class Firewall_rulesFacts(object):
]
rule = self.parse_attr(conf, a_lst)
r_sub = {
- "p2p": self.parse_p2p(conf),
"tcp": self.parse_tcp(conf),
"icmp": self.parse_icmp(conf, "icmp"),
"time": self.parse_time(conf, "time"),
@@ -269,23 +268,6 @@ class Firewall_rulesFacts(object):
lengths.append(obj)
return lengths
- def parse_p2p(self, conf):
- """
- This function forms the regex to fetch the 'p2p' with in
- 'rules'
- :param conf: configuration data.
- :return: generated rule list configuration.
- """
- a_lst = []
- applications = findall(r"p2p (?:\'*)(\d+)(?:\'*)", conf, M)
- if applications:
- app_lst = []
- for r in set(applications):
- obj = {"application": r.strip("'")}
- app_lst.append(obj)
- a_lst = sorted(app_lst, key=lambda i: i["application"])
- return a_lst
-
def parse_src_or_dest(self, conf, attrib=None):
"""
This function triggers the parsing of 'source or
@@ -447,17 +429,6 @@ class Firewall_rulesFacts(object):
cfg_dict["rate"] = self.parse_rate(conf, "rate")
return cfg_dict
- def parse_rate(self, conf, attrib=None):
- """
- This function triggers the parsing of 'rate' attributes.
- :param conf: configuration.
- :param attrib: 'rate'
- :return: generated config dictionary.
- """
- a_lst = ["unit", "number"]
- cfg_dict = self.parse_attr(conf, a_lst, match=attrib)
- return cfg_dict
-
def parse_attr(self, conf, attr_list, match=None):
"""
This function peforms the following:
@@ -490,6 +461,7 @@ class Firewall_rulesFacts(object):
if attrib == 'log':
out = search(r"^.*\d+" + " (log$)", conf, M)
if out:
+
val = out.group(1).strip("'")
if self.is_num(attrib):
val = int(val)
@@ -537,3 +509,21 @@ class Firewall_rulesFacts(object):
"""
num_set = ("time", "code", "type", "count", "burst", "number")
return True if attrib in num_set else False
+
+ def parse_rate(self, conf, match):
+ """
+ This function triggers the parsing of 'rate' attributes.
+ :param conf: configuration.
+ :param attrib: 'rate'
+ :return: generated config dictionary.
+ """
+ config = {}
+
+ out = search(r"^.*" + match + " (.+)", conf, M)
+ if out:
+ val = out.group(1).strip("'")
+ if "/" in val: # number/unit
+ (number, unit) = val.split("/")
+ config['number'] = number
+ config['unit'] = unit
+ return config