mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* add multiple VLAN ranges support * fix pip8
This commit is contained in:
parent
8765d2a8e8
commit
6a25e10271
1 changed files with 10 additions and 4 deletions
|
@ -42,7 +42,7 @@ options:
|
|||
vlan_id:
|
||||
description:
|
||||
- The VLAN ID that should be configured with the portgroup, use 0 for no VLAN.
|
||||
- 'If C(vlan_trunk) is configured to be I(true), this can be a range, example: 1-4094.'
|
||||
- 'If C(vlan_trunk) is configured to be I(true), this can be a combination of multiple ranges and numbers, example: 1-200, 205, 400-4094.'
|
||||
required: True
|
||||
num_ports:
|
||||
description:
|
||||
|
@ -159,7 +159,7 @@ EXAMPLES = '''
|
|||
password: '{{ vcenter_password }}'
|
||||
portgroup_name: vlan-trunk-portrgoup
|
||||
switch_name: dvSwitch
|
||||
vlan_id: 1-1000
|
||||
vlan_id: 1-1000, 1005, 1100-1200
|
||||
vlan_trunk: True
|
||||
num_ports: 120
|
||||
portgroup_type: earlyBinding
|
||||
|
@ -257,8 +257,14 @@ class VMwareDvsPortgroup(PyVmomi):
|
|||
config.defaultPortConfig = vim.dvs.VmwareDistributedVirtualSwitch.VmwarePortConfigPolicy()
|
||||
if self.module.params['vlan_trunk']:
|
||||
config.defaultPortConfig.vlan = vim.dvs.VmwareDistributedVirtualSwitch.TrunkVlanSpec()
|
||||
vlan_id_start, vlan_id_end = self.module.params['vlan_id'].split('-')
|
||||
config.defaultPortConfig.vlan.vlanId = [vim.NumericRange(start=int(vlan_id_start.strip()), end=int(vlan_id_end.strip()))]
|
||||
vlan_id_list = []
|
||||
for vlan_id_splitted in self.module.params['vlan_id'].split(','):
|
||||
try:
|
||||
vlan_id_start, vlan_id_end = vlan_id_splitted.split('-')
|
||||
vlan_id_list.append(vim.NumericRange(start=int(vlan_id_start.strip()), end=int(vlan_id_end.strip())))
|
||||
except ValueError:
|
||||
vlan_id_list.append(vim.NumericRange(start=int(vlan_id_splitted.strip()), end=int(vlan_id_splitted.strip())))
|
||||
config.defaultPortConfig.vlan.vlanId = vlan_id_list
|
||||
else:
|
||||
config.defaultPortConfig.vlan = vim.dvs.VmwareDistributedVirtualSwitch.VlanIdSpec()
|
||||
config.defaultPortConfig.vlan.vlanId = int(self.module.params['vlan_id'])
|
||||
|
|
Loading…
Reference in a new issue