Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #2065/c147d2fb backport][stable-2] snmp_facts - added timeout and retries params to module #2073

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/2065-snmp-facts-timeout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- snmp_facts - added parameters ``timeout`` and ``retries`` to module (https://github.com/ansible-collections/community.general/issues/980).
17 changes: 15 additions & 2 deletions plugins/modules/net_tools/snmp_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
- Encryption key.
- Required if I(level) is C(authPriv).
type: str
timeout:
description:
- Response timeout in seconds.
type: int
version_added: 2.3.0
retries:
description:
- Maximum number of request retries, 0 retries means just a single request.
type: int
version_added: 2.3.0
'''

EXAMPLES = r'''
Expand Down Expand Up @@ -271,6 +281,8 @@ def main():
privacy=dict(type='str', choices=['aes', 'des']),
authkey=dict(type='str', no_log=True),
privkey=dict(type='str', no_log=True),
timeout=dict(type='int'),
retries=dict(type='int'),
),
required_together=(
['username', 'level', 'integrity', 'authkey'],
Expand All @@ -285,6 +297,7 @@ def main():
module.fail_json(msg=missing_required_lib('pysnmp'), exception=PYSNMP_IMP_ERR)

cmdGen = cmdgen.CommandGenerator()
transport_opts = dict((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"):
Expand Down Expand Up @@ -333,7 +346,7 @@ def Tree():

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), **transport_opts),
cmdgen.MibVariable(p.sysDescr,),
cmdgen.MibVariable(p.sysObjectId,),
cmdgen.MibVariable(p.sysUpTime,),
Expand Down Expand Up @@ -364,7 +377,7 @@ def Tree():

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), **transport_opts),
cmdgen.MibVariable(p.ifIndex,),
cmdgen.MibVariable(p.ifDescr,),
cmdgen.MibVariable(p.ifMtu,),
Expand Down