diff options
author | Peter Sprygada <privateip@users.noreply.github.com> | 2018-01-27 14:03:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-27 14:03:06 +0100 |
commit | c2d3b9cbd5ebb22345a253fe27b52b44d4c3a38b (patch) | |
tree | 0ef49686f25ccc9045f341f8a70ef73667ab1fe8 /contrib/inventory | |
parent | Integration tests for influxdb_user module (#35315) (diff) | |
download | ansible-c2d3b9cbd5ebb22345a253fe27b52b44d4c3a38b.tar.xz ansible-c2d3b9cbd5ebb22345a253fe27b52b44d4c3a38b.zip |
refactors nios api shared code to handle provider better (#35393)
* refactors nios api shared code to handle provider better
This change refactors the shared code to be easily shared between
modules, plugins and dynamic inventory scripts. All parts now implement
the provider arguments uniformly.
This also provides a centralized fix to suppress urllib3 warnings coming
from the requests library implemented by infoblox_client
* fix up pep8 errors
* fix missing var name
Diffstat (limited to 'contrib/inventory')
-rwxr-xr-x | contrib/inventory/infoblox.py | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/contrib/inventory/infoblox.py b/contrib/inventory/infoblox.py index 374a7564d4..736333faf1 100755 --- a/contrib/inventory/infoblox.py +++ b/contrib/inventory/infoblox.py @@ -25,18 +25,9 @@ import argparse from ansible.parsing.dataloader import DataLoader from ansible.module_utils.six import iteritems from ansible.module_utils._text import to_text -from ansible.module_utils.net_tools.nios.api import get_connector +from ansible.module_utils.net_tools.nios.api import WapiInventory from ansible.module_utils.net_tools.nios.api import normalize_extattrs, flatten_extattrs -try: - # disable urllib3 warnings so as to not interfere with printing to stdout - # which is read by ansible - import urllib3 - urllib3.disable_warnings() -except ImportError: - sys.stdout.write('missing required library: urllib3\n') - sys.exit(-1) - CONFIG_FILES = [ '/etc/ansible/infoblox.yaml', @@ -70,7 +61,7 @@ def main(): loader = DataLoader() config = loader.load_from_file(config_file) provider = config.get('provider') or {} - connector = get_connector(**provider) + wapi = WapiInventory(provider) except Exception as exc: sys.stdout.write(to_text(exc)) sys.exit(-1) @@ -99,10 +90,10 @@ def main(): return_fields = ['name', 'view', 'extattrs', 'ipv4addrs'] - hosts = connector.get_object('record:host', - host_filter, - extattrs=extattrs, - return_fields=return_fields) + hosts = wapi.get_object('record:host', + host_filter, + extattrs=extattrs, + return_fields=return_fields) if hosts: for item in hosts: |