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

Added support for assigning vlans in module nios_network.py #171

Merged
merged 3 commits into from
Nov 18, 2024
Merged
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
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