Skip to content

Commit

Permalink
Merge branch 'infobloxopen:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnagornyi authored Nov 20, 2024
2 parents be7610b + e85fcf4 commit a2cec1f
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 14 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Infoblox.Nios_Modules Release Notes

.. contents:: Topics

v1.7.1
======

Release Summary
---------------
This update focuses on specific improvements and bug fixes for Host records to enhance system functionality and performance.

Bugfixes
--------
- Refined Host record return fields to ensure use_nextserver and nextserver are only included for IPv4, as these fields are not applicable to IPv6. `#274 <https://github.com/infobloxopen/infoblox-ansible/pull/274>`_
- For Host IPv6, the mac parameter has been renamed to duid. `#274 <https://github.com/infobloxopen/infoblox-ansible/pull/274>`_


v1.7.0
======

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The `infoblox.nios_modules` collection has the following content:
- `nios_restartservices` - Controlled restart of Infoblox NIOS services
- `nios_srv_record` – Configure Infoblox NIOS SRV records
- `nios_txt_record` – Configure Infoblox NIOS txt records
- `nios_vlan` – Configure Infoblox NIOS vlan
- `nios_zone` – Configure Infoblox NIOS DNS zones

#### Plugins
Expand Down
2 changes: 1 addition & 1 deletion changelogs/.plugin-cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ plugins:
shell: {}
strategy: {}
vars: {}
version: 1.7.0
version: 1.7.1
7 changes: 7 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,10 @@ releases:
name: nios_nsgroup_stubmember
namespace: ""
release_date: "2024-10-04"
1.7.1:
changes:
bugfixes:
- Refined Host record return fields to ensure use_nextserver and nextserver are only included for IPv4, as these fields are not applicable to IPv6.
- For Host IPv6, the mac parameter has been renamed to duid.
release_summary: "This update focuses on specific improvements and bug fixes for Host records to enhance system functionality and performance."
release_date: "2024-11-18"
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace: infoblox
name: nios_modules

# The version of the collection. Must be compatible with semantic versioning
version: 1.7.0
version: 1.7.1

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
8 changes: 5 additions & 3 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
NIOS_DTC_MONITOR_TCP = 'dtc:monitor:tcp'
NIOS_DTC_TOPOLOGY = 'dtc:topology'
NIOS_EXTENSIBLE_ATTRIBUTE = 'extensibleattributedef'
NIOS_VLAN = 'vlan'

NIOS_PROVIDER_SPEC = {
'host': dict(fallback=(env_fallback, ['INFOBLOX_HOST'])),
Expand Down Expand Up @@ -530,7 +531,7 @@ def run(self, ib_obj_type, ib_spec):
# Handle use_for_ea_inheritance flag changes for IPv4addr in a host record
# Fetch the updated reference of host to avoid drift.
host_ref = self.connector.get_object(obj_type=str(res), return_fields=['ipv4addrs'])
if host_ref:
if host_ref and 'ipv4addrs' in host_ref:
# Create a dictionary for quick lookups
ref_dict = {obj['ipv4addr']: obj['_ref'] for obj in host_ref['ipv4addrs']}
sorted_ipv4addrs = sorted(proposed_object['ipv4addrs'], key=lambda x: x.get('use_for_ea_inheritance', False))
Expand Down Expand Up @@ -655,6 +656,8 @@ def issubset(self, item, objects):
# Normalize MAC address for comparison
if 'mac' in item:
item['mac'] = item['mac'].replace('-', ':').lower()
elif 'duid' in item:
item['duid'] = item['duid'].replace('-', ':').lower()
if all(entry in obj.items() for entry in item.items()):
return True
else:
Expand Down Expand Up @@ -864,8 +867,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
'ipv4addrs.nextserver', 'ipv4addrs.use_nextserver', 'ipv4addrs.use_for_ea_inheritance'
]
ipv6addrs_return = [
'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host',
'ipv6addrs.use_nextserver', 'ipv6addrs.nextserver'
'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host'
]
return_fields.extend(ipv4addrs_return)
return_fields.extend(ipv6addrs_return)
Expand Down
32 changes: 25 additions & 7 deletions plugins/modules/nios_host_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,19 @@
configure_for_dhcp:
description:
- Configure the host_record over DHCP instead of DNS, if user
changes it to true, user need to mention MAC address to configure.
changes it to true, user need to mention DUID address to configure.
type: bool
required: false
mac:
aliases:
- dhcp
duid:
description:
- Configures the hardware MAC address for the host record. If user makes
DHCP to true, user need to mention MAC address.
- Configures the hardware DUID address for the host record. If user makes
DHCP to true, user need to mention DUID address.
type: str
required: false
aliases:
- mac
- duid
aliases:
description:
- Configures an optional list of additional aliases to add to the host
Expand Down Expand Up @@ -362,6 +364,22 @@
username: admin
password: admin
connection: local
- name: Create host record with IPv4 and IPv6 addresses
infoblox.nios_modules.nios_host_record:
name: hostrec.ansible.com
ipv4:
- address: 192.168.10.7
mac: 12:80:C8:E3:4C:AB
ipv6:
- address: fe80::10
duid: 12:80:C8:E3:4C:B4
state: present
provider:
host: "{{ inventory_hostname_short }}"
username: admin
password: admin
connection: local
'''

RETURN = ''' # '''
Expand Down Expand Up @@ -415,8 +433,8 @@ def main():

ipv6addr_spec = dict(
ipv6addr=dict(required=True, aliases=['address']),
configure_for_dhcp=dict(type='bool', required=False),
mac=dict(required=False)
configure_for_dhcp=dict(type='bool', required=False, aliases=['dhcp']),
duid=dict(required=False)
)

ib_spec = dict(
Expand Down
73 changes: 71 additions & 2 deletions plugins/modules/nios_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@
- If set on creation, the network is created according to the values
specified in the selected template.
type: str
vlans:
description:
- Configures the set of vlans to be included as part of
the configured network instance. This argument accepts a list
of values (see suboptions). When configuring suboptions at
least one of C(name) or C(id) must be specified.
type: list
elements: dict
suboptions:
name:
description:
- The name of the vlan.
type: str
id:
description:
- The id of the vlan.
type: int
parent:
description:
- The name of the parent vlanview or vlanrange.
type: str
extattrs:
description:
- Allows for the configuration of Extensible Attributes on the
Expand Down Expand Up @@ -269,6 +290,21 @@
username: admin
password: admin
connection: local
- name: Configure a network ipv4 and assign vlans
infoblox.nios_modules.nios_network:
network: 192.168.10.0/24
comment: this is a test comment
vlans:
- name: ansiblevlan
parent: ansiblevlanview
- id: 10
state: present
provider:
host: "{{ inventory_hostname_short }}"
username: admin
password: admin
connection: local
'''

RETURN = ''' # '''
Expand Down Expand Up @@ -345,6 +381,34 @@ def check_vendor_specific_dhcp_option(module, ib_spec):
def main():
''' Main entry point for module execution
'''
def vlans(module):
vlans_list = list()
if module.params['vlans']:
for vlan in module.params['vlans']:

vlan_filtered = dict((k, v) for k, v in iteritems(vlan) if v is not None)
if 'name' not in vlan_filtered and 'id' not in vlan_filtered:
module.fail_json(msg='one of `name` or `id` is required for vlans value')

if 'parent' in vlan_filtered:
obj_vlanview = wapi.get_object('vlanview', {'name': vlan_filtered['parent']})
obj_vlanrange = wapi.get_object('vlanrange', {'name': vlan_filtered['parent']})
if obj_vlanview and not obj_vlanrange:
vlan_filtered['parent'] = obj_vlanview[0]['_ref']
elif not obj_vlanview and obj_vlanrange:
vlan_filtered['parent'] = obj_vlanrange[0]['_ref']
else:
module.fail_json(msg='VLAN View/Range \'%s\' cannot be found.' % vlan_filtered['parent'])

obj_vlan = wapi.get_object('vlan', vlan_filtered)

if obj_vlan:
vlans_list.append({'vlan': obj_vlan[0]['_ref']})
else:
module.fail_json(msg='VLAN `%s` cannot be found.' % vlan['name'])

return vlans_list

option_spec = dict(
# one of name or num is required; enforced by the function options()
name=dict(),
Expand All @@ -356,12 +420,17 @@ def main():
vendor_class=dict(default='DHCP')
)

vlans_spec = dict(
id=dict(type='int'),
name=dict(),
parent=dict(default='default')
)

ib_spec = dict(
network=dict(required=True, aliases=['name', 'cidr'], ib_req=True),
network_view=dict(default='default', ib_req=True),

options=dict(type='list', elements='dict', options=option_spec, transform=options, default=[]),

vlans=dict(type='list', elements='dict', options=vlans_spec, transform=vlans),
template=dict(type='str'),
extattrs=dict(type='dict'),
comment=dict(),
Expand Down
Loading

0 comments on commit a2cec1f

Please sign in to comment.