Skip to content

Commit

Permalink
Merge branch 'feat_SetVNVMHostNetworkAdapterVDUplink' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mtboren committed Jun 23, 2018
2 parents 5484819 + d07dce4 commit b5ca669
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 30 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### ChangeLog for vNugglets.VDNetworking PowerShell module

#### v1.2.0, Jun 2018
- \[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
- \[enhancement] Added `Get-VNVSwitchByVMHostNetworkAdapter` for getting the virtual switch (standard or distributed) with which the given VMHostNetworkAdapter physical NIC is associated, if any

#### v1.1.0, Jan 2018
- \[update] Added `-WhatIf` support to `New-VNVDTrafficRuleAction`, `New-VNVDTrafficRuleQualifier`
- \[bugfix] `-Enabled` parameter on `Set-VNVDTrafficRuleSet` was not working as expected. Fixed
Expand Down
14 changes: 3 additions & 11 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Contents:
- [Getting Help](#gettingHelpSection)
- [ChangeLog](#changelog)

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.
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.

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

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

`Find-Module vNugglets.VDNetworking | Install-Module`
- Or, save the module first for further inspection/distribution (always a good idea):
Expand Down Expand Up @@ -55,12 +56,3 @@ The cmdlets in this module all have proper help, so you can learn and discover j
<a id="changelog"></a>
### ChangeLog
The [ChangeLog](ChangeLog.md) for this module is, of course, a log of the major changes through the module's history. Enjoy the story.

### Other Notes
A few notes on updates to this repo:

Jan 2018
- initial public "prod" release

Dec 2017
- initial public dev release
3 changes: 2 additions & 1 deletion ToDoAndNotes.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## Notes on Traffic Filtering and Marking code
## Notes on vNugglets.VDNetworking PowerShell module


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

### Maybe eventually add/update:
- `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
- `Copy-VNVDTrafficRule -Rule -Ruleset <rulesettowhichtocopy>`
- `Set-VNVDTrafficRule` -- to update a rule, maybe? (like change qualifier/action?)
- `New-VNVDTrafficRule`
Expand Down
6 changes: 3 additions & 3 deletions Update-ThisModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ begin {
$hshManifestParams = @{
# Confirm = $true
Path = $strFilespecForPsd1
ModuleVersion = "1.1.0"
ModuleVersion = "1.2.0"
Author = "Matt Boren (@mtboren)"
CompanyName = 'vNugglets for the VMware PowerCLI community'
Copyright = "MIT License"
Description = "Module with functions for managing VMware vSphere Virtual Distributed Networking components like traffic filtering and marking"
# AliasesToExport = @()
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"
FormatsToProcess = "${strModuleName}.format.ps1xml"
FunctionsToExport = Write-Output Get-VNVDTrafficFilterPolicyConfig Get-VNVDTrafficRuleSet Get-VNVDTrafficRule Get-VNVDTrafficRuleQualifier Get-VNVDTrafficRuleAction New-VNVDTrafficRuleQualifier New-VNVDTrafficRuleAction New-VNVDTrafficRule Remove-VNVDTrafficRule Set-VNVDTrafficRuleSet
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
IconUri = "https://avatars0.githubusercontent.com/u/10615837"
LicenseUri = "https://github.com/vNugglets/vNuggletsPSMod_vDNetworking/blob/master/License"
NestedModules = Write-Output GetItems.ps1 NewItems.ps1 RemoveItems.ps1 SetItems.ps1 "${strModuleName}_SupportingFunctions.ps1"
Expand All @@ -33,7 +33,7 @@ begin {
RequiredModules = "VMware.VimAutomation.Vds"
RootModule = "${strModuleName}_ModRoot.psm1"
ScriptsToProcess = "${strModuleName}_init.ps1", "${strModuleName}_ClassDefinition.ps1"
Tags = Write-Output vNugglets VMware vSphere PowerCLI VDPortGroup TrafficFiltering Filter Filtering TrafficMarking Mark Marking VDSwitch
Tags = Write-Output vNugglets VMware vSphere PowerCLI VDPortGroup TrafficFiltering Filter Filtering TrafficMarking Mark Marking VDSwitch Uplink VDUplink VMHostNetworkAdapater VMNIC
# Verbose = $true
} ## end hashtable

Expand Down
19 changes: 19 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilt
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficRuleSet
```

#### `Get-VNVSwitchByVMHostNetworkAdapter`: Get the virtual switch (standard or distributed) with which the given VMHostNetworkAdapter physical NIC is associated, if any.

```PowerShell
## Get the vSwitch with which VMNIC2 on myVMHost0.dom.com is associated
Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic2 | Get-VNVSwitchByVMHostNetworkAdapter
```

#### `New-VNVDTrafficRule`: Make new Traffic Rule and add it to the given Traffic Ruleset of a vDPortgroup traffic filter policy

```PowerShell
Expand Down Expand Up @@ -100,3 +107,15 @@ Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilt
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficRuleSet | Set-VNVDTrafficRuleSet -Enabled:$false
```

#### `Set-VNVMHostNetworkAdapterVDUplink`: Set the VDSwitch Uplink for a VMHost physical NIC ("VMNIC") on the VDSwitch of which the VMNIC is already a part

```PowerShell
## 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)
Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic3 | Set-VNVMHostNetworkAdapterVDUplink -UplinkName Uplinks-02
## 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)
## Could then check out the current status like:
## Get-VDSwitch myVDSwitch0 | Get-VDPort -Uplink | Where-Object {$_.ProxyHost.Name -eq "myVMHost0.dom.com"} | Select-Object key, ConnectedEntity, ProxyHost, Name | Sort-Object ProxyHost, Name
Set-VNVMHostNetworkAdapterVDUplink -VMHostNetworkAdapter (Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic2, vmnic3) -UplinkName Uplinks-01, Uplinks-02
```

6 changes: 5 additions & 1 deletion makeExamplesMd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ Get-Command -Module vNugglets.VDNetworking -PipelineVariable oThisCommand | Fore
$oHelp_ThisCommand = Get-Help -Full -Name $oThisCommand.Name
## make a string with the example description(s) and example code(s) for this cmdlet
$strExampleCodeBlock = ($oHelp_ThisCommand.examples.example | Foreach-Object {
"`n## {0}`n{1}" -f ($($_.remarks.Text | Where-Object {-not [System.String]::IsNullOrEmpty($_)}) -join "`n"), $_.code
## for this example, make a single string that is like:
# ## example's comment line 0 here
# ## example's comment line 1 here
# example's actual code here
"`n{0}`n{1}" -f ($($_.remarks.Text | Where-Object {-not [System.String]::IsNullOrEmpty($_)} | Foreach-Object {$_.Split("`n")} | Foreach-Object {"## $_"}) -join "`n"), $_.code
}) -join "`n"
## make a string that has the cmdlet name and description followed by a code block with example(s)
"#### ``{0}``: {1}`n`n``````PowerShell{2}`n```````n" -f `
Expand Down
44 changes: 43 additions & 1 deletion vNugglets.VDNetworking/GetItems.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,46 @@ function Get-VNVDTrafficRuleAction {
$_.TrafficRule.Action
} ## end foreach-object
} ## end process
} ## end function
} ## end function



function Get-VNVSwitchByVMHostNetworkAdapter {
<# .Description
Get the virtual switch (standard or distributed) with which the given VMHostNetworkAdapter physical NIC is associated, if any.
.Example
Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic2 | Get-VNVSwitchByVMHostNetworkAdapter
Get the vSwitch with which VMNIC2 on myVMHost0.dom.com is associated
.Outputs
Virtual standard- or distributed switch with which given physical VMHost network adapter is associated, if any
#>
[CmdletBinding()]
param(
## The VMHostNetworkAdapter (physical NIC) for which to get the vSwitch
[parameter(Mandatory=$true, ValueFromPipeline=$true)][VMware.VimAutomation.Types.Host.NIC.PhysicalNic[]]$VMHostNetworkAdapter
) ## end param

process {
$VMHostNetworkAdapter | Foreach-Object {
$oThisVMHostNetworkAdapter = $_
if ($oAssociatedVSwitch = $oThisVMHostNetworkAdapter.VMHost.ExtensionData.Config.Network.Vswitch, $oThisVMHostNetworkAdapter.VMHost.ExtensionData.Config.Network.ProxySwitch | Foreach-Object {$_} | Where-Object {$_.Pnic -contains $oThisVMHostNetworkAdapter.Id}) {
switch ($oAssociatedVSwitch) {
## vSS
{$_ -is [VMware.Vim.HostVirtualSwitch]} {
$oThisVMHostNetworkAdapter.VMHost | Get-VirtualSwitch -Standard -Name $oAssociatedVSwitch.Name
break
} ## end case
## vDSwitch
{$_ -is [VMware.Vim.HostProxySwitch]} {
$oThisVMHostNetworkAdapter.VMHost | Get-VDSwitch -Name $oAssociatedVSwitch.DvsName
break
} ## end case
default {Write-Warning "vSwitch not of expected type of either [VMware.Vim.HostVirtualSwitch] or [VMware.Vim.HostProxySwitch]. What kind of vSwitch is it? $_"}
} ## end switch
} ## end if
else {Write-Verbose "No vSwitch associated with VMNIC '$($oThisVMHostNetworkAdapter.Name)' found on VMHost '$($oThisVMHostNetworkAdapter.VMHost.Name)'"}
} ## end Foreach-Object
} ## end process
} ## end fn
Loading

0 comments on commit b5ca669

Please sign in to comment.