Skip to content

Commit

Permalink
[FIX] Sanity issue on nios_next_network
Browse files Browse the repository at this point in the history
  • Loading branch information
JkhatriInfobox committed Sep 11, 2024
1 parent 5ff9d18 commit 646b926
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions plugins/lookup/nios_next_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '192.168.10.0/24', cidr=25, exclude=['192.168.10.0/25'],
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
- name: return the available ipv6 network addresses for network-container 2001:1:111:1::0/64
set_fact:
networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '2001:1:111:1::0/64', cidr=126,
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
- name: return the available ipv6 network addresses for network-container 2001:1:111:1::0/64
set_fact:
networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '2001:1:111:1::0/64', cidr=126,
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
"""

RETURN = """
Expand All @@ -90,6 +90,7 @@
from ..module_utils.api import NIOS_IPV4_NETWORK_CONTAINER, NIOS_IPV6_NETWORK_CONTAINER
import ipaddress


class LookupModule(LookupBase):

def run(self, terms, variables=None, **kwargs):
Expand All @@ -106,7 +107,7 @@ def run(self, terms, variables=None, **kwargs):
raise AnsibleError('missing CIDR argument in the form of xx')

if network.prefixlen >= cidr:
raise AnsibleError('cidr %s must be greater than parent network cidr %s' % (cidr,network.prefixlen))
raise AnsibleError('cidr %s must be greater than parent network cidr %s' % (cidr, network.prefixlen))

container_type = None
network_objects = None
Expand All @@ -125,14 +126,14 @@ def run(self, terms, variables=None, **kwargs):

# check for valid subnetting cidr
if network.prefixlen >= cidr:
raise AnsibleError('cidr %s must be greater than parent network cidr %s' % (cidr,network.prefixlen))
raise AnsibleError('cidr %s must be greater than parent network cidr %s' % (cidr, network.prefixlen))

provider = kwargs.pop('provider', {})
wapi = WapiLookup(provider)

if container_type is None:
raise AnsibleError('unable to identify network-container type')

network_objects = wapi.get_object(container_type, {'network': network.with_prefixlen})

if network_objects is None:
Expand Down

0 comments on commit 646b926

Please sign in to comment.