Skip to content

Commit feb03f5

Browse files
committed
Merge branch 'dev'
2 parents 6b2e1d8 + b5ca669 commit feb03f5

File tree

9 files changed

+211
-30
lines changed

9 files changed

+211
-30
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
### ChangeLog for vNugglets.VDNetworking PowerShell module
22

3+
#### v1.2.0, Jun 2018
4+
- \[enhancement] Added `Set-VNVMHostNetworkAdapterVDUplink` for setting the VDSwitch Uplink for a VMHost physical NIC ("VMNIC") on the VDSwitch of which the VMNIC is already a part
5+
- \[enhancement] Added `Get-VNVSwitchByVMHostNetworkAdapter` for getting the virtual switch (standard or distributed) with which the given VMHostNetworkAdapter physical NIC is associated, if any
6+
37
#### v1.1.0, Jan 2018
48
- \[update] Added `-WhatIf` support to `New-VNVDTrafficRuleAction`, `New-VNVDTrafficRuleQualifier`
59
- \[bugfix] `-Enabled` parameter on `Set-VNVDTrafficRuleSet` was not working as expected. Fixed

ReadMe.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Contents:
66
- [Getting Help](#gettingHelpSection)
77
- [ChangeLog](#changelog)
88

9-
This PowerShell module provides functionality to automate the management of VMware vSphere virtual distributed networking items for which VMware PowerCLI does not already provide support. For example, for the reporting on-, creation of-, and removal of traffic filtering and marking rules at the vDPortgroup level.
9+
This PowerShell module provides functionality to automate the management of VMware vSphere virtual distributed networking items for which VMware PowerCLI does not already provide support. For example, for the reporting on-, creation of-, and removal of traffic filtering and marking rules at the vDPortgroup level. Another capability: managing the VDUplink of which a VMHost VMNIC is a part.
1010

1111
Some of the functionality provided by the cmdlets in this module:
1212
- Get VDPortgroup traffic policy
@@ -15,12 +15,13 @@ Some of the functionality provided by the cmdlets in this module:
1515
- Create traffic policy rule qualifiers, for use in creation of new policy rules
1616
- Create new traffic rules for the ruleset for the given vDPortgroup
1717
- Remove given traffic rule(s) from a vDPortgroup
18+
- Set the VDSwitch Uplink for a VMHost physical NIC ("VMNIC") on the VDSwitch of which the VMNIC is already a part
1819

1920
<a id="quickStart"></a>
2021
### QuickStart
2122
Chomping at the bit to get going with using this module? Of course you are! Go like this:
2223
- This module available in the PowerShell Gallery! To install it on your machine or to save it for inspection, first, use one of these:
23-
- Install the module:
24+
- Install the module (maybe after you've inspected it first with the command after this):
2425

2526
`Find-Module vNugglets.VDNetworking | Install-Module`
2627
- Or, save the module first for further inspection/distribution (always a good idea):
@@ -55,12 +56,3 @@ The cmdlets in this module all have proper help, so you can learn and discover j
5556
<a id="changelog"></a>
5657
### ChangeLog
5758
The [ChangeLog](ChangeLog.md) for this module is, of course, a log of the major changes through the module's history. Enjoy the story.
58-
59-
### Other Notes
60-
A few notes on updates to this repo:
61-
62-
Jan 2018
63-
- initial public "prod" release
64-
65-
Dec 2017
66-
- initial public dev release

ToDoAndNotes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
## Notes on Traffic Filtering and Marking code
1+
## Notes on vNugglets.VDNetworking PowerShell module
22

33

44
### Need to make:
55
- Tests (partial, currently, written for interactive test, not fully automated)
66

77
### Maybe eventually add/update:
8+
- `Set-VNVMHostNetworkAdapterVDUplink`: add check that, if all specified VMHostNetworkAdapters are already associated with the given UplinkNames, take no action and return a Verbose message to that effect ("already in desired state"); approximate start/finish points for this feature are noted in comments in the code
89
- `Copy-VNVDTrafficRule -Rule -Ruleset <rulesettowhichtocopy>`
910
- `Set-VNVDTrafficRule` -- to update a rule, maybe? (like change qualifier/action?)
1011
- `New-VNVDTrafficRule`

Update-ThisModuleManifest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ begin {
1515
$hshManifestParams = @{
1616
# Confirm = $true
1717
Path = $strFilespecForPsd1
18-
ModuleVersion = "1.1.0"
18+
ModuleVersion = "1.2.0"
1919
Author = "Matt Boren (@mtboren)"
2020
CompanyName = 'vNugglets for the VMware PowerCLI community'
2121
Copyright = "MIT License"
2222
Description = "Module with functions for managing VMware vSphere Virtual Distributed Networking components like traffic filtering and marking"
2323
# AliasesToExport = @()
2424
FileList = Write-Output "${strModuleName}.psd1" "${strModuleName}_ModRoot.psm1" "en-US\about_${strModuleName}.help.txt" GetItems.ps1 NewItems.ps1 RemoveItems.ps1 SetItems.ps1 "${strModuleName}_SupportingFunctions.ps1" "${strModuleName}.format.ps1xml" "${strModuleName}_init.ps1" "${strModuleName}_ClassDefinition.ps1"
2525
FormatsToProcess = "${strModuleName}.format.ps1xml"
26-
FunctionsToExport = Write-Output Get-VNVDTrafficFilterPolicyConfig Get-VNVDTrafficRuleSet Get-VNVDTrafficRule Get-VNVDTrafficRuleQualifier Get-VNVDTrafficRuleAction New-VNVDTrafficRuleQualifier New-VNVDTrafficRuleAction New-VNVDTrafficRule Remove-VNVDTrafficRule Set-VNVDTrafficRuleSet
26+
FunctionsToExport = Write-Output Get-VNVDTrafficFilterPolicyConfig Get-VNVDTrafficRuleSet Get-VNVDTrafficRule Get-VNVDTrafficRuleQualifier Get-VNVDTrafficRuleAction Get-VNVSwitchByVMHostNetworkAdapter New-VNVDTrafficRuleQualifier New-VNVDTrafficRuleAction New-VNVDTrafficRule Remove-VNVDTrafficRule Set-VNVDTrafficRuleSet Set-VNVMHostNetworkAdapterVDUplink
2727
IconUri = "https://avatars0.githubusercontent.com/u/10615837"
2828
LicenseUri = "https://github.com/vNugglets/vNuggletsPSMod_vDNetworking/blob/master/License"
2929
NestedModules = Write-Output GetItems.ps1 NewItems.ps1 RemoveItems.ps1 SetItems.ps1 "${strModuleName}_SupportingFunctions.ps1"
@@ -33,7 +33,7 @@ begin {
3333
RequiredModules = "VMware.VimAutomation.Vds"
3434
RootModule = "${strModuleName}_ModRoot.psm1"
3535
ScriptsToProcess = "${strModuleName}_init.ps1", "${strModuleName}_ClassDefinition.ps1"
36-
Tags = Write-Output vNugglets VMware vSphere PowerCLI VDPortGroup TrafficFiltering Filter Filtering TrafficMarking Mark Marking VDSwitch
36+
Tags = Write-Output vNugglets VMware vSphere PowerCLI VDPortGroup TrafficFiltering Filter Filtering TrafficMarking Mark Marking VDSwitch Uplink VDUplink VMHostNetworkAdapater VMNIC
3737
# Verbose = $true
3838
} ## end hashtable
3939

docs/examples.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilt
4141
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficRuleSet
4242
```
4343

44+
#### `Get-VNVSwitchByVMHostNetworkAdapter`: Get the virtual switch (standard or distributed) with which the given VMHostNetworkAdapter physical NIC is associated, if any.
45+
46+
```PowerShell
47+
## Get the vSwitch with which VMNIC2 on myVMHost0.dom.com is associated
48+
Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic2 | Get-VNVSwitchByVMHostNetworkAdapter
49+
```
50+
4451
#### `New-VNVDTrafficRule`: Make new Traffic Rule and add it to the given Traffic Ruleset of a vDPortgroup traffic filter policy
4552

4653
```PowerShell
@@ -100,3 +107,15 @@ Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilt
100107
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficRuleSet | Set-VNVDTrafficRuleSet -Enabled:$false
101108
```
102109

110+
#### `Set-VNVMHostNetworkAdapterVDUplink`: Set the VDSwitch Uplink for a VMHost physical NIC ("VMNIC") on the VDSwitch of which the VMNIC is already a part
111+
112+
```PowerShell
113+
## Set the VMNIC "vminic3" from VMHost myVMHost0.dom.com to be in VDUplink "Uplinks-02" on VDS myVDSwitch0 (the vDSwitch of which VMNIC3 is a part)
114+
Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic3 | Set-VNVMHostNetworkAdapterVDUplink -UplinkName Uplinks-02
115+
116+
## Set the VMNICs "vminic2", "vminic3" from VMHost myVMHost0.dom.com to be in VDUplinks "Uplinks-01", "Uplinks-02" on VDS myVDSwitch0 (the vDSwitch of which VMNIC2 and VMNIC3 are a part)
117+
## Could then check out the current status like:
118+
## Get-VDSwitch myVDSwitch0 | Get-VDPort -Uplink | Where-Object {$_.ProxyHost.Name -eq "myVMHost0.dom.com"} | Select-Object key, ConnectedEntity, ProxyHost, Name | Sort-Object ProxyHost, Name
119+
Set-VNVMHostNetworkAdapterVDUplink -VMHostNetworkAdapter (Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic2, vmnic3) -UplinkName Uplinks-01, Uplinks-02
120+
```
121+

makeExamplesMd.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ Get-Command -Module vNugglets.VDNetworking -PipelineVariable oThisCommand | Fore
66
$oHelp_ThisCommand = Get-Help -Full -Name $oThisCommand.Name
77
## make a string with the example description(s) and example code(s) for this cmdlet
88
$strExampleCodeBlock = ($oHelp_ThisCommand.examples.example | Foreach-Object {
9-
"`n## {0}`n{1}" -f ($($_.remarks.Text | Where-Object {-not [System.String]::IsNullOrEmpty($_)}) -join "`n"), $_.code
9+
## for this example, make a single string that is like:
10+
# ## example's comment line 0 here
11+
# ## example's comment line 1 here
12+
# example's actual code here
13+
"`n{0}`n{1}" -f ($($_.remarks.Text | Where-Object {-not [System.String]::IsNullOrEmpty($_)} | Foreach-Object {$_.Split("`n")} | Foreach-Object {"## $_"}) -join "`n"), $_.code
1014
}) -join "`n"
1115
## make a string that has the cmdlet name and description followed by a code block with example(s)
1216
"#### ``{0}``: {1}`n`n``````PowerShell{2}`n```````n" -f `

vNugglets.VDNetworking/GetItems.ps1

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,46 @@ function Get-VNVDTrafficRuleAction {
201201
$_.TrafficRule.Action
202202
} ## end foreach-object
203203
} ## end process
204-
} ## end function
204+
} ## end function
205+
206+
207+
208+
function Get-VNVSwitchByVMHostNetworkAdapter {
209+
<# .Description
210+
Get the virtual switch (standard or distributed) with which the given VMHostNetworkAdapter physical NIC is associated, if any.
211+
212+
.Example
213+
Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic2 | Get-VNVSwitchByVMHostNetworkAdapter
214+
Get the vSwitch with which VMNIC2 on myVMHost0.dom.com is associated
215+
216+
.Outputs
217+
Virtual standard- or distributed switch with which given physical VMHost network adapter is associated, if any
218+
#>
219+
[CmdletBinding()]
220+
param(
221+
## The VMHostNetworkAdapter (physical NIC) for which to get the vSwitch
222+
[parameter(Mandatory=$true, ValueFromPipeline=$true)][VMware.VimAutomation.Types.Host.NIC.PhysicalNic[]]$VMHostNetworkAdapter
223+
) ## end param
224+
225+
process {
226+
$VMHostNetworkAdapter | Foreach-Object {
227+
$oThisVMHostNetworkAdapter = $_
228+
if ($oAssociatedVSwitch = $oThisVMHostNetworkAdapter.VMHost.ExtensionData.Config.Network.Vswitch, $oThisVMHostNetworkAdapter.VMHost.ExtensionData.Config.Network.ProxySwitch | Foreach-Object {$_} | Where-Object {$_.Pnic -contains $oThisVMHostNetworkAdapter.Id}) {
229+
switch ($oAssociatedVSwitch) {
230+
## vSS
231+
{$_ -is [VMware.Vim.HostVirtualSwitch]} {
232+
$oThisVMHostNetworkAdapter.VMHost | Get-VirtualSwitch -Standard -Name $oAssociatedVSwitch.Name
233+
break
234+
} ## end case
235+
## vDSwitch
236+
{$_ -is [VMware.Vim.HostProxySwitch]} {
237+
$oThisVMHostNetworkAdapter.VMHost | Get-VDSwitch -Name $oAssociatedVSwitch.DvsName
238+
break
239+
} ## end case
240+
default {Write-Warning "vSwitch not of expected type of either [VMware.Vim.HostVirtualSwitch] or [VMware.Vim.HostProxySwitch]. What kind of vSwitch is it? $_"}
241+
} ## end switch
242+
} ## end if
243+
else {Write-Verbose "No vSwitch associated with VMNIC '$($oThisVMHostNetworkAdapter.Name)' found on VMHost '$($oThisVMHostNetworkAdapter.VMHost.Name)'"}
244+
} ## end Foreach-Object
245+
} ## end process
246+
} ## end fn

0 commit comments

Comments
 (0)