Skip to content

Commit

Permalink
Change the type of net_flow to string
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolenz committed Oct 4, 2022
1 parent 14e90de commit dba84dd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1483-vmware_dvs_portgroup.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
breaking_changes:
- vmware_dvs_portgroup - Remove the default for `network_policy` and add a new sub-option `inherited`
(https://github.com/ansible-collections/community.vmware/pull/1483).
- vmware_dvs_portgroup - Change the type of `net_flow` to string to allow setting it implicitly to inherited or to keep the value as-is
(https://github.com/ansible-collections/community.vmware/pull/1483).
54 changes: 39 additions & 15 deletions plugins/modules/vmware_dvs_portgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,15 @@
description:
- Indicate whether or not the virtual machine IP traffic that flows through a vds gets analyzed by sending reports to a NetFlow collector.
required: False
type: bool
type: 'str'
choices:
- true
- on
- yes
- false
- off
- no
- inherited
version_added: '2.3.0'
in_traffic_shaping:
description:
Expand Down Expand Up @@ -392,6 +400,8 @@
PyVmomi,
find_dvs_by_name,
find_dvspg_by_name,
is_boolean,
is_truthy,
vmware_argument_spec,
wait_for_task)

Expand Down Expand Up @@ -529,12 +539,14 @@ def build_config(self):
config.policy.vlanOverrideAllowed = self.module.params['port_policy']['vlan_override']

# NetFlow
config.defaultPortConfig.ipfixEnabled = vim.BoolPolicy()
if self.module.params['net_flow']:
config.defaultPortConfig.ipfixEnabled.inherited = False
config.defaultPortConfig.ipfixEnabled.value = self.module.params['net_flow']
else:
config.defaultPortConfig.ipfixEnabled.inherited = True
net_flow = self.module.params['net_flow']
if net_flow is not None:
config.defaultPortConfig.ipfixEnabled = vim.BoolPolicy()
if is_boolean(net_flow):
config.defaultPortConfig.ipfixEnabled.inherited = False
config.defaultPortConfig.ipfixEnabled.value = is_truthy(net_flow)
else:
config.defaultPortConfig.ipfixEnabled.inherited = True

# Ingress traffic shaping
config.defaultPortConfig.inShapingPolicy = vim.dvs.DistributedVirtualPort.TrafficShapingPolicy()
Expand Down Expand Up @@ -758,13 +770,14 @@ def check_dvspg_state(self):
return 'update'

# NetFlow
if self.module.params['net_flow'] is not None and \
(self.dvs_portgroup.config.defaultPortConfig.ipfixEnabled.inherited is not False
or self.dvs_portgroup.config.defaultPortConfig.ipfixEnabled.value != self.module.params['net_flow']):
return 'update'
elif self.module.params['net_flow'] is None and \
self.dvs_portgroup.config.defaultPortConfig.ipfixEnabled.inherited is not True:
return 'update'
net_flow = self.module.params['net_flow']
if net_flow is not None:
if is_boolean(net_flow) and \
(self.dvs_portgroup.config.defaultPortConfig.ipfixEnabled.inherited is not False
or self.dvs_portgroup.config.defaultPortConfig.ipfixEnabled.value != is_truthy(net_flow)):
return 'update'
elif self.dvs_portgroup.config.defaultPortConfig.ipfixEnabled.inherited is not True:
return 'update'

# Ingress traffic shaping
if self.module.params['in_traffic_shaping'] is not None and \
Expand Down Expand Up @@ -887,7 +900,18 @@ def main():
burst_size=dict(type='int'),
),
),
net_flow=dict(type='bool'),
net_flow=dict(
type='str',
choices=[
'true',
'on',
'yes',
'false',
'off',
'no',
'inherited',
],
),
teaming_policy=dict(
type='dict',
options=dict(
Expand Down

0 comments on commit dba84dd

Please sign in to comment.