refactor(firewall): SNMP's firewall step lives with the others in OpenPortMixin
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 1m2s
driver / test (3.12) (pull_request) Successful in 1m6s
driver / lowest (pull_request) Successful in 28s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 2m26s
driver / publish (pull_request) Skipped
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 1m2s
driver / test (3.12) (pull_request) Successful in 1m6s
driver / lowest (pull_request) Successful in 28s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 2m26s
driver / publish (pull_request) Skipped
This commit is contained in:
1 parent
70b605d05b
commit
fc4f08302c
3 files changed
+8
-6
No files matched your search
@@ -13,6 +13,7 @@ from typing import TYPE_CHECKING, Literal
|
|||||||
|
|
||||||
from napalm_device_types import (
|
from napalm_device_types import (
|
||||||
OPENED_PORTS_RECORD,
|
OPENED_PORTS_RECORD,
|
||||||
|
SNMP_PURPOSE,
|
||||||
FixStepOutcomeDict,
|
FixStepOutcomeDict,
|
||||||
OpenedRuleDict,
|
OpenedRuleDict,
|
||||||
opened_rule_line,
|
opened_rule_line,
|
||||||
@@ -24,6 +25,7 @@ from napalm_device_types import (
|
|||||||
ufw_allow_recorded_command,
|
ufw_allow_recorded_command,
|
||||||
ufw_delete_command,
|
ufw_delete_command,
|
||||||
)
|
)
|
||||||
|
from napalm_device_types.models import SnmpAgentSettingsDict
|
||||||
|
|
||||||
from napalm_linux._snmp_agent import (
|
from napalm_linux._snmp_agent import (
|
||||||
_source,
|
_source,
|
||||||
@@ -83,7 +85,7 @@ def _count_command(firewall: Firewall, port: int, proto: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
class OpenPortMixin:
|
class OpenPortMixin:
|
||||||
"""``_allow_sources`` and ``_revoke_sources``: the shared firewall steps."""
|
"""``_allow_sources`` and ``_revoke_sources``: the shared firewall steps, and SNMP's."""
|
||||||
|
|
||||||
def _firewall(self) -> Firewall:
|
def _firewall(self) -> Firewall:
|
||||||
"""The firewall this host runs. firewalld first: its hosts have iptables too, and
|
"""The firewall this host runs. firewalld first: its hosts have iptables too, and
|
||||||
@@ -120,6 +122,10 @@ class OpenPortMixin:
|
|||||||
done = f"{proto}/{port} open for {', '.join(sources)}"
|
done = f"{proto}/{port} open for {', '.join(sources)}"
|
||||||
return self._root_outcome(" && ".join(rules), 30, done)
|
return self._root_outcome(" && ".join(rules), 30, done)
|
||||||
|
|
||||||
|
def _allow_snmp_sources(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict:
|
||||||
|
"""SNMP's firewall step (napalm-device-types ``SnmpAgentMixin``): udp/161."""
|
||||||
|
return self._allow_sources(settings.get("allowed_sources", []), 161, "udp", SNMP_PURPOSE)
|
||||||
|
|
||||||
def _revoke_sources(self, purpose: str, port: int, proto: str) -> FixStepOutcomeDict:
|
def _revoke_sources(self, purpose: str, port: int, proto: str) -> FixStepOutcomeDict:
|
||||||
"""Remove the rules recorded under *purpose*, whatever port they opened, and
|
"""Remove the rules recorded under *purpose*, whatever port they opened, and
|
||||||
nothing else; report what is left for *proto*/*port*.
|
nothing else; report what is left for *proto*/*port*.
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ from napalm_device_types import (
|
|||||||
DNF_INSTALLED_CVES_COMMAND,
|
DNF_INSTALLED_CVES_COMMAND,
|
||||||
DNF_SECURITY_COMMAND,
|
DNF_SECURITY_COMMAND,
|
||||||
LLDPCTL_KEYVALUE_COMMAND,
|
LLDPCTL_KEYVALUE_COMMAND,
|
||||||
SNMP_PURPOSE,
|
|
||||||
AptProxyMixin,
|
AptProxyMixin,
|
||||||
ByteStream,
|
ByteStream,
|
||||||
CommandResult,
|
CommandResult,
|
||||||
@@ -1798,9 +1797,6 @@ class LinuxDriver(
|
|||||||
return {"ok": False, "output": (written.stdout or written.stderr).strip()[-300:]}
|
return {"ok": False, "output": (written.stdout or written.stderr).strip()[-300:]}
|
||||||
return {"ok": True, "output": f"wrote {_SNMPD_CONF}"}
|
return {"ok": True, "output": f"wrote {_SNMPD_CONF}"}
|
||||||
|
|
||||||
def _allow_snmp_sources(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict:
|
|
||||||
return self._allow_sources(settings.get("allowed_sources", []), 161, "udp", SNMP_PURPOSE)
|
|
||||||
|
|
||||||
def _start_snmp_agent(self) -> FixStepOutcomeDict:
|
def _start_snmp_agent(self) -> FixStepOutcomeDict:
|
||||||
return self._root_outcome(
|
return self._root_outcome(
|
||||||
"systemctl enable snmpd && systemctl restart snmpd && systemctl is-active snmpd",
|
"systemctl enable snmpd && systemctl restart snmpd && systemctl is-active snmpd",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"napalm_linux.linux"
|
"napalm_linux.linux"
|
||||||
],
|
],
|
||||||
"python_file_lines": {
|
"python_file_lines": {
|
||||||
"napalm_linux/linux.py": 1993
|
"napalm_linux/linux.py": 1990
|
||||||
},
|
},
|
||||||
"untyped_public": []
|
"untyped_public": []
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user