Skip to content

Commit

Permalink
Ea definition support (#235)
Browse files Browse the repository at this point in the history
* Attributes (#4)

* Add extensible attribute module

* added choices to IB_spec

* doco

* Add the struct creation to api

* doco

* pep and lint

* fix pep issues

* Add flags for extensible attributes (#5) (#6)

* Extensible attributes module - support flags

infobloxopen/infoblox-ansible/#186 add support for flags to
the extensible attributes module

* Extensible attributes - fix linting

reported by the ansible sanity tests

---------

Co-authored-by: Hugues Malphettes <[email protected]>

* Documentation update

fix doco

line length

fix line length

PEP issue

pep issue

* [FIX] CI execution for unit test

* [FIX] Github workflows for CI Run

Updated workflow file to support ansible-stable 2.17 and removed 2.14

[FIX] coverage report for stable-2.16

[FIX] changed called_once_with to assert_called_once_with for unit tests

[FIX] compact file deprication for ansible-2.17

* [FIX] Updated unit test case by replacing called_once_with to assert_called_once_with for python3.12

* Updated data type for Min and Max from str to int

---------

Co-authored-by: matthewdennett <[email protected]>
Co-authored-by: matt <[email protected]>
Co-authored-by: Hugues Malphettes <[email protected]>
  • Loading branch information
4 people authored Jul 9, 2024
1 parent 8b4f2d0 commit 85df85e
Show file tree
Hide file tree
Showing 29 changed files with 424 additions and 106 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,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.10'
- ansible-version: devel
python-version: '3.9'
- ansible-version: stable-2.16
python-version: '3.8'
- 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 All @@ -83,7 +83,7 @@ jobs:
run: |
ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz
git clone https://github.com/ansible/ansible.git -b ${{ matrix.ansible-version }}
if [ "${{ matrix.ansible-version }}" != "devel" ]; then cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/; fi
if [ "${{ matrix.ansible-version }}" != "devel" ] && [ "${{ matrix.ansible-version }}" != "stable-2.17" ]; then cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/; fi
cp -rf ansible/test/units/modules/utils.py /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/
sed -i 's/units/ansible_collections.infoblox.nios_modules.tests.unit/' /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py
if [ -f /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt ]; then pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt; fi
Expand All @@ -93,8 +93,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 @@ -114,24 +114,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.10'
- ansible-version: devel
python-version: '3.9'
- ansible-version: stable-2.16
python-version: '3.8'
- 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,15 +186,15 @@ 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
15 changes: 9 additions & 6 deletions plugins/lookup/nios_next_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,23 @@
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'}) }}"
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 from DHCP range
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', use_range=true, provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', use_range=true,
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', \
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,
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']
ansible.builtin.set_fact:
Expand All @@ -71,7 +73,8 @@
- name: return next available IP address for network fd30:f52:2:12::/64
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', 'fd30:f52:2:12::/64', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', 'fd30:f52:2:12::/64',
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
"""

RETURN = """
Expand Down
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 85df85e

Please sign in to comment.