Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce selecting ref from network_obj based on network view #157

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion plugins/lookup/nios_next_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@
required: false
type: list
elements: str
network_view:
description: The network view to retrieve the CIDR network from.
required: false
default: default
type: str
'''

EXAMPLES = """
- name: return next available IP address for network 192.168.10.0/24
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"

- name: return next available IP address for network 192.168.10.0/24 in a non-default network view
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', network_view='ansible', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"

- name: return the next 3 available IP addresses for network 192.168.10.0/24
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3,
Expand Down Expand Up @@ -91,9 +100,10 @@ def run(self, terms, variables=None, **kwargs):

num = kwargs.get('num', 1)
exclude_ip = kwargs.get('exclude', [])
network_view = kwargs.get('network_view', 'default')

try:
ref = network_obj[0]['_ref']
ref = [network['_ref'] for network in network_obj if network['network_view'] == network_view][0]
avail_ips = wapi.call_func('next_available_ip', ref, {'num': num, 'exclude': exclude_ip})
return [avail_ips['ips']]
except Exception as exc:
Expand Down
13 changes: 12 additions & 1 deletion plugins/lookup/nios_next_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
default: ''
type: list
elements: str
network_view:
description: The network view to retrieve the CIDR network from.
required: false
default: default
type: str
'''

EXAMPLES = """
Expand All @@ -49,6 +54,11 @@
networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '192.168.10.0/24', cidr=25,
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"

- name: return next available network for network-container 192.168.10.0/24 in a non-default network view
ansible.builtin.set_fact:
networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '192.168.10.0/24', cidr=25, network_view='ansible'
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"

- name: return the next 2 available network addresses for network-container 192.168.10.0/24
ansible.builtin.set_fact:
networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '192.168.10.0/24', cidr=25, num=2,
Expand Down Expand Up @@ -94,9 +104,10 @@ def run(self, terms, variables=None, **kwargs):
raise AnsibleError('unable to find network-container object %s' % network)
num = kwargs.get('num', 1)
exclude_ip = kwargs.get('exclude', [])
network_view = kwargs.get('network_view', 'default')

try:
ref = network_obj[0]['_ref']
ref = [network['_ref'] for network in network_obj if network['network_view'] == network_view][0]
avail_nets = wapi.call_func('next_available_network', ref, {'cidr': cidr, 'num': num, 'exclude': exclude_ip})
return [avail_nets['networks']]
except Exception as exc:
Expand Down