mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-22 12:03:58 -07:00
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
This commit is contained in:
parent
1f1402ea68
commit
c2d3b9cbd5
10 changed files with 90 additions and 70 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue