Debian Codegraph @

ansible_collections/community/proxmox/plugins/module_utils/proxmox_node_firewall.py

raw
1 # Copyright (c) 2026, Clément Cruau (@PendaGTP) <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
6 ansible_to_proxmox_bool,
7 proxmox_to_ansible_bool,
8 )
9
10 SCHEMA = {
11 "enabled": {
12 "api": "enable",
13 "default": False,
14 "to_api": ansible_to_proxmox_bool,
15 "from_api": proxmox_to_ansible_bool,
16 },
17 "log_level_in": {"default": "nolog"},
18 "log_level_out": {"default": "nolog"},
19 "log_level_forward": {"default": "nolog"},
20 "ndp": {
21 "default": True,
22 "to_api": ansible_to_proxmox_bool,
23 "from_api": proxmox_to_ansible_bool,
24 },
25 "nftables": {
26 "default": False,
27 "to_api": ansible_to_proxmox_bool,
28 "from_api": proxmox_to_ansible_bool,
29 },
30 "nosmurfs": {
31 "default": True,
32 "to_api": ansible_to_proxmox_bool,
33 "from_api": proxmox_to_ansible_bool,
34 },
35 "smurf_log_level": {"default": "nolog"},
36 "tcp_flags_log_level": {"default": "nolog"},
37 "tcpflags": {
38 "default": False,
39 "to_api": ansible_to_proxmox_bool,
40 "from_api": proxmox_to_ansible_bool,
41 },
42 "nf_conntrack_allow_invalid": {
43 "default": False,
44 "to_api": ansible_to_proxmox_bool,
45 "from_api": proxmox_to_ansible_bool,
46 },
47 "nf_conntrack_helpers": {"default": None},
48 "nf_conntrack_max": {"default": 262144},
49 "nf_conntrack_tcp_timeout_established": {"default": 432000},
50 "nf_conntrack_tcp_timeout_syn_recv": {"default": 60},
51 "protection_synflood": {
52 "default": False,
53 "to_api": ansible_to_proxmox_bool,
54 "from_api": proxmox_to_ansible_bool,
55 },
56 "protection_synflood_burst": {"default": 1000},
57 "protection_synflood_rate": {"default": 200},
58 }
59
60
61 def node_firewall_options_to_ansible_result(node_name, raw):
62 """
63 Build the Ansible-side node firewall options dict from API data.
64
65 Args:
66 node_name (str): Name of the node.
67 raw (dict): Raw firewall data to process.
68
69 Returns:
70 dict: Firewall settings converted into pythonic values.
71 """
72 result = {
73 "node_name": node_name,
74 }
75
76 for field, meta in SCHEMA.items():
77 api_key = meta.get("api", field)
78 value = raw.get(api_key, meta.get("default"))
79
80 if "from_api" in meta:
81 value = meta["from_api"](value)
82
83 result[field] = value
84
85 return result