Skip to content

Commit 0419a0f

Browse files
committed
add helper function for reusability for setting RuleSet properties
1 parent 2a7ef38 commit 0419a0f

File tree

7 files changed

+135
-198
lines changed

7 files changed

+135
-198
lines changed

Update-ThisModuleManifest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ begin {
1919
Copyright = "MIT License"
2020
Description = "Module with functions for managing VMware vSphere Virtual Distributed Networking components like traffic filtering and marking"
2121
# AliasesToExport = @()
22-
FileList = Write-Output "${strModuleName}.psd1" "${strModuleName}_ModRoot.psm1" "en-US\about_${strModuleName}.help.txt" GetItems.ps1 NewItems.ps1
22+
FileList = Write-Output "${strModuleName}.psd1" "${strModuleName}_ModRoot.psm1" "en-US\about_${strModuleName}.help.txt" GetItems.ps1 NewItems.ps1 "${strModuleName}_SupportingFunctions.ps1"
2323
# FormatsToProcess = "${strModuleName}.format.ps1xml"
24-
FunctionsToExport = Write-Output Get-VNVDTrafficFilterPolicyConfig Get-VNVDTrafficRuleSet Get-VNVDTrafficRule Get-VNVDTrafficRuleQualifier New-VNVDNetworkRuleQualifier New-VNVDTrafficRuleAction New-VNVDTrafficRule
24+
FunctionsToExport = Write-Output Get-VNVDTrafficFilterPolicyConfig Get-VNVDTrafficRuleSet Get-VNVDTrafficRule Get-VNVDTrafficRuleQualifier New-VNVDTrafficRuleQualifier New-VNVDTrafficRuleAction New-VNVDTrafficRule
2525
IconUri = "https://avatars0.githubusercontent.com/u/10615837"
2626
LicenseUri = "https://github.com/vNugglets/vNuggletsPSMod_vDNetworking/blob/master/License"
27-
NestedModules = Write-Output GetItems.ps1 NewItems.ps1
27+
NestedModules = Write-Output GetItems.ps1 NewItems.ps1 "${strModuleName}_SupportingFunctions.ps1"
2828
PowerShellVersion = [System.Version]"5.0"
2929
ProjectUri = "https://github.com/vNugglets/vNuggletsPSMod_vDNetworking"
3030
ReleaseNotes = "See release notes at https://github.com/vNugglets/vNuggletsPSMod_vDNetworking/blob/master/ChangeLog.md"

notes_SetCoSAndDSCPOnVDPG.ps1

Lines changed: 20 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
## Sample code to set Class of Service (CoS) and Differentiated Service Code Point (DSCP) values on vDPGs on a VDSwitch
2-
## params to take for new FilterPolicy
3-
vDPG
4-
Name
5-
RuleAction
6-
[switch]Enabled = $true
7-
[int]CoSValue -- nullable
8-
[int]DSCPValue -- nullable
9-
[ValidateSet("incomingPackets","outgoingPackets","both")][VMware.Vim.DvsNetworkRuleDirectionType]TrafficDirection
10-
[VMware.Vim.DvsNetworkRuleQualifier[]]RuleQualifier
11-
1+
## Sample code to set Class of Service (CoS) and Differentiated Service Code Point (DSCP) TrafficRules to TrafficFilterConfig TrafficRuleSet on vDPGs on a VDSwitch
122

133
Need:
144
- Remove-VNVDTrafficRule -Rule -RunAsync
@@ -18,42 +8,42 @@ Need:
188
- set confirmation level to High
199
- enables the overwriting of the rules in the ruleset with jsut the new Rule(s) specified
2010
- Get-VNVDTrafficRuleAction
21-
- New-VNVDTrafficRule
22-
- may need to add logic to ensure it meets requirement stated in API ref of, "There can be a maximum of 1 DvsIpNetworkRuleQualifier, 1 DvsMacNetworkRuleQualifier and 1 DvsSystemTrafficNetworkRuleQualifier for a total of 3 qualifiers"
23-
- add to TrafficRuleset
2411

2512
Maybe eventually add:
26-
Copy-VNVDTrafficRule -Rule -Ruleset rulesettowhichtocopy
27-
Set-VNVDTrafficRule -- to update a rule, maybe? (like change qualifier/action?)
13+
- Copy-VNVDTrafficRule -Rule -Ruleset rulesettowhichtocopy
14+
- Set-VNVDTrafficRule -- to update a rule, maybe? (like change qualifier/action?)
15+
- New-VNVDTrafficRule
16+
- may need to add logic to ensure it meets requirement stated in API ref of, "There can be a maximum of 1 DvsIpNetworkRuleQualifier, 1 DvsMacNetworkRuleQualifier and 1 DvsSystemTrafficNetworkRuleQualifier for a total of 3 qualifiers"
2817

2918
Done (to at least some extent -- some may have further features to implement):
3019
- Get-VNVDTrafficFilterPolicyConfig
3120
- Get-VNVDTrafficRuleSet (returns VNVDTrafficRuleSet object with VDPG property, too)
3221
- Get-VNVDTrafficRule
3322
- Get-VNVDTrafficRuleQualifier
34-
- New-VNVDNetworkRuleQualifier
23+
- New-VNVDTrafficRuleQualifier
3524
- New-VNVDTrafficRuleAction
3625
- remaining Action types to implement: DvsCopyNetworkRuleAction, DvsGreEncapNetworkRuleAction, DvsLogNetworkRuleAction, DvsMacRewriteNetworkRuleAction, DvsPuntNetworkRuleAction, DvsRateLimitNetworkRuleAction
37-
- Ruleset object returned Get-VNVDTrafficRuleSet from should have property of "parent vDPG", to be used for vDPG reconfig task (need to add vDPG property to return from Get-VNVDTrafficFilterPolicyConfig, Get-VNVDTrafficRuleSet, and Get-VNVDTrafficRule)
26+
- Ruleset object returned from Get-VNVDTrafficRuleSet should have property of "parent vDPG", to be used for vDPG reconfig task (need to add vDPG property to return from Get-VNVDTrafficFilterPolicyConfig, Get-VNVDTrafficRuleSet, and Get-VNVDTrafficRule)
27+
- New-VNVDTrafficRule
28+
- adds rule to TrafficRuleset
3829

3930
## something like
4031
# gets
4132
# get-vdpg | get-vdtrafficruleset | add-vdtrafficrule
4233
# get-vdpg | get-vdtrafficruleset | get-vdtrafficrule
4334
# new
44-
# $oTraffQualifier0 = New-VNVDNetworkRuleQualifier -ParmsHere
45-
# $oTraffQualifier1 = New-VNVDNetworkRuleQualifier -ParmsHere
35+
# $oTraffQualifier0 = New-VNVDTrafficRuleQualifier -ParmsHere
36+
# $oTraffQualifier1 = New-VNVDTrafficRuleQualifier -ParmsHere
4637
# $oTraffRule = New-VNVDTrafficRule -Direction blahh -Qualifier $oTraffQualifier0, $oTraffQualifier1
4738
# get-vdpg someVdpg | New-VNVDTrafficPolicy -Enabled -Rule $oTraffRule
4839
# or
4940
# overwrite all rules in the ruleset (if any) with new rule(s) specified
50-
# get-vdpg someVdpg | Get-VNVdpgTrafficRuleSet | Set-VNVdpgTrafficRuleSet -Enabled -Rule (New-VNVDTrafficRule -Direction blahh -Qualifier (New-VNVDNetworkRuleQualifier -ParmsHere))
41+
# get-vdpg someVdpg | Get-VNVdpgTrafficRuleSet | Set-VNVdpgTrafficRuleSet -Enabled -Rule (New-VNVDTrafficRule -Direction blahh -Qualifier (New-VNVDTrafficRuleQualifier -ParmsHere))
5142
# add traffic rule to traffic ruleset
52-
# get-vdpg someVdpg | Get-VNVdpgTrafficRuleSet | Add-VNVdpgTrafficRuleSetRule -Rule (New-VNVDTrafficRule -Direction blahh -Qualifier (New-VNVDNetworkRuleQualifier -ParmsHere))
43+
# get-vdpg someVdpg | Get-VNVdpgTrafficRuleSet | Add-VNVdpgTrafficRuleSetRule -Rule (New-VNVDTrafficRule -Direction blahh -Qualifier (New-VNVDTrafficRuleQualifier -ParmsHere))
5344

5445

55-
<# couple of examples
56-
## from https://communities.vmware.com/thread/493610?q=distributed%20switch%20traffic%20filter
46+
<# example from https://communities.vmware.com/thread/493610?q=distributed%20switch%20traffic%20filter
5747
$dvSwName = 'dvSw1'
5848
$dvPgNames = 'dvPg1'
5949
@@ -88,129 +78,12 @@ foreach($pg in (Get-View -Id $dvSw.ExtensionData.Portgroup | Where {$dvPgNames
8878
8979
$pg.ReconfigureDVPortgroup($spec)
9080
}
91-
92-
93-
94-
# or, partially working, from https://www.reddit.com/r/vmware/comments/6ughyq/powercli_configure_traffic_filtering_and_marking/
95-
$dvSwName = 'name-of-dvsw'
96-
$dvPgNames = 'name-of-pg'
97-
98-
$dvSw = Get-VDSwitch -Name $dvSwName
99-
100-
101-
foreach($pg in (Get-View -Id $dvSw.ExtensionData.Portgroup | Where {$dvPgNames -contains $_.Name})){
102-
$spec = New-Object VMware.Vim.DVPortgroupConfigSpec
103-
$spec.ConfigVersion = $pg.Config.ConfigVersion
104-
$spec.DefaultPortConfig = New-Object VMware.Vim.VMwareDVSPortSetting
105-
$spec.DefaultPortConfig.FilterPolicy = New-Object VMware.Vim.DvsFilterPolicy
106-
107-
$filter = New-Object VMware.Vim.DvsTrafficFilterConfig
108-
$filter.AgentName = 'dvfilter-generic-vmware'
109-
110-
$ruleSet = New-Object VMware.Vim.DvsTrafficRuleset
111-
$ruleSet.Enabled = $true
112-
113-
114-
$bu01ip4 = New-Object VMware.Vim.DvsTrafficRule
115-
$bu01ip4.Description = 'Tag AF23 to IP4 BU01'
116-
$bu01ip4.Direction = 'both'
117-
# of basetype VMware.Vim.DvsNetworkRuleQualifier
118-
$bu01ip4Props = New-Object VMware.Vim.DvsIpNetworkRuleQualifier
119-
$bu01ip4Props.protocol = ${6}
120-
$bu01ip4Props.destinationAddress = ${ip:172.16.14.31}
121-
$bu01ip4.qualifier += $bu01ip4Props
122-
123-
124-
$action = New-Object VMware.Vim.DvsUpdateTagNetworkRuleAction
125-
$action.DSCPTag = 22
126-
127-
128-
$bu01ip4.Action += $action
129-
$ruleSet.Rules += $bu01ip4
130-
131-
$filter.TrafficRuleSet += $ruleSet
132-
spec.DefaultPortConfig.FilterPolicy.FilterConfig += $filter
133-
$pg.ReconfigureDVPortgroup($spec)
134-
}
13581
#>
13682

13783

138-
## get VDTrafficFilterPolicyConfig:
139-
#$viewVDPG.Config.DefaultPortConfig.FilterPolicy.FilterConfig
140-
## can get:
141-
# VDTrafficFilterPolicyConfig: Key, Enabled, Precedence, Key, AgentName, SlotNumber, Parameters, OnFailure, Inherited
142-
# --> VDTrafficFilterPolicyConfig.VDTrafficRule: Key, Description, Sequence, Qualifier, Action, Direction
143-
# --> VDTrafficFilterPolicyConfig.VDTrafficRule.VDTrafficRuleQualifier: VMware.Vim.DvsSystemTrafficNetworkRuleQualifier or VMware.Vim.DvsIpNetworkRuleQualifier or one other
144-
<#
145-
{
146-
"FilterConfig": [
147-
{
148-
"TrafficRuleset": {
149-
"Key": "51_255_ _13461229",
150-
"Enabled": true,
151-
"Precedence": null,
152-
"Rules": [
153-
{
154-
"Key": "51_255_ _13461229_71622573",
155-
"Description": "test VSAN rule0",
156-
"Sequence": 10,
157-
"Qualifier": [
158-
{
159-
"TypeOfSystemTraffic": {
160-
"Value": "vsan",
161-
"Negate": false
162-
},
163-
"Key": "51_255_ _13461229_71622573_99129637"
164-
}
165-
],
166-
"Action": {
167-
"QosTag": null,
168-
"DscpTag": 25
169-
},
170-
"Direction": "incomingPackets"
171-
},
172-
{
173-
"Key": "51_255_ _13461229_16439589",
174-
"Description": "test BUR rule",
175-
"Sequence": 20,
176-
"Qualifier": [
177-
{
178-
"SourceAddress": {
179-
"AddressPrefix": "255.255.255.255",
180-
"PrefixLength": 0,
181-
"Negate": null
182-
},
183-
"DestinationAddress": {
184-
"AddressPrefix": "10.5.64.0",
185-
"PrefixLength": 20,
186-
"Negate": false
187-
},
188-
"Protocol": {
189-
"Value": 6,
190-
"Negate": false
191-
},
192-
"SourceIpPort": null,
193-
"DestinationIpPort": null,
194-
"TcpFlags": null,
195-
"Key": "51_255_ _13461229_16439589_25543994"
196-
}
197-
],
198-
"Action": {
199-
"QosTag": null,
200-
"DscpTag": 8
201-
},
202-
"Direction": "incomingPackets"
203-
}
204-
]
205-
},
206-
"Key": "51_255_ _91108317",
207-
"AgentName": "dvfilter-generic-vmware",
208-
"SlotNumber": null,
209-
"Parameters": null,
210-
"OnFailure": null,
211-
"Inherited": false
212-
}
213-
],
214-
"Inherited": false
215-
}
216-
#>
84+
## get VDTrafficFilterPolicyConfig:
85+
#$viewVDPG.Config.DefaultPortConfig.FilterPolicy.FilterConfig
86+
## can get:
87+
# VDTrafficFilterPolicyConfig: Key, Enabled, Precedence, Key, AgentName, SlotNumber, Parameters, OnFailure, Inherited
88+
# --> VDTrafficFilterPolicyConfig.VDTrafficRule: Key, Description, Sequence, Qualifier, Action, Direction
89+
# --> VDTrafficFilterPolicyConfig.VDTrafficRule.VDTrafficRuleQualifier: VMware.Vim.DvsSystemTrafficNetworkRuleQualifier or VMware.Vim.DvsIpNetworkRuleQualifier or one other

vNugglets.VDNetworking/GetItems.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function Get-VNVDTrafficRuleSet {
7373
{"ByVDPortGroup", "ByVDPortGroupView" -contains $_} {
7474
## get the View objects over which to iterate (either the .ExtensionData)
7575
$(if ($PSCmdlet.ParameterSetName -eq "ByVDPortGroup") {$VDPortgroup | Foreach-Object {$_.ExtensionData}} else {$VDPortgroupView}) | Foreach-Object {
76+
## update the ViewData for this vDPG, just to be sure that all is current
7677
$oThisVDPGView = $_; $oThisVDPGView.UpdateViewData("Config")
7778
$oThisVDPGView.Config.DefaultPortConfig.FilterPolicy.FilterConfig | Foreach-Object {
7879
New-Object -Type VNVDTrafficRuleSet -Property @{

0 commit comments

Comments
 (0)