Skip to content

Commit

Permalink
Merge branch 'master' into ansible_lint_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JchhatbarInfoblox authored Jul 9, 2024
2 parents 0bc1b8e + 3f5025e commit e5d39f3
Show file tree
Hide file tree
Showing 30 changed files with 494 additions and 127 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
strategy:
fail-fast: false
matrix:
ansible-version: [stable-2.14]
ansible-version: [stable-2.15]
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Python 3.10
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: "3.10"
python-version: '3.11'

- name: Install ansible (${{ matrix.ansible-version }})
run: pip install pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check
Expand All @@ -48,25 +48,25 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel]
python-version: ['3.9', '3.10', '3.11', '3.12']
ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel]
exclude:
- ansible-version: devel
python-version: "3.8"
python-version: '3.11'
- ansible-version: devel
python-version: "3.9"
- ansible-version: stable-2.16
python-version: "3.8"
python-version: '3.10'
- ansible-version: devel
python-version: '3.9'
- ansible-version: stable-2.17
python-version: '3.9'
- ansible-version: stable-2.16
python-version: "3.9"
- ansible-version: stable-2.15
python-version: "3.8"
- ansible-version: stable-2.14
python-version: "3.8"
python-version: '3.12'

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -95,8 +95,8 @@ jobs:

- name: Generate coverage report
run: |
if [ "${{ matrix.ansible-version }}" == "stable-2.14" ]; then
pip install coverage==6.5.0;
if [ "${{ matrix.ansible-version }}" == "devel" ]; then
pip install coverage==7.5.3;
elif [ "${{ matrix.ansible-version }}" == "stable-2.15" ]; then
pip install coverage==6.5.0;
fi
Expand All @@ -115,24 +115,24 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel]
python-version: ['3.9', '3.10', '3.11', '3.12']
ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel]
exclude:
- ansible-version: devel
python-version: "3.8"
python-version: '3.11'
- ansible-version: devel
python-version: "3.9"
- ansible-version: stable-2.16
python-version: "3.8"
python-version: '3.10'
- ansible-version: devel
python-version: '3.9'
- ansible-version: stable-2.17
python-version: '3.9'
- ansible-version: stable-2.16
python-version: "3.9"
- ansible-version: stable-2.15
python-version: "3.8"
- ansible-version: stable-2.14
python-version: "3.8"
python-version: '3.12'
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -186,14 +186,14 @@ jobs:
strategy:
fail-fast: false
matrix:
ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel]
ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel]
steps:
- name: Set up Python 3.10
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
# it is just required to run that once as "ansible-test sanity" in the docker image
# will run on all python versions it supports.
python-version: "3.10"
python-version: 3.11

- name: Install ansible (${{ matrix.ansible-version }}) version
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check
Expand Down
40 changes: 21 additions & 19 deletions plugins/lookup/nios_next_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
required: True
type: str
use_range:
description: Use DHCP range to retrieve the next available IP address(es).
description: Use DHCP range to retrieve the next available IP address(es). Requested number of IP Addresses must be between 1 and 20.
required: false
default: no
type: bool
Expand Down Expand Up @@ -63,8 +63,8 @@
- 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,
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3, \
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
- name: return the next 3 available IP addresses for network 192.168.10.0/24
excluding ip addresses - ['192.168.10.1', '192.168.10.2']
Expand All @@ -88,7 +88,6 @@
"""

from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_text
from ansible.errors import AnsibleError
from ..module_utils.api import WapiLookup
import ipaddress
Expand All @@ -105,12 +104,12 @@ def run(self, terms, variables=None, **kwargs):
provider = kwargs.pop('provider', {})
wapi = WapiLookup(provider)

if kwargs.get('use_range', False):
network_obj = wapi.get_object('range', {'network': network})
elif isinstance(ipaddress.ip_network(network), ipaddress.IPv6Network):
network_obj = wapi.get_object('ipv6network', {'network': network})
if isinstance(ipaddress.ip_network(network), ipaddress.IPv6Network):
object_type = 'ipv6range' if kwargs.get('use_range', False) else 'ipv6network'
else:
network_obj = wapi.get_object('network', {'network': network})
object_type = 'range' if kwargs.get('use_range', False) else 'network'

network_obj = wapi.get_object(object_type, {'network': network})

if network_obj is None:
raise AnsibleError('unable to find network object %s' % network)
Expand All @@ -119,13 +118,16 @@ def run(self, terms, variables=None, **kwargs):
exclude_ip = kwargs.get('exclude', [])
network_view = kwargs.get('network_view', 'default')

try:
ref_list = [network['_ref'] for network in network_obj if network['network_view'] == network_view]
if not ref_list:
raise AnsibleError('no records found')
else:
ref = ref_list[0]
avail_ips = wapi.call_func('next_available_ip', ref, {'num': num, 'exclude': exclude_ip})
return [avail_ips['ips']]
except Exception as exc:
raise AnsibleError(to_text(exc))
ref_list = [network['_ref'] for network in network_obj if network['network_view'] == network_view]
if not ref_list:
raise AnsibleError('no records found')

for ref in ref_list:
try:
avail_ips = wapi.call_func('next_available_ip', ref, {'num': num, 'exclude': exclude_ip})
if len(avail_ips['ips']) >= num:
return [avail_ips['ips']]
except Exception:
continue

raise AnsibleError('unable to find the required number of IPs')
12 changes: 12 additions & 0 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
NIOS_DTC_MONITOR_SNMP = 'dtc:monitor:snmp'
NIOS_DTC_MONITOR_TCP = 'dtc:monitor:tcp'
NIOS_DTC_TOPOLOGY = 'dtc:topology'
NIOS_EXTENSIBLE_ATTRIBUTE = 'extensibleattributedef'

NIOS_PROVIDER_SPEC = {
'host': dict(fallback=(env_fallback, ['INFOBLOX_HOST'])),
Expand Down Expand Up @@ -214,6 +215,14 @@ def convert_members_to_struct(member_spec):
return member_spec


def convert_ea_list_to_struct(member_spec):
''' Transforms the list of the values into a valid WAPI struct.
'''
if 'list_values' in member_spec.keys():
member_spec['list_values'] = [{'_struct': 'extensibleattributedef:listvalues', 'value': v} for v in member_spec['list_values']]
return member_spec


def normalize_ib_spec(ib_spec):
result = {}
for arg in ib_spec:
Expand Down Expand Up @@ -381,6 +390,9 @@ def run(self, ib_obj_type, ib_spec):
proposed_object['end_addr'] = proposed_object.get('new_end_addr')
del proposed_object['new_end_addr']

if (ib_obj_type == NIOS_EXTENSIBLE_ATTRIBUTE):
proposed_object = convert_ea_list_to_struct(proposed_object)

# checks if the 'text' field has to be updated for the TXT Record
if (ib_obj_type == NIOS_TXT_RECORD):
text_obj = proposed_object["text"]
Expand Down
Loading

0 comments on commit e5d39f3

Please sign in to comment.