1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

snmp_facts: improvements (#11148)

* snmp_facts: improvements

* require level if vesion=v3
This commit is contained in:
Alexei Znamensky 2025-11-24 01:17:11 +13:00 committed by GitHub
parent 1c678f5c07
commit 7321ba4990
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 14 deletions

View file

@ -249,9 +249,7 @@ def decode_mac(hexstring):
def lookup_adminstatus(int_adminstatus):
adminstatus_options = {1: "up", 2: "down", 3: "testing"}
if int_adminstatus in adminstatus_options:
return adminstatus_options[int_adminstatus]
return ""
return adminstatus_options.get(int_adminstatus, "")
def lookup_operstatus(int_operstatus):
@ -264,9 +262,7 @@ def lookup_operstatus(int_operstatus):
6: "notPresent",
7: "lowerLayerDown",
}
if int_operstatus in operstatus_options:
return operstatus_options[int_operstatus]
return ""
return operstatus_options.get(int_operstatus, "")
def main():
@ -288,6 +284,11 @@ def main():
["username", "level", "integrity", "authkey"],
["privacy", "privkey"],
),
required_if=[
("version", "v2", ["community"]),
("version", "v2c", ["community"]),
("version", "v3", ["username", "authkey", "level"]),
],
supports_check_mode=True,
)
@ -298,17 +299,9 @@ def main():
cmdGen = cmdgen.CommandGenerator()
transport_opts = {k: m_args[k] for k in ("timeout", "retries") if m_args[k] is not None}
# Verify that we receive a community when using snmp v2
if m_args["version"] in ("v2", "v2c"):
if m_args["community"] is None:
module.fail_json(msg="Community not set when using snmp version 2")
integrity_proto = None
privacy_proto = None
if m_args["version"] == "v3":
if m_args["username"] is None:
module.fail_json(msg="Username not set when using snmp version 3")
if m_args["level"] == "authPriv" and m_args["privacy"] is None:
module.fail_json(msg="Privacy algorithm not set when using authPriv")