1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

snmp_facts: doc update (#1569)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2021-01-01 21:44:44 +05:30 committed by GitHub
parent eacbf45632
commit ba50d114d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,51 +21,51 @@ requirements:
options: options:
host: host:
description: description:
- Set to target snmp server (normally C({{ inventory_hostname }})). - Set to target SNMP server (normally C({{ inventory_hostname }})).
type: str type: str
required: true required: true
version: version:
description: description:
- SNMP Version to use, v2/v2c or v3. - SNMP Version to use, C(v2), C(v2c) or C(v3).
type: str type: str
required: true required: true
choices: [ v2, v2c, v3 ] choices: [ v2, v2c, v3 ]
community: community:
description: description:
- The SNMP community string, required if version is v2/v2c. - The SNMP community string, required if I(version) is C(v2) or C(v2c).
type: str type: str
level: level:
description: description:
- Authentication level. - Authentication level.
- Required if version is v3. - Required if I(version) is C(v3).
type: str type: str
choices: [ authNoPriv, authPriv ] choices: [ authNoPriv, authPriv ]
username: username:
description: description:
- Username for SNMPv3. - Username for SNMPv3.
- Required if version is v3. - Required if I(version) is C(v3).
type: str type: str
integrity: integrity:
description: description:
- Hashing algorithm. - Hashing algorithm.
- Required if version is v3. - Required if I(version) is C(v3).
type: str type: str
choices: [ md5, sha ] choices: [ md5, sha ]
authkey: authkey:
description: description:
- Authentication key. - Authentication key.
- Required if version is v3. - Required I(version) is C(v3).
type: str type: str
privacy: privacy:
description: description:
- Encryption algorithm. - Encryption algorithm.
- Required if level is authPriv. - Required if I(level) is C(authPriv).
type: str type: str
choices: [ aes, des ] choices: [ aes, des ]
privkey: privkey:
description: description:
- Encryption key. - Encryption key.
- Required if version is authPriv. - Required if I(level) is C(authPriv).
type: str type: str
''' '''
@ -174,10 +174,10 @@ PYSNMP_IMP_ERR = None
try: try:
from pysnmp.entity.rfc3413.oneliner import cmdgen from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.proto.rfc1905 import EndOfMibView from pysnmp.proto.rfc1905 import EndOfMibView
has_pysnmp = True HAS_PYSNMP = True
except Exception: except Exception:
PYSNMP_IMP_ERR = traceback.format_exc() PYSNMP_IMP_ERR = traceback.format_exc()
has_pysnmp = False HAS_PYSNMP = False
from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
@ -221,8 +221,7 @@ def decode_hex(hexstring):
return hexstring return hexstring
if hexstring[:2] == "0x": if hexstring[:2] == "0x":
return to_text(binascii.unhexlify(hexstring[2:])) return to_text(binascii.unhexlify(hexstring[2:]))
else: return hexstring
return hexstring
def decode_mac(hexstring): def decode_mac(hexstring):
@ -231,8 +230,7 @@ def decode_mac(hexstring):
return hexstring return hexstring
if hexstring[:2] == "0x": if hexstring[:2] == "0x":
return hexstring[2:] return hexstring[2:]
else: return hexstring
return hexstring
def lookup_adminstatus(int_adminstatus): def lookup_adminstatus(int_adminstatus):
@ -243,8 +241,7 @@ def lookup_adminstatus(int_adminstatus):
} }
if int_adminstatus in adminstatus_options: if int_adminstatus in adminstatus_options:
return adminstatus_options[int_adminstatus] return adminstatus_options[int_adminstatus]
else: return ""
return ""
def lookup_operstatus(int_operstatus): def lookup_operstatus(int_operstatus):
@ -259,8 +256,7 @@ def lookup_operstatus(int_operstatus):
} }
if int_operstatus in operstatus_options: if int_operstatus in operstatus_options:
return operstatus_options[int_operstatus] return operstatus_options[int_operstatus]
else: return ""
return ""
def main(): def main():
@ -285,13 +281,13 @@ def main():
m_args = module.params m_args = module.params
if not has_pysnmp: if not HAS_PYSNMP:
module.fail_json(msg=missing_required_lib('pysnmp'), exception=PYSNMP_IMP_ERR) module.fail_json(msg=missing_required_lib('pysnmp'), exception=PYSNMP_IMP_ERR)
cmdGen = cmdgen.CommandGenerator() cmdGen = cmdgen.CommandGenerator()
# Verify that we receive a community when using snmp v2 # Verify that we receive a community when using snmp v2
if m_args['version'] == "v2" or m_args['version'] == "v2c": if m_args['version'] in ("v2", "v2c"):
if m_args['community'] is None: if m_args['community'] is None:
module.fail_json(msg='Community not set when using snmp version 2') module.fail_json(msg='Community not set when using snmp version 2')
@ -313,7 +309,7 @@ def main():
privacy_proto = cmdgen.usmDESPrivProtocol privacy_proto = cmdgen.usmDESPrivProtocol
# Use SNMP Version 2 # Use SNMP Version 2
if m_args['version'] == "v2" or m_args['version'] == "v2c": if m_args['version'] in ("v2", "v2c"):
snmp_auth = cmdgen.CommunityData(m_args['community']) snmp_auth = cmdgen.CommunityData(m_args['community'])
# Use SNMP Version 3 with authNoPriv # Use SNMP Version 3 with authNoPriv