diff --git a/changelogs/fragments/1483-vmware_dvs_portgroup.yml b/changelogs/fragments/1483-vmware_dvs_portgroup.yml index f5e1a2ed19..9715e2cded 100644 --- a/changelogs/fragments/1483-vmware_dvs_portgroup.yml +++ b/changelogs/fragments/1483-vmware_dvs_portgroup.yml @@ -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). diff --git a/plugins/modules/vmware_dvs_portgroup.py b/plugins/modules/vmware_dvs_portgroup.py index 7eb1edeba8..2e0617c0e7 100644 --- a/plugins/modules/vmware_dvs_portgroup.py +++ b/plugins/modules/vmware_dvs_portgroup.py @@ -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: @@ -392,6 +400,8 @@ PyVmomi, find_dvs_by_name, find_dvspg_by_name, + is_boolean, + is_truthy, vmware_argument_spec, wait_for_task) @@ -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() @@ -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 \ @@ -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(