Skip to content

Commit

Permalink
Merge pull request #109 from bgelens/bgelens
Browse files Browse the repository at this point in the history
xVMSwitch - Fixes #107 and fixes #108 adds comment based help and updates unit tests to latest template version
  • Loading branch information
bgelens authored Jul 1, 2017
2 parents 2b0e777 + f28be54 commit fbca5c0
Show file tree
Hide file tree
Showing 4 changed files with 585 additions and 307 deletions.
85 changes: 76 additions & 9 deletions DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ Import-Module -Name ( Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath '\HyperVCommon\HyperVCommon.psm1' )

<#
.SYNOPSIS
Gets MSFT_xVMSwitch resource current state.
.PARAMETER Name
Name of the VM Switch.
.PARAMETER Type
Type of switch.
#>
function Get-TargetResource
{
[CmdletBinding()]
Expand Down Expand Up @@ -52,15 +62,23 @@ function Get-TargetResource
if ($null -ne $switch)
{
$ensure = 'Present'
if ($switch.EmbeddedTeamingEnabled -ne $true)
if ($switch.SwitchType -eq 'External')
{
$netAdapterName = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescription -ErrorAction SilentlyContinue).Name
$description = $switch.NetAdapterInterfaceDescription
if ($switch.EmbeddedTeamingEnabled -ne $true)
{
$netAdapterName = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescription -ErrorAction SilentlyContinue).Name
$description = $switch.NetAdapterInterfaceDescription
}
else
{
$netAdapterName = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions).Name
$description = $switch.NetAdapterInterfaceDescriptions
}
}
else
{
$netAdapterName = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions).Name
$description = $switch.NetAdapterInterfaceDescriptions
$netAdapterName = $null
$description = $null
}
}
else
Expand Down Expand Up @@ -91,7 +109,31 @@ function Get-TargetResource
return $returnValue
}

<#
.SYNOPSIS
Configures MSFT_xVMSwitch resource state.
.PARAMETER Name
Name of the VM Switch.
.PARAMETER Type
Type of switch.
.PARAMETER NetAdapterName
Network adapter name(s) for external switch type.
.PARAMETER AllowManagementOS
Specify if the VM host has access to the physical NIC.
.PARAMETER EnableEmbeddedTeaming
Should embedded NIC teaming be used (Windows Server 2016 only).
.PARAMETER BandwidthReservationMode
Type of Bandwidth Reservation Mode to use for the switch.
.PARAMETER Ensure
Whether switch should be present or absent.
#>
function Set-TargetResource
{
[CmdletBinding()]
Expand Down Expand Up @@ -129,13 +171,15 @@ function Set-TargetResource
[String]
$Ensure = "Present"
)

# Check if Hyper-V module is present for Hyper-V cmdlets
if (!(Get-Module -ListAvailable -Name Hyper-V))
{
New-InvalidOperationError `
-ErrorId 'HyperVNotInstalledError' `
-ErrorMessage $LocalizedData.HyperVNotInstalledError
}

# Check to see if the BandwidthReservationMode chosen is supported in the OS
elseif (($BandwidthReservationMode -ne "NA") -and ((Get-OSVersion) -lt [version]'6.2.0'))
{
Expand Down Expand Up @@ -185,8 +229,8 @@ function Set-TargetResource
$removeReaddSwitch = $true
}

if ($null -ne $switch.EmbeddedTeamingEnabled `
-and $switch.EmbeddedTeamingEnabled -ne $EnableEmbeddedTeaming)
if ($null -ne $switch.EmbeddedTeamingEnabled -and
$switch.EmbeddedTeamingEnabled -ne $EnableEmbeddedTeaming)
{
Write-Verbose -Message ($LocalizedData.EnableEmbeddedTeamingIncorrect -f $Name)
$removeReaddSwitch = $true
Expand Down Expand Up @@ -280,7 +324,31 @@ function Set-TargetResource
}
}

<#
.SYNOPSIS
Tests if MSFT_xVMSwitch resource state is in the desired state or not.
.PARAMETER Name
Name of the VM Switch.
.PARAMETER Type
Type of switch.
.PARAMETER NetAdapterName
Network adapter name(s) for external switch type.
.PARAMETER AllowManagementOS
Specify if the VM host has access to the physical NIC.
.PARAMETER EnableEmbeddedTeaming
Should embedded NIC teaming be used (Windows Server 2016 only).
.PARAMETER BandwidthReservationMode
Type of Bandwidth Reservation Mode to use for the switch.
.PARAMETER Ensure
Whether switch should be present or absent.
#>
function Test-TargetResource
{
[CmdletBinding()]
Expand Down Expand Up @@ -320,8 +388,6 @@ function Test-TargetResource
$Ensure = "Present"
)

#region input validation

# Check if Hyper-V module is present for Hyper-V cmdlets
if (!(Get-Module -ListAvailable -Name Hyper-V))
{
Expand All @@ -330,6 +396,7 @@ function Test-TargetResource
-ErrorMessage $LocalizedData.HyperVNotInstalledError
}

#region input validation
if ($Type -eq 'External' -and !($NetAdapterName))
{
New-InvalidArgumentError `
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,19 @@ Please see the Examples section for more details.

### Unreleased

* MSFT_xVMHyperV:
* MSFT_xVMHyperV:
- Increased xVMHyperV StartupMemory and MinimumMemory limits from 17GB to 64GB.
- EnableGuestService works on localized OS (language independent).
- Adds missing Hyper-V-PowerShell feature in examples.
* Added the following resources:
- MSFT_xVMProcessor to manage virtual machine processor options.
- MSFT_xVMHost to managing Hyper-V host settings.
* MSFT_xVMSwitch:
* MSFT_xVMSwitch:
- Added support for Switch Embedded Teaming (SET) in Server 2016.
- Fixed a bug where Get-TargetResource threw an error if a non External switch is used.
- Updated unit tests to use template version 1.2.0.
- Style fixes.
- Added support for Localization.

### 3.8.0.0

Expand Down
Loading

0 comments on commit fbca5c0

Please sign in to comment.