mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-04 07:19:10 -07:00
add dependency manager (#5535)
* add dependency manager * add plugins/module_utils/deps.py to BOTMETA * ditch usng OrderedDict to keep compatibility with Python 2.6 * Update plugins/module_utils/deps.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
5e5af458fb
commit
0624951e17
7 changed files with 117 additions and 69 deletions
|
@ -183,20 +183,14 @@ ansible_interfaces:
|
|||
'''
|
||||
|
||||
import binascii
|
||||
import traceback
|
||||
from collections import defaultdict
|
||||
from ansible_collections.community.general.plugins.module_utils import deps
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
|
||||
PYSNMP_IMP_ERR = None
|
||||
try:
|
||||
with deps.declare("pysnmp"):
|
||||
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||
from pysnmp.proto.rfc1905 import EndOfMibView
|
||||
HAS_PYSNMP = True
|
||||
except Exception:
|
||||
PYSNMP_IMP_ERR = traceback.format_exc()
|
||||
HAS_PYSNMP = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
|
||||
|
||||
class DefineOid(object):
|
||||
|
@ -299,8 +293,7 @@ def main():
|
|||
|
||||
m_args = module.params
|
||||
|
||||
if not HAS_PYSNMP:
|
||||
module.fail_json(msg=missing_required_lib('pysnmp'), exception=PYSNMP_IMP_ERR)
|
||||
deps.validate(module)
|
||||
|
||||
cmdGen = cmdgen.CommandGenerator()
|
||||
transport_opts = dict((k, m_args[k]) for k in ('timeout', 'retries') if m_args[k] is not None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue