Skip to content

Commit dd983ac

Browse files
committed
Merge branch 'enh_TakePSScriptAnalyzerSuggestions' into dev
2 parents 935ce25 + 7cc362f commit dd983ac

File tree

7 files changed

+205
-190
lines changed

7 files changed

+205
-190
lines changed

ChangeLog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
### ChangeLog for vNugglets.VDNetworking PowerShell module
22

3-
#### v1.0, Jan 2017
3+
#### v1.0.next, Sometime 2018
4+
- \[update] Added `-WhatIf` support to `New-VNVDTrafficRuleAction`, `New-VNVDTrafficRuleQualifier`
5+
- \[bugfix] `-Enabled` parameter on `Set-VNVDTrafficRuleSet` was not working as expected. Fixed
6+
- \[miscellaneous] Other various updates and optimizations
7+
8+
#### v1.0, Jan 2018
49
- initial public "prod" release of `master` branch
510
- published module in PowerShell Gallery
611

testing/vNugglets.VDNetworking.Tests_Get.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ $oTestVDPG = New-VDPortgroup -VDSwitch $oTestVDSwitch -Name "vNuggsTestVDPG_toDe
3434
$oTestVDPG | Get-VNVDTrafficRuleSet | New-VNVDTrafficRule -Name "testRule2_toDelete_${strGuidForThisTest}" -Action (New-VNVDTrafficRuleAction -QosTag 7 -DscpTag 30) -Direction both -Qualifier (New-VNVDTrafficRuleQualifier -SystemTrafficType vdp), (New-VNVDTrafficRuleQualifier -DestinationIpAddress 172.16.100.0/24)
3535
- get TrafficRuleSet (should have three TrafficRules)
3636
$oTestVDPG | Get-VNVDTrafficRuleSet
37+
- enable the TrafficRuleSet
38+
$oTestVDPG | Get-VNVDTrafficRuleSet | Set-VNVDTrafficRuleSet -Enabled
3739
- get TrafficRules (should be three)
3840
$oTestVDPG | Get-VNVDTrafficRuleSet | Get-VNVDTrafficRule | Measure-Object
3941
- remove two TrafficRules

vNugglets.VDNetworking/GetItems.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function Get-VNVDTrafficFilterPolicyConfig {
2020
$VDPortgroup | Foreach-Object {
2121
$oThisVDPG = $_
2222
New-Object -Type VNVDTrafficFilterPolicyConfig -Property @{
23-
TrafficFilterPolicyConfig = $_.ExtensionData.Config.DefaultPortConfig.FilterPolicy.FilterConfig
24-
VDPortgroupView = $_.ExtensionData
23+
TrafficFilterPolicyConfig = $oThisVDPG.ExtensionData.Config.DefaultPortConfig.FilterPolicy.FilterConfig
24+
VDPortgroupView = $oThisVDPG.ExtensionData
2525
} ## end new-object
2626
} ## end foreach-object
2727
} ## end process

vNugglets.VDNetworking/NewItems.ps1

Lines changed: 141 additions & 136 deletions
Large diffs are not rendered by default.

vNugglets.VDNetworking/RemoveItems.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function Remove-VNVDTrafficRule {
4545
$strMsgForShouldProcess_Action = "Remove {0} traffic rule{1} (of name{1} '{2}')" -f $intNumDvsTrafficRulesToRemove, $(if ($intNumDvsTrafficRulesToRemove -ne 1) {"s"}), ($arrDvsTrafficRulesToRemove.Description -join ", ")
4646
if ($PSCmdlet.ShouldProcess($strMsgForShouldProcess_Target, $strMsgForShouldProcess_Action)) {
4747
try {
48-
## use the helper function to remove this TrafficRule from the TrafficRuleSet Rules array
49-
$oUpdatedTrafficRuleset = _Set-VNVDTrafficRuleset_helper -TrafficRuleSet $oVNVDTrafficRuleset_TheseRules -TrafficRule $arrDvsTrafficRulesToRemove -RuleOperation Remove
48+
## use the helper function to remove this TrafficRule from the TrafficRuleSet Rules array; the "Remove" RuleOperation returns nothing of the helper function
49+
Set-VNVDTrafficRuleset_helper -TrafficRuleSet $oVNVDTrafficRuleset_TheseRules -TrafficRule $arrDvsTrafficRulesToRemove -RuleOperation Remove
5050
} ## end try
5151
catch {Throw $_}
5252
} ## end if

vNugglets.VDNetworking/SetItems.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function Set-VNVDTrafficRuleSet {
2727
$TrafficRuleSet | Foreach-Object {
2828
$oThisVNVDTrafficRuleset = $_
2929
$strMsgForShouldProcess_Target = "Traffic ruleset '{0}' on vDPG '{1}'" -f $oThisVNVDTrafficRuleset.TrafficRuleset.Key, $oThisVNVDTrafficRuleset.VDPortgroupView.Name
30-
$strMsgForShouldProcess_Action = "{0} ruleset" -f $(if ($Enable) {"Enable"} else {"Disable"})
30+
$strMsgForShouldProcess_Action = "{0} ruleset" -f $(if ($Enabled) {"Enable"} else {"Disable"})
3131
if ($PSCmdlet.ShouldProcess($strMsgForShouldProcess_Target, $strMsgForShouldProcess_Action)) {
3232
try {
3333
## use the helper function to add this new TrafficRule to the TrafficRuleSet Rules array
34-
_Set-VNVDTrafficRuleset_helper -TrafficRuleSet $oThisVNVDTrafficRuleset -Enabled:$Enabled
34+
Set-VNVDTrafficRuleset_helper -TrafficRuleSet $oThisVNVDTrafficRuleset -Enabled:$Enabled
3535
} ## end try
3636
catch {Throw $_}
3737
} ## end if
Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
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

Comments
 (0)