11# # some supporting functions used internally in the module
22
3- function _Set -VNVDTrafficRuleset_helper {
3+ function Set -VNVDTrafficRuleset_helper {
44<# . Description
55 Set the Rules property of the given Traffic Ruleset of a vDPortgroup traffic filter policy: either add a rule, remove a rule, or overwrite the Rules altogether with the new rule(s) provided
66
77 . Example
8- _Set -VNVDTrafficRuleset_helper -TrafficRuleSet $oSomeTrafficRuleset -TrafficRule $oRule0, $oRule1 -RuleOperation Add -Enabled
8+ Set -VNVDTrafficRuleset_helper -TrafficRuleSet $oSomeTrafficRuleset -TrafficRule $oRule0, $oRule1 -RuleOperation Add -Enabled
99 Add the two rules to the given TrafficRuleSet rules, and Enable the TrafficRuleSet
1010
1111 . Example
12- _Set -VNVDTrafficRuleset_helper -TrafficRuleSet $oSomeTrafficRuleset -TrafficRule $oSomeOldRule -RuleOperation Remove -Enabled:$false
12+ Set -VNVDTrafficRuleset_helper -TrafficRuleSet $oSomeTrafficRuleset -TrafficRule $oSomeOldRule -RuleOperation Remove -Enabled:$false
1313 Remove this rule from the given TrafficRuleSet rules array, and Disable the TrafficRuleSet
1414
1515 . Example
16- _Set -VNVDTrafficRuleset_helper -TrafficRuleSet $oSomeTrafficRuleset -TrafficRule $oReplacementRule0, $oReplacementRule1 -RuleOperation Overwrite
16+ Set -VNVDTrafficRuleset_helper -TrafficRuleSet $oSomeTrafficRuleset -TrafficRule $oReplacementRule0, $oReplacementRule1 -RuleOperation Overwrite
1717 Set the rules array for the given TrafficRuleSet to have just these two rules
1818
1919 . Outputs
2020 VNVDTrafficRuleSet
2121#>
22- [CmdletBinding (DefaultParameterSetName = " Default" )]
22+ [CmdletBinding (DefaultParameterSetName = " Default" , SupportsShouldProcess = $true )]
2323 [OutputType ([VNVDTrafficRuleSet ])]
2424 param (
2525 # # Given vDPortgroup's TrafficRuleset upon which to act
@@ -39,56 +39,59 @@ function _Set-VNVDTrafficRuleset_helper {
3939 $TrafficRuleSet | Foreach-Object {
4040 $oThisVNVDTrafficRuleset = $_
4141 $oVDPortgroupView_ThisTrafficRuleset = $oThisVNVDTrafficRuleset.VDPortgroupView
42- # # update View data, to make sure we have the current info
43- $oVDPortgroupView_ThisTrafficRuleset.UpdateViewData (" Config.ConfigVersion" , " Config.DefaultPortConfig.FilterPolicy.FilterConfig" )
42+ $strShouldProcessMsg_target = " Traffic Ruleset of key '{0}' on VDPortGroup '{1}'" -f $oThisVNVDTrafficRuleset.TrafficRuleset.Key , $oVDPortgroupView_ThisTrafficRuleset.Name
43+ if ($PSCmdlet.ShouldProcess ($strShouldProcessMsg_target )) {
44+ # # update View data, to make sure we have the current info
45+ $oVDPortgroupView_ThisTrafficRuleset.UpdateViewData (" Config.ConfigVersion" , " Config.DefaultPortConfig.FilterPolicy.FilterConfig" )
4446
45- # # make a new config spec using values from the existing config of the vDPG
46- $specDVPortgroupConfigSpec = New-Object - Type VMware.Vim.DVPortgroupConfigSpec - Property @ {
47- ConfigVersion = $oVDPortgroupView_ThisTrafficRuleset.Config.ConfigVersion
48- DefaultPortConfig = New-Object - Type VMware.Vim.VMwareDVSPortSetting - Property @ {
49- FilterPolicy = New-Object - Type VMware.Vim.DvsFilterPolicy - Property @ {
50- FilterConfig = New-Object - Type VMware.Vim.DvsTrafficFilterConfig - Property @ {
51- # # if the current TrafficRuleset property is $null, create a new TrafficRuleset; else, use the existing TrafficRuleset
52- TrafficRuleset = if ($null -eq $oThisVNVDTrafficRuleset.TrafficRuleset ) {New-Object - TypeName VMware.Vim.DvsTrafficRuleset} else {$oThisVNVDTrafficRuleset.TrafficRuleset }
53- # # use the current FilterConfig value for this property, and not setting the other properties
54- AgentName = if ($null -eq $oVDPortgroupView_ThisTrafficRuleset.Config.DefaultPortConfig.FilterPolicy.FilterConfig.AgentName ) {" dvfilter-generic-vmware" } else {$oVDPortgroupView_ThisTrafficRuleset.Config.DefaultPortConfig.FilterPolicy.FilterConfig.AgentName }
47+ # # make a new config spec using values from the existing config of the vDPG
48+ $specDVPortgroupConfigSpec = New-Object - Type VMware.Vim.DVPortgroupConfigSpec - Property @ {
49+ ConfigVersion = $oVDPortgroupView_ThisTrafficRuleset.Config.ConfigVersion
50+ DefaultPortConfig = New-Object - Type VMware.Vim.VMwareDVSPortSetting - Property @ {
51+ FilterPolicy = New-Object - Type VMware.Vim.DvsFilterPolicy - Property @ {
52+ FilterConfig = New-Object - Type VMware.Vim.DvsTrafficFilterConfig - Property @ {
53+ # # if the current TrafficRuleset property is $null, create a new TrafficRuleset; else, use the existing TrafficRuleset
54+ TrafficRuleset = if ($null -eq $oThisVNVDTrafficRuleset.TrafficRuleset ) {New-Object - TypeName VMware.Vim.DvsTrafficRuleset} else {$oThisVNVDTrafficRuleset.TrafficRuleset }
55+ # # use the current FilterConfig value for this property, and not setting the other properties
56+ AgentName = if ($null -eq $oVDPortgroupView_ThisTrafficRuleset.Config.DefaultPortConfig.FilterPolicy.FilterConfig.AgentName ) {" dvfilter-generic-vmware" } else {$oVDPortgroupView_ThisTrafficRuleset.Config.DefaultPortConfig.FilterPolicy.FilterConfig.AgentName }
57+ } # # end new-object
5558 } # # end new-object
5659 } # # end new-object
5760 } # # end new-object
58- } # # end new-object
5961
60- if ($PSCmdlet.ParameterSetName -eq " ActOnRules" ) {
61- Switch ($RuleOperation ) {
62- " Add" {
63- # # add the new TrafficRule to the RuleSet
64- $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules += $TrafficRule
65- $bReturnUpdatedRulesetObject = $true
66- break
67- } # # end case
68- " Remove" {
69- # # remove the TrafficRule(s) from the RuleSet
70- $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules = $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules | Where-Object {$TrafficRule.Key -notcontains $_.Key }
71- break
72- } # # end case
73- " Overwrite" {
74- # # overwrite the Rules Property in the RuleSet
75- $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules = $TrafficRule
76- $bReturnUpdatedRulesetObject = $true
77- break
78- } # # end case
79- } # # end switch
80- } # # end if
62+ if ($PSCmdlet.ParameterSetName -eq " ActOnRules" ) {
63+ Switch ($RuleOperation ) {
64+ " Add" {
65+ # # add the new TrafficRule to the RuleSet
66+ $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules += $TrafficRule
67+ $bReturnUpdatedRulesetObject = $true
68+ break
69+ } # # end case
70+ " Remove" {
71+ # # remove the TrafficRule(s) from the RuleSet
72+ $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules = $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules | Where-Object {$TrafficRule.Key -notcontains $_.Key }
73+ break
74+ } # # end case
75+ " Overwrite" {
76+ # # overwrite the Rules Property in the RuleSet
77+ $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Rules = $TrafficRule
78+ $bReturnUpdatedRulesetObject = $true
79+ break
80+ } # # end case
81+ } # # end switch
82+ } # # end if
8183
82- if ($PSBoundParameters.ContainsKey (" Enabled" )) {
83- $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Enabled = $Enabled.ToBool ()
84- if ($PSBoundParameters [" RuleOperation" ] -ne " Remove" ) {$bReturnUpdatedRulesetObject = $true }
85- } # # end if
84+ if ($PSBoundParameters.ContainsKey (" Enabled" )) {
85+ $specDVPortgroupConfigSpec.DefaultPortConfig.FilterPolicy.FilterConfig.TrafficRuleset.Enabled = $Enabled.ToBool ()
86+ if ($PSBoundParameters [" RuleOperation" ] -ne " Remove" ) {$bReturnUpdatedRulesetObject = $true }
87+ } # # end if
8688
87- # # reconfig the VDPortgroup with the config spec
88- $oVDPortgroupView_ThisTrafficRuleset.ReconfigureDVPortgroup ($specDVPortgroupConfigSpec )
89+ # # reconfig the VDPortgroup with the config spec
90+ $oVDPortgroupView_ThisTrafficRuleset.ReconfigureDVPortgroup ($specDVPortgroupConfigSpec )
8991
90- # # get the current TrafficRuleSet and return it, if so specified (like, if add or overwrite of rules, but not for remove of a rule)
91- if ($bReturnUpdatedRulesetObject ) {$oVDPortgroupView_ThisTrafficRuleset | Get-VNVDTrafficRuleSet }
92+ # # get the current TrafficRuleSet and return it, if so specified (like, if add or overwrite of rules, but not for remove of a rule)
93+ if ($bReturnUpdatedRulesetObject ) {$oVDPortgroupView_ThisTrafficRuleset | Get-VNVDTrafficRuleSet }
94+ } # # end if
9295 } # # end foreach-object
9396 } # # end process
9497} # # end function
0 commit comments