Infoblox ipv6 support feature (#39668)

* Update nios.py

* Update nios.py

* Update nios.py

* nios lookup errors out when there are no results #37970  Open	

Indentation failure issue resolved

* Returning empty list instead of None

In case of no results, res will be returned as an empty list instead of None (implementing ganeshrn comment)

* infoblox ipv6 support changes

* infoblox ipv6 support changes

* for fixing pep8 errors

* moving ipaddr check to utils

* adding ipv6addr check

* increasing space to resolve pep8 error

* modified the playbook examples to valid ones

* Update nios_network.py
pull/40128/merge
Sumit Jaiswal 6 years ago committed by GitHub
parent 291c89382c
commit 9c0825a4cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -359,6 +359,14 @@ def validate_ip_address(address):
return address.count('.') == 3
def validate_ip_v6_address(address):
try:
socket.inet_pton(socket.AF_INET6, address)
except socket.error:
return False
return True
def validate_prefix(prefix):
if prefix and not 0 <= int(prefix) <= 32:
return False

@ -20,6 +20,7 @@ description:
- Adds and/or removes instances of network objects from
Infoblox NIOS servers. This module manages NIOS C(network) objects
using the Infoblox WAPI interface over REST.
- Supports both IPV4 and IPV6 internet protocols
requirements:
- infoblox_client
extends_documentation_fragment: nios
@ -87,7 +88,7 @@ options:
'''
EXAMPLES = '''
- name: configure a network
- name: configure a network ipv4
nios_network:
network: 192.168.10.0/24
comment: this is a test comment
@ -98,7 +99,18 @@ EXAMPLES = '''
password: admin
connection: local
- name: set dhcp options for a network
- name: configure a network ipv6
nios_network:
network: fe80::/64
comment: this is a test comment
state: present
provider:
host: "{{ inventory_hostname_short }}"
username: admin
password: admin
connection: local
- name: set dhcp options for a network ipv4
nios_network:
network: 192.168.10.0/24
comment: this is a test comment
@ -112,7 +124,7 @@ EXAMPLES = '''
password: admin
connection: local
- name: remove a network
- name: remove a network ipv4
nios_network:
network: 192.168.10.0/24
state: absent
@ -128,6 +140,7 @@ RETURN = ''' # '''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems
from ansible.module_utils.net_tools.nios.api import WapiModule
from ansible.module_utils.network.common.utils import validate_ip_address, validate_ip_v6_address
def options(module):
@ -159,6 +172,17 @@ def options(module):
return options
def check_ip_addr_type(ip):
'''This function will check if the argument ip is type v4/v6 and return appropriate infoblox network type
'''
check_ip = ip.split('/')
if validate_ip_address(check_ip[0]):
return 'network'
elif validate_ip_v6_address(check_ip[0]):
return 'ipv6network'
def main():
''' Main entry point for module execution
'''
@ -194,8 +218,12 @@ def main():
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
# to get the argument ipaddr
obj_filter = dict([(k, module.params[k]) for k, v in iteritems(ib_spec) if v.get('ib_req')])
network_type = check_ip_addr_type(obj_filter['network'])
wapi = WapiModule(module)
result = wapi.run('network', ib_spec)
result = wapi.run(network_type, ib_spec)
module.exit_json(**result)

Loading…
Cancel
Save