From bfe0989343ed091f9e9eff3d0a5c1ee3747e5614 Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Thu, 12 May 2016 08:52:03 +0530 Subject: [PATCH 01/14] Adding xVMNetworkAdapter resource --- .../MSFT_xVMNetworkAdapter.psm1 | 300 ++++++++++++++++++ .../MSFT_xVMNetworkAdapter.schema.mof | 11 + .../en-US/MSFT_xVMNetworkAdapter.psd1 | 21 ++ .../Sample_xVMNetworkAdapter_ManagementOS.ps1 | 31 ++ ..._xVMNetworkAdapter_VM-StaticMacAddress.ps1 | 39 +++ Examples/Sample_xVMNetworkAdapter_VM.ps1 | 34 ++ README.md | 14 + .../MSFT_xVMNetworkAdapter.Tests.ps1 | 192 +++++++++++ 8 files changed, 642 insertions(+) create mode 100644 DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 create mode 100644 DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof create mode 100644 DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 create mode 100644 Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 create mode 100644 Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 create mode 100644 Examples/Sample_xVMNetworkAdapter_VM.ps1 create mode 100644 Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 new file mode 100644 index 0000000..c510e20 --- /dev/null +++ b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 @@ -0,0 +1,300 @@ +Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xVMNetworkAdapter.psd1 -BaseDirectory $PSScriptRoot -Verbose + +Function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + Param ( + [Parameter(Mandatory)] + [String] $Id, + + [Parameter(Mandatory)] + [String] $Name, + + [Parameter(Mandatory)] + [String] $SwitchName, + + [Parameter(Mandatory)] + [String] $VMName + ) + + $configuration = @{ + Id = $Id + Name = $Name + SwitchName = $SwitchName + VMName = $VMName + } + + $arguments = @{ + Name = $Name + } + + if ($VMName -ne 'Management OS') + { + $arguments.Add('VMName',$VMName) + } + else + { + $arguments.Add('ManagementOS', $true) + $arguments.Add('SwitchName', $SwitchName) + } + + Write-Verbose $localizedData.GetVMNetAdapter + $netAdapter = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue + + if ($netAdapter) + { + Write-Verbose -Message $localizedData.FoundVMNetAdapter + if ($VMName -eq 'Management OS') + { + $configuration.Add('StaticMacAddress', $NetAdapter.MacAddress) + } + elseif ($NetAdapter.VMName) + { + $configuration.Add('StaticMacAddress', $NetAdapter.MacAddress) + $configuration.Add('DynamicMacAddress', $NetAdapter.DynamicMacAddressEnabled) + } + $configuration.Add('Ensure','Present') + } + else + { + Write-Verbose -Message $localizedData.NoVMNetAdapterFound + $configuration.Add('Ensure','Absent') + } + + $configuration +} + +Function Set-TargetResource +{ + [CmdletBinding()] + Param ( + [Parameter(Mandatory)] + [String] $Id, + + [Parameter(Mandatory)] + [String] $Name, + + [Parameter(Mandatory)] + [String] $SwitchName, + + [Parameter(Mandatory)] + [String] $VMName, + + [Parameter()] + [Bool] $DynamicMacAddress, + + [Parameter()] + [String] $StaticMacAddress, + + [Parameter()] + [ValidateSet('Present','Absent')] + [String] $Ensure='Present' + ) + + if ($DynamicMacAddress -and $StaticMacAddress) + { + throw $localizedData.StaticAndDynamicTogether + } + + $arguments = @{ + Name = $Name + } + + if ($VMName -ne 'Management OS') + { + $arguments.Add('VMName',$VMName) + } + else + { + $arguments.Add('ManagementOS', $true) + $arguments.Add('SwitchName', $SwitchName) + } + + Write-Verbose -Message $localizedData.GetVMNetAdapter + $netAdapterExists = Get-VMNetworkAdapter @Arguments -ErrorAction SilentlyContinue + + if ($Ensure -eq 'Present') + { + if ($netAdapterExists) + { + Write-Verbose -Message $localizedData.FoundVMNetAdapter + if (($VMName -ne 'Management OS')) + { + Write-Verbose -Message $localizedData.ModifyVMNetAdapter + $setArguments = @{ + VMNetworkAdapter = $NetAdapterExists + } + + if ($DynamicMacAddress) + { + if (-not $NetAdapterExists.DynamicMacAddressEnabled) + { + Write-Verbose -Message $localizedData.EnableDynamicMacAddress + $setArguments.Add('DynamicMacAddress',$true) + } + } elseif ($StaticMacAddress) { + if ($StaticMacAddress -ne $NetAdapterExists.MacAddress) + { + Write-Verbose -Message $localizedData.EnableStaticMacAddress + $setArguments.Add('StaticMacAddress', $StaticMacAddress) + } + } + elseif ($NetAdapterExists.SwitchName -ne $SwitchName) + { + Write-Verbose -Message $localizedData.PerformSwitchConnect + Connect-VMNetworkAdapter -VMNetworkAdapter $netAdapterExists -SwitchName $SwitchName -ErrorAction Stop -Verbose + } + + Write-Verbose -Message $localizedData.PerformVMNetModify + Set-VMNetworkAdapter @setArguments -ErrorAction Stop + } + else + { + Write-Verbose $localizedData.CannotChangeHostAdapterMacAddress + } + } + else + { + if ($VMName -ne 'Management OS') + { + if ($DynamicMacAddress) + { + $arguments.Add('DynamicMacAddress',$true) + } + elseif ($StaticMacAddress) + { + $arguments.Add('StaticMacAddress',$StaticMacAddress) + } + $arguments.Add('SwitchName',$SwitchName) + } + Write-Verbose -Message $localizedData.AddVMNetAdapter + Add-VMNetworkAdapter @arguments -ErrorAction Stop + } + } + else + { + Write-Verbose -Message $localizedData.RemoveVMNetAdapter + Remove-VMNetworkAdapter @arguments -ErrorAction Stop + } +} + +Function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + Param ( + [Parameter(Mandatory)] + [String] $Id, + + [Parameter(Mandatory)] + [String] $Name, + + [Parameter(Mandatory)] + [String] $SwitchName, + + [Parameter(Mandatory)] + [String] $VMName, + + [Parameter()] + [Bool] $DynamicMacAddress, + + [Parameter()] + [String] $StaticMacAddress, + + [Parameter()] + [ValidateSet('Present','Absent')] + [String] $Ensure='Present' + ) + + if ($DynamicMacAddress -and $StaticMacAddress) + { + throw $localizedData.StaticAndDynamicTogether + } + + $arguments = @{ + Name = $Name + } + + if ($VMName -ne 'Management OS') + { + $arguments.Add('VMName',$VMName) + } + else + { + $arguments.Add('ManagementOS', $true) + $arguments.Add('SwitchName', $SwitchName) + } + + Write-Verbose -Message $localizedData.GetVMNetAdapter + $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue + + if ($Ensure -eq 'Present') + { + if ($netAdapterExists) + { + if ($VMName -ne 'Management OS') + { + if ($DynamicMacAddress) + { + if ($netAdapterExists.DynamicMacAddressEnabled) + { + Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + return $true + } + else + { + Write-Verbose -Message $localizedData.EnableDynamicMacAddress + return $false + } + } + elseif ($StaticMacAddress) + { + if ($netAdapterExists.MacAddress -eq $StaticMacAddress) + { + Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + return $true + } + else + { + Write-Verbose -Message $localizedData.EnableStaticMacAddress + return $false + } + } + elseif ($netAdapterExists.SwitchName -ne $SwitchName) + { + Write-Verbose -Message $localizedData.SwitchIsDifferent + return $false + } + else + { + Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + return $true + } + } + else + { + Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + return $true + } + } + else + { + Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistShouldAdd + return $false + } + } + else + { + if ($netAdapterExists) + { + Write-Verbose -Message $localizedData.VMNetAdapterExistsShouldRemove + return $false + } + else + { + Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistNoActionNeeded + return $true + } + } +} diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof new file mode 100644 index 0000000..7fddaff --- /dev/null +++ b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof @@ -0,0 +1,11 @@ +[ClassVersion("1.3"), FriendlyName("xVMNetworkAdapter")] +class MSFT_xVMNetworkAdapter : OMI_BaseResource +{ + [Key] String Id; + [Required] String Name; + [Required] String SwitchName; + [Required] String VMName; + [Write] Boolean DynamicMacAddress; + [Write] String StaticMacAddress; + [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; +}; diff --git a/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 b/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 new file mode 100644 index 0000000..c4eb692 --- /dev/null +++ b/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 @@ -0,0 +1,21 @@ +ConvertFrom-StringData @' + VMNameAndManagementTogether=VMName cannot be provided when ManagementOS is set to True. + MustProvideVMName=Must provide VMName parameter when ManagementOS is set to False. + GetVMNetAdapter=Getting VM Network Adapter information. + FoundVMNetAdapter=Found VM Network Adapter. + NoVMNetAdapterFound=No VM Network Adapter found. + StaticAndDynamicTogether=StaticMacAddress and DynamicMacAddress parameters cannot be provided together. + ModifyVMNetAdapter=VM Network Adapter exists with different configuration. This will be modified. + EnableDynamicMacAddress=VM Network Adapter exists but without Dynamic MAC address setting. + EnableStaticMacAddress=VM Network Adapter exists but without static MAC address setting. + PerformVMNetModify=Performing VM Network Adapter configuration changes. + CannotChangeHostAdapterMacAddress=VM Network adapter in configuration is a host adapter. Its configuration cannot be modified. + AddVMNetAdapter=Adding VM Network Adapter. + RemoveVMNetAdapter=Removing VM Network Adapter. + VMNetAdapterExistsNoActionNeeded=VM Network Adapter exists with requested configuration. No action needed. + VMNetAdapterDoesNotExistShouldAdd=VM Network Adapter does not exist. It will be added. + VMNetAdapterExistsShouldRemove=VM Network Adapter Exists. It will be removed. + VMNetAdapterDoesNotExistNoActionNeeded=VM Network adapter does not exist. No action needed. + SwitchIsDifferent=Net Adapter is not connected to the requested switch. + PerformSwitchConnect=Connecting VM Net adapter to the right switch. +'@ diff --git a/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 b/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 new file mode 100644 index 0000000..729cf04 --- /dev/null +++ b/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 @@ -0,0 +1,31 @@ +configuration Sample_xVMNetworkAdapter_ManagementOS +{ + param + ( + [string[]]$NodeName = 'localhost', + + [Parameter(Mandatory)] + [string]$Id, + + [Parameter(Mandatory)] + [string]$Name, + + [Parameter(Mandatory)] + [string]$SwitchName + ) + + Import-DscResource -module xHyper-V + + Node $NodeName + { + # Ensures a VM network adapter is attached to the management OS + xVMNetworkAdapter ManagementAdapter + { + Ensure = 'Present' + Id = $Id + Name = $Name + SwitchName = $SwitchName + VMName = 'Management OS' + } + } +} diff --git a/Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 b/Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 new file mode 100644 index 0000000..7bd8ae3 --- /dev/null +++ b/Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 @@ -0,0 +1,39 @@ +configuration Sample_xVMNetworkAdapter_VM-StaticMacAddress +{ + param + ( + [string[]]$NodeName = 'localhost', + + [Parameter(Mandatory)] + [string]$Id, + + [Parameter(Mandatory)] + [string]$Name, + + [Parameter(Mandatory)] + [string]$SwitchName, + + [Parameter(Mandatory)] + [string]$VMName, + + [Parameter(Mandatory)] + [string]$StaticMacAddress + ) + + Import-DscResource -module xHyper-V + + Node $NodeName + { + # Ensures a VM network adapter is attached to a VM + xVMNetworkAdapter ManagementAdapter + { + Ensure = 'Present' + Id = $Id + Name = $Name + SwitchName = $SwitchName + VMName = $VMName + DynamicMacAddress = $false + StaticMacAddress = $StaticMacAddress + } + } +} diff --git a/Examples/Sample_xVMNetworkAdapter_VM.ps1 b/Examples/Sample_xVMNetworkAdapter_VM.ps1 new file mode 100644 index 0000000..acac04d --- /dev/null +++ b/Examples/Sample_xVMNetworkAdapter_VM.ps1 @@ -0,0 +1,34 @@ +configuration Sample_xVMNetworkAdapter_VM +{ + param + ( + [string[]]$NodeName = 'localhost', + + [Parameter(Mandatory)] + [string]$Id, + + [Parameter(Mandatory)] + [string]$Name, + + [Parameter(Mandatory)] + [string]$SwitchName, + + [Parameter(Mandatory)] + [string]$VMName + ) + + Import-DscResource -module xHyper-V + + Node $NodeName + { + # Ensures a VM network adapter is attached to a VM + xVMNetworkAdapter ManagementAdapter + { + Ensure = 'Present' + Id = $Id + Name = $Name + SwitchName = $SwitchName + VMName = $VMName + } + } +} diff --git a/README.md b/README.md index f23614a..9289830 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,23 @@ The following xVMHyper-V properties **cannot** be changed after VM creation: * **FileDirectory**: The FileDirectory objects to copy to the VHD (as used in the "File" resource). Please see the Examples section for more details. +### xVMNetworkAdapter + +* **Id**: Unique string for identifying the resource instance. +* **Name**: Name of the network adapter as it appears either in the management OS or attached to a VM. +* **SwitchName**: Virtual Switch name to connect the adapter to. +* **VMName**: Name of the VM to attach to. If you want to attach new VM Network adapter to the management OS, set this property to 'Management OS'. +* **DynamicMacAddress**: Set this to $false if you want to specify a static MAC address. +* **StaticMacAddress**: Specifies static MAC address for the Network adapter. +* **Ensure**: Ensures that the VM Network Adapter is Present or Absent. +* +Please see the Examples section for more details. + ## Versions ### Unreleased +* Adding a new resource + * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management OS or VM. ### 3.4.0.0 diff --git a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 new file mode 100644 index 0000000..c310adf --- /dev/null +++ b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 @@ -0,0 +1,192 @@ +$Global:DSCModuleName = 'xHyper-V' +$Global:DSCResourceName = 'MSFT_xVMNetworkAdapter' + +#region HEADER +if ( (-not (Test-Path -Path '.\DSCResource.Tests\')) -or ` + (-not (Test-Path -Path '.\DSCResource.Tests\TestHelper.psm1')) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git') +} +else +{ + & git @('-C',(Join-Path -Path (Get-Location) -ChildPath '\DSCResource.Tests\'),'pull') +} +Import-Module .\DSCResource.Tests\TestHelper.psm1 -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $Global:DSCModuleName ` + -DSCResourceName $Global:DSCResourceName ` + -TestType Unit +#endregion + +# Begin Testing +try +{ + #region Pester Tests + InModuleScope $Global:DSCResourceName { + # Create the Mock Objects that will be used for running tests + $MockHostAdapter = [PSCustomObject] @{ + Id = 'HostManagement1' + Name = 'Management' + SwitchName = 'HostSwitch' + VMName = 'Management OS' + } + + $TestAdapter = [PSObject]@{ + Id = $MockHostAdapter.Id + Name = $MockHostAdapter.Name + SwitchName = $MockHostAdapter.SwitchName + VMName = $MockHostAdapter.VMName + } + + $MockAdapter = [PSObject]@{ + Name = $TestAdapter.Name + SwitchName = $MockHostAdapter.SwitchName + IsManagementOs = $True + MacAddress = '14FEB5C6CE98' + } + + Describe "$($Global:DSCResourceName)\Get-TargetResource" { + + Context 'NetAdapter does not exist' { + Mock Get-VMNetworkAdapter + It 'should return ensure as absent' { + $Result = Get-TargetResource ` + @TestAdapter + $Result.Ensure | Should Be 'Absent' + } + It 'should call the expected mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + } + } + + Context 'NetAdapter exists' { + Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } + It 'should return adapter properties' { + $Result = Get-TargetResource @TestAdapter + $Result.Ensure | Should Be 'Present' + $Result.Name | Should Be $TestAdapter.Name + $Result.SwitchName | Should Be $TestAdapter.SwitchName + $Result.VMName | Should Be 'Management OS' + $Result.Id | Should Be $TestAdapter.Id + } + It 'should call the expected mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + } + } + } + + Describe "$($Global:DSCResourceName)\Set-TargetResource" { + $newAdapter = [PSObject]@{ + Id = 'UniqueString' + Name = $TestAdapter.Name + SwitchName = $TestAdapter.SwitchName + VMName = 'Management OS' + Ensure = 'Present' + } + + Context 'Adapter does not exist but should' { + + Mock Get-VMNetworkAdapter + Mock Add-VMNetworkAdapter + Mock Remove-VMNetworkAdapter + + It 'should not throw error' { + { + Set-TargetResource @newAdapter + } | Should Not Throw + } + It 'should call expected Mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + Assert-MockCalled -commandName Add-VMNetworkAdapter -Exactly 1 + Assert-MockCalled -commandName Remove-VMNetworkAdapter -Exactly 0 + } + } + + Context 'Adapter exists but should not exist' { + Mock Get-VMNetworkAdapter + Mock Add-VMNetworkAdapter + Mock Remove-VMNetworkAdapter + + It 'should not throw error' { + { + $updateAdapter = $newAdapter.Clone() + $updateAdapter.Ensure = 'Absent' + Set-TargetResource @updateAdapter + } | Should Not Throw + } + It 'should call expected Mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + Assert-MockCalled -commandName Add-VMNetworkAdapter -Exactly 0 + Assert-MockCalled -commandName Remove-VMNetworkAdapter -Exactly 1 + } + } + } + + Describe "$($Global:DSCResourceName)\Test-TargetResource" { + $newAdapter = [PSObject]@{ + Id = 'UniqueString' + Name = $TestAdapter.Name + SwitchName = $TestAdapter.SwitchName + VMName = 'Management OS' + Ensure = 'Present' + } + + Context 'Adapter does not exist but should' { + Mock Get-VMNetworkAdapter + + It 'should return false' { + Test-TargetResource @newAdapter | Should be $false + } + It 'should call expected Mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + } + } + + Context 'Adapter exists but should not exist' { + Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } + + It 'should return $false' { + $updateAdapter = $newAdapter.Clone() + $updateAdapter.Ensure = 'Absent' + Test-TargetResource @updateAdapter | Should Be $false + } + It 'should call expected Mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + } + } + + Context 'Adapter exists and no action needed' { + Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } + + It 'should return true' { + $updateAdapter = $newAdapter.Clone() + Test-TargetResource @updateAdapter | Should Be $true + } + It 'should call expected Mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + } + } + + Context 'Adapter does not and no action needed' { + Mock Get-VMNetworkAdapter + + It 'should return true' { + $updateAdapter = $newAdapter.Clone() + $updateAdapter.Ensure = 'Absent' + Test-TargetResource @updateAdapter | Should Be $true + } + It 'should call expected Mocks' { + Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 + } + } + } + + } + #endregion +} +finally +{ + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +} From f36dc6c53a57f70f6edcf3e27e22514b273555c7 Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Thu, 12 May 2016 09:05:19 +0530 Subject: [PATCH 02/14] fix tests --- .../MSFT_xVMNetworkAdapter.Tests.ps1 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 index c310adf..870a0ef 100644 --- a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 +++ b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 @@ -46,6 +46,13 @@ try } Describe "$($Global:DSCResourceName)\Get-TargetResource" { + function Get-VMNetworkAdapter { + [CmdletBinding()] + Param( + [string]$Name, + [string]$SwitchType + ) + } Context 'NetAdapter does not exist' { Mock Get-VMNetworkAdapter @@ -60,7 +67,10 @@ try } Context 'NetAdapter exists' { - Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMSwitch -MockWith { + return $MockAdapter + } + It 'should return adapter properties' { $Result = Get-TargetResource @TestAdapter $Result.Ensure | Should Be 'Present' From bdbcf1ab8bebe616e5d2a8b948624cdc2d785f9d Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Thu, 12 May 2016 09:11:28 +0530 Subject: [PATCH 03/14] some more fixes! --- .../MSFT_xVMNetworkAdapter.Tests.ps1 | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 index 870a0ef..d74d667 100644 --- a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 +++ b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 @@ -23,6 +23,13 @@ try { #region Pester Tests InModuleScope $Global:DSCResourceName { + + #Function placeholders + function Get-VMNetworkAdapter { } + function Set-VMNetworkAdapter { } + function Remove-VMNetworkAdapter { } + function Add-VMNetworkAdapter { } + # Create the Mock Objects that will be used for running tests $MockHostAdapter = [PSCustomObject] @{ Id = 'HostManagement1' @@ -46,14 +53,6 @@ try } Describe "$($Global:DSCResourceName)\Get-TargetResource" { - function Get-VMNetworkAdapter { - [CmdletBinding()] - Param( - [string]$Name, - [string]$SwitchType - ) - } - Context 'NetAdapter does not exist' { Mock Get-VMNetworkAdapter It 'should return ensure as absent' { @@ -67,8 +66,8 @@ try } Context 'NetAdapter exists' { - Mock -CommandName Get-VMSwitch -MockWith { - return $MockAdapter + Mock -CommandName Get-VMNetworkAdapter -MockWith { + $MockAdapter } It 'should return adapter properties' { From d6708d15c5d802f5fa1723bed99984afc76d965b Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Thu, 12 May 2016 10:18:05 +0530 Subject: [PATCH 04/14] Update to mocks --- .../MSFT_xVMNetworkAdapter.Tests.ps1 | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 index d74d667..a07cbf2 100644 --- a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 +++ b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 @@ -24,12 +24,6 @@ try #region Pester Tests InModuleScope $Global:DSCResourceName { - #Function placeholders - function Get-VMNetworkAdapter { } - function Set-VMNetworkAdapter { } - function Remove-VMNetworkAdapter { } - function Add-VMNetworkAdapter { } - # Create the Mock Objects that will be used for running tests $MockHostAdapter = [PSCustomObject] @{ Id = 'HostManagement1' @@ -53,6 +47,11 @@ try } Describe "$($Global:DSCResourceName)\Get-TargetResource" { + #Function placeholders + function Get-VMNetworkAdapter { } + function Set-VMNetworkAdapter { } + function Remove-VMNetworkAdapter { } + function Add-VMNetworkAdapter { } Context 'NetAdapter does not exist' { Mock Get-VMNetworkAdapter It 'should return ensure as absent' { @@ -85,6 +84,11 @@ try } Describe "$($Global:DSCResourceName)\Set-TargetResource" { + #Function placeholders + function Get-VMNetworkAdapter { } + function Set-VMNetworkAdapter { } + function Remove-VMNetworkAdapter { } + function Add-VMNetworkAdapter { } $newAdapter = [PSObject]@{ Id = 'UniqueString' Name = $TestAdapter.Name @@ -132,6 +136,11 @@ try } Describe "$($Global:DSCResourceName)\Test-TargetResource" { + #Function placeholders + function Get-VMNetworkAdapter { } + function Set-VMNetworkAdapter { } + function Remove-VMNetworkAdapter { } + function Add-VMNetworkAdapter { } $newAdapter = [PSObject]@{ Id = 'UniqueString' Name = $TestAdapter.Name From 62c8493db804559a7f8385f2b407c87fea965f6d Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Fri, 28 Oct 2016 16:05:50 +0530 Subject: [PATCH 05/14] Updating xVMNetworkAdapter - This closes the review comments from PR #53 --- .../MSFT_xVMNetworkAdapter.psm1 | 186 +++++++++--------- .../MSFT_xVMNetworkAdapter.schema.mof | Bin 384 -> 744 bytes .../en-US/MSFT_xVMNetworkAdapter.psd1 | 4 +- .../Sample_xVMNetworkAdapter_ManagementOS.ps1 | 38 +--- ...xVMNetworkAdapter_MultipleManagementOS.ps1 | 21 ++ .../Sample_xVMNetworkAdapter_MultipleVM.ps1 | 29 +++ ...xVMNetworkAdapter_MultipleVMMACAddress.ps1 | 23 +++ ..._xVMNetworkAdapter_VM-StaticMacAddress.ps1 | 39 ---- Examples/Sample_xVMNetworkAdapter_VM.ps1 | 34 ---- .../MSFT_xVMNetworkAdapter.Tests.ps1 | 12 +- 10 files changed, 189 insertions(+), 197 deletions(-) create mode 100644 Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 create mode 100644 Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 create mode 100644 Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 delete mode 100644 Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 delete mode 100644 Examples/Sample_xVMNetworkAdapter_VM.ps1 diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 index c510e20..70e70e2 100644 --- a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 +++ b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 @@ -1,4 +1,16 @@ -Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xVMNetworkAdapter.psd1 -BaseDirectory $PSScriptRoot -Verbose +#region localizeddata +if (Test-Path "${PSScriptRoot}\${PSUICulture}") +{ + Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xVMNetworkAdapter.psd1 ` + -BaseDirectory "${PSScriptRoot}\${PSUICulture}" +} +else +{ + #fallback to en-US + Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xVMNetworkAdapter.psd1 ` + -BaseDirectory "${PSScriptRoot}\en-US" +} +#endregion Function Get-TargetResource { @@ -6,7 +18,7 @@ Function Get-TargetResource [OutputType([System.Collections.Hashtable])] Param ( [Parameter(Mandatory)] - [String] $Id, + [String] $Id, [Parameter(Mandatory)] [String] $Name, @@ -29,7 +41,7 @@ Function Get-TargetResource Name = $Name } - if ($VMName -ne 'Management OS') + if ($VMName -ne 'ManagementOS') { $arguments.Add('VMName',$VMName) } @@ -39,30 +51,31 @@ Function Get-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose $localizedData.GetVMNetAdapter + Write-Verbose -Message $localizedData.GetVMNetAdapter $netAdapter = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($netAdapter) { - Write-Verbose -Message $localizedData.FoundVMNetAdapter - if ($VMName -eq 'Management OS') + Write-Verbose $localizedData.FoundVMNetAdapter + if ($VMName -eq 'ManagementOS') { - $configuration.Add('StaticMacAddress', $NetAdapter.MacAddress) + $configuration.Add('MacAddress', $netAdapter.MacAddress) + $configuration.Add('DynamicMacAddress', $false) } - elseif ($NetAdapter.VMName) + elseif ($netAdapter.VMName) { - $configuration.Add('StaticMacAddress', $NetAdapter.MacAddress) - $configuration.Add('DynamicMacAddress', $NetAdapter.DynamicMacAddressEnabled) + $configuration.Add('MacAddress', $netAdapter.MacAddress) + $configuration.Add('DynamicMacAddress', $netAdapter.DynamicMacAddressEnabled) } $configuration.Add('Ensure','Present') } - else + else { Write-Verbose -Message $localizedData.NoVMNetAdapterFound $configuration.Add('Ensure','Absent') } - $configuration + return $configuration } Function Set-TargetResource @@ -70,8 +83,8 @@ Function Set-TargetResource [CmdletBinding()] Param ( [Parameter(Mandatory)] - [String] $Id, - + [String] $Id, + [Parameter(Mandatory)] [String] $Name, @@ -82,26 +95,18 @@ Function Set-TargetResource [String] $VMName, [Parameter()] - [Bool] $DynamicMacAddress, - - [Parameter()] - [String] $StaticMacAddress, + [String] $MacAddress, [Parameter()] [ValidateSet('Present','Absent')] [String] $Ensure='Present' ) - if ($DynamicMacAddress -and $StaticMacAddress) - { - throw $localizedData.StaticAndDynamicTogether - } - $arguments = @{ Name = $Name } - if ($VMName -ne 'Management OS') + if ($VMName -ne 'ManagementOS') { $arguments.Add('VMName',$VMName) } @@ -111,70 +116,83 @@ Function Set-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose -Message $localizedData.GetVMNetAdapter - $netAdapterExists = Get-VMNetworkAdapter @Arguments -ErrorAction SilentlyContinue + Write-Verbose $localizedData.GetVMNetAdapter + $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($Ensure -eq 'Present') { if ($netAdapterExists) { - Write-Verbose -Message $localizedData.FoundVMNetAdapter - if (($VMName -ne 'Management OS')) + Write-Verbose $localizedData.FoundVMNetAdapter + if (($VMName -ne 'ManagementOS')) { - Write-Verbose -Message $localizedData.ModifyVMNetAdapter - $setArguments = @{ - VMNetworkAdapter = $NetAdapterExists - } - - if ($DynamicMacAddress) + if ($MacAddress) { - if (-not $NetAdapterExists.DynamicMacAddressEnabled) + if ($netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose -Message $localizedData.EnableDynamicMacAddress - $setArguments.Add('DynamicMacAddress',$true) + Write-Verbose -Message $localizedData.EnableStaticMacAddress + $updateMacAddress = $true } - } elseif ($StaticMacAddress) { - if ($StaticMacAddress -ne $NetAdapterExists.MacAddress) + elseif ($MacAddress -ne $netAdapterExists.StaicMacAddress) { Write-Verbose -Message $localizedData.EnableStaticMacAddress - $setArguments.Add('StaticMacAddress', $StaticMacAddress) + $updateMacAddress = $true + } + } + else + { + if (-not $netAdapterExists.DynamicMacAddressEnabled) + { + Write-Verbose $localizedData.EnableDynamicMacAddress + $updateMacAddress = $true } } - elseif ($NetAdapterExists.SwitchName -ne $SwitchName) + + if ($netAdapterExists.SwitchName -ne $SwitchName) { - Write-Verbose -Message $localizedData.PerformSwitchConnect + Write-Verbose $localizedData.PerformSwitchConnect Connect-VMNetworkAdapter -VMNetworkAdapter $netAdapterExists -SwitchName $SwitchName -ErrorAction Stop -Verbose } - Write-Verbose -Message $localizedData.PerformVMNetModify - Set-VMNetworkAdapter @setArguments -ErrorAction Stop - } - else - { - Write-Verbose $localizedData.CannotChangeHostAdapterMacAddress + if (($updateMacAddress)) + { + Write-Verbose $localizedData.PerformVMNetModify + + $setArguments = @{ } + $setArguments.Add('VMNetworkAdapter',$netAdapterExists) + if ($MacAddress) + { + $setArguments.Add('StaticMacAddress',$MacAddress) + } + else + { + $setArguments.Add('DynamicMacAddress', $true) + } + Set-VMNetworkAdapter @setArguments -ErrorAction Stop + } } } else { - if ($VMName -ne 'Management OS') + if ($VMName -ne 'ManagementOS') { - if ($DynamicMacAddress) + if (-not $MacAddress) { $arguments.Add('DynamicMacAddress',$true) } - elseif ($StaticMacAddress) + else { - $arguments.Add('StaticMacAddress',$StaticMacAddress) + $arguments.Add('StaticMacAddress',$MacAddress) } $arguments.Add('SwitchName',$SwitchName) } - Write-Verbose -Message $localizedData.AddVMNetAdapter + Write-Verbose $localizedData.AddVMNetAdapter Add-VMNetworkAdapter @arguments -ErrorAction Stop } } else { - Write-Verbose -Message $localizedData.RemoveVMNetAdapter + Write-Verbose $localizedData.RemoveVMNetAdapter Remove-VMNetworkAdapter @arguments -ErrorAction Stop } } @@ -185,7 +203,7 @@ Function Test-TargetResource [OutputType([System.Boolean])] Param ( [Parameter(Mandatory)] - [String] $Id, + [String] $Id, [Parameter(Mandatory)] [String] $Name, @@ -197,26 +215,18 @@ Function Test-TargetResource [String] $VMName, [Parameter()] - [Bool] $DynamicMacAddress, - - [Parameter()] - [String] $StaticMacAddress, + [String] $MacAddress, [Parameter()] [ValidateSet('Present','Absent')] [String] $Ensure='Present' ) - if ($DynamicMacAddress -and $StaticMacAddress) - { - throw $localizedData.StaticAndDynamicTogether - } - $arguments = @{ Name = $Name } - if ($VMName -ne 'Management OS') + if ($VMName -ne 'ManagementOS') { $arguments.Add('VMName',$VMName) } @@ -226,61 +236,57 @@ Function Test-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose -Message $localizedData.GetVMNetAdapter + Write-Verbose $localizedData.GetVMNetAdapter $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($Ensure -eq 'Present') { if ($netAdapterExists) { - if ($VMName -ne 'Management OS') + if ($VMName -ne 'ManagementOS') { - if ($DynamicMacAddress) + if ($MacAddress) { if ($netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded - return $true + Write-Verbose $localizedData.EnableStaticMacAddress + return $false } - else + elseif ($netAdapterExists.MacAddress -ne $MacAddress) { - Write-Verbose -Message $localizedData.EnableDynamicMacAddress + Write-Verbose $localizedData.StaticAddressDoesNotMatch return $false } } - elseif ($StaticMacAddress) + else { - if ($netAdapterExists.MacAddress -eq $StaticMacAddress) - { - Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded - return $true - } - else + if (-not $netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose -Message $localizedData.EnableStaticMacAddress + Write-Verbose $localizedData.EnableDynamicMacAddress return $false } - } - elseif ($netAdapterExists.SwitchName -ne $SwitchName) + } + + if ($netAdapterExists.SwitchName -ne $SwitchName) { - Write-Verbose -Message $localizedData.SwitchIsDifferent + Write-Verbose $localizedData.SwitchIsDifferent return $false } else { - Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + Write-Verbose $localizedData.VMNetAdapterExistsNoActionNeeded return $true } } else { - Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + Write-Verbose $localizedData.VMNetAdapterExistsNoActionNeeded return $true } - } + } else { - Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistShouldAdd + Write-Verbose $localizedData.VMNetAdapterDoesNotExistShouldAdd return $false } } @@ -288,13 +294,15 @@ Function Test-TargetResource { if ($netAdapterExists) { - Write-Verbose -Message $localizedData.VMNetAdapterExistsShouldRemove + Write-Verbose $localizedData.VMNetAdapterExistsShouldRemove return $false } else { - Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistNoActionNeeded + Write-Verbose $localizedData.VMNetAdapterDoesNotExistNoActionNeeded return $true } } } + +Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof index 7fddaff1ce713dd7deb9c6deff75fc1073afbc33..c8be918e3c14636743f5e210d30409c76f265034 100644 GIT binary patch literal 744 zcmb7?O-lk%6o%hzLH}WJRUi>9Yo&dFgcTXKkcjDesUf|VGf^V`_3AlS9fNV93^UF> zp7-ONcYc5Nw5y)ZG*GIXt1GWDznMk~+E-1-I@D2l*L0w|5?#`j(HqnUJJB`xA!kE; z!_ubWRp<+zvEJ06FV#C0<2RN^nYJsH6EGck@Ab3+L!uL0+<MFKaeTm#(c$^0+P|E28%&2yWT-m5mb=;pKi}wl z$1B`JoWgcmb=hVoF7CY_C$V(bAuY`=y#r?U?9)=3lF;n}Wf>Qo>)Z`J!?LW*;+L?( s<{RUxZZA;DV{ZPROUoi%WY8qn5iYF~@O(~|f%hSMbi_@% literal 384 zcmaKnL2Cj*42AFeE5e)HWwu?Pfn^Va5 zUS6_#s8FOJ78iU^-QNvVKZOZ9^0sQ`xTBu>EcBe>A@DY{xR1oDUnb`41D#J^)_*t* zVWFq%F$yh7Ld}MfV*+ihX4I6BM|S=lrgro*T+&DFnCyj|b8oTy;G)_5r)bap^}n)< zRKhrfiqOMj<8kMVMw3~~B+|unvhK1xV!S0vp}?vpjr*f|Za0vRDplFrcXR5fTw|B_ Mp1joDK6n}>UlGxN-2eap diff --git a/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 b/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 index c4eb692..c60f3ff 100644 --- a/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 +++ b/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 @@ -4,7 +4,8 @@ ConvertFrom-StringData @' GetVMNetAdapter=Getting VM Network Adapter information. FoundVMNetAdapter=Found VM Network Adapter. NoVMNetAdapterFound=No VM Network Adapter found. - StaticAndDynamicTogether=StaticMacAddress and DynamicMacAddress parameters cannot be provided together. + StaticMacAddressChosen=Static MAC Address has been specified. + StaticAddressDoesNotMatch=Staic MAC address on the VM Network Adapter does not match. ModifyVMNetAdapter=VM Network Adapter exists with different configuration. This will be modified. EnableDynamicMacAddress=VM Network Adapter exists but without Dynamic MAC address setting. EnableStaticMacAddress=VM Network Adapter exists but without static MAC address setting. @@ -16,6 +17,7 @@ ConvertFrom-StringData @' VMNetAdapterDoesNotExistShouldAdd=VM Network Adapter does not exist. It will be added. VMNetAdapterExistsShouldRemove=VM Network Adapter Exists. It will be removed. VMNetAdapterDoesNotExistNoActionNeeded=VM Network adapter does not exist. No action needed. + StaticMacExists=StaicMacAddress configuration exists as desired. SwitchIsDifferent=Net Adapter is not connected to the requested switch. PerformSwitchConnect=Connecting VM Net adapter to the right switch. '@ diff --git a/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 b/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 index 729cf04..d939de4 100644 --- a/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 +++ b/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 @@ -1,31 +1,13 @@ -configuration Sample_xVMNetworkAdapter_ManagementOS +Configuration HostOSAdapter { - param - ( - [string[]]$NodeName = 'localhost', - - [Parameter(Mandatory)] - [string]$Id, - - [Parameter(Mandatory)] - [string]$Name, - - [Parameter(Mandatory)] - [string]$SwitchName - ) - - Import-DscResource -module xHyper-V - - Node $NodeName - { - # Ensures a VM network adapter is attached to the management OS - xVMNetworkAdapter ManagementAdapter - { - Ensure = 'Present' - Id = $Id - Name = $Name - SwitchName = $SwitchName - VMName = 'Management OS' - } + Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + cVMNetworkAdapter HostOSAdapter { + Id = 'Management-NIC' + Name = 'Management-NIC' + SwitchName = 'SETSwitch' + VMName = 'ManagementOS' + Ensure = 'Present' } } diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 b/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 new file mode 100644 index 0000000..bf031b5 --- /dev/null +++ b/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 @@ -0,0 +1,21 @@ +Configuration HostOSAdapter +{ + Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + cVMNetworkAdapter ManagementAdapter { + Id = 'Management-NIC' + Name = 'Management-NIC' + SwitchName = 'SETSwitch' + VMName = 'ManagementOS' + Ensure = 'Present' + } + + cVMNetworkAdapter ClusterAdapter { + Id = 'Cluster-NIC' + Name = 'Cluster-NIC' + SwitchName = 'SETSwitch' + VMName = 'ManagementOS' + Ensure = 'Present' + } +} diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 b/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 new file mode 100644 index 0000000..1720dea --- /dev/null +++ b/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 @@ -0,0 +1,29 @@ +Configuration VMAdapter +{ + Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + cVMNetworkAdapter MyVM01NIC { + Id = 'MyVM01-NIC' + Name = 'MyVM01-NIC' + SwitchName = 'SETSwitch' + VMName = 'MyVM01' + Ensure = 'Present' + } + + cVMNetworkAdapter MyVM02NIC { + Id = 'MyVM02-NIC' + Name = 'NetAdapter' + SwitchName = 'SETSwitch' + VMName = 'MyVM02' + Ensure = 'Present' + } + + cVMNetworkAdapter MyVM03NIC { + Id = 'MyVM03-NIC' + Name = 'NetAdapter' + SwitchName = 'SETSwitch' + VMName = 'MyVM03' + Ensure = 'Present' + } +} diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 b/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 new file mode 100644 index 0000000..c23ad31 --- /dev/null +++ b/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 @@ -0,0 +1,23 @@ +Configuration VMAdapter +{ + Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + cVMNetworkAdapter MyVM01NIC { + Id = 'MyVM01-NIC' + Name = 'MyVM01-NIC' + SwitchName = 'SETSwitch' + MacAddress = '001523be0c' + VMName = 'MyVM01' + Ensure = 'Present' + } + + cVMNetworkAdapter MyVM02NIC { + Id = 'MyVM02-NIC' + Name = 'MyVM02-NIC' + SwitchName = 'SETSwitch' + MacAddress = '001523be0d' + VMName = 'MyVM02' + Ensure = 'Present' + } +} diff --git a/Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 b/Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 deleted file mode 100644 index 7bd8ae3..0000000 --- a/Examples/Sample_xVMNetworkAdapter_VM-StaticMacAddress.ps1 +++ /dev/null @@ -1,39 +0,0 @@ -configuration Sample_xVMNetworkAdapter_VM-StaticMacAddress -{ - param - ( - [string[]]$NodeName = 'localhost', - - [Parameter(Mandatory)] - [string]$Id, - - [Parameter(Mandatory)] - [string]$Name, - - [Parameter(Mandatory)] - [string]$SwitchName, - - [Parameter(Mandatory)] - [string]$VMName, - - [Parameter(Mandatory)] - [string]$StaticMacAddress - ) - - Import-DscResource -module xHyper-V - - Node $NodeName - { - # Ensures a VM network adapter is attached to a VM - xVMNetworkAdapter ManagementAdapter - { - Ensure = 'Present' - Id = $Id - Name = $Name - SwitchName = $SwitchName - VMName = $VMName - DynamicMacAddress = $false - StaticMacAddress = $StaticMacAddress - } - } -} diff --git a/Examples/Sample_xVMNetworkAdapter_VM.ps1 b/Examples/Sample_xVMNetworkAdapter_VM.ps1 deleted file mode 100644 index acac04d..0000000 --- a/Examples/Sample_xVMNetworkAdapter_VM.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -configuration Sample_xVMNetworkAdapter_VM -{ - param - ( - [string[]]$NodeName = 'localhost', - - [Parameter(Mandatory)] - [string]$Id, - - [Parameter(Mandatory)] - [string]$Name, - - [Parameter(Mandatory)] - [string]$SwitchName, - - [Parameter(Mandatory)] - [string]$VMName - ) - - Import-DscResource -module xHyper-V - - Node $NodeName - { - # Ensures a VM network adapter is attached to a VM - xVMNetworkAdapter ManagementAdapter - { - Ensure = 'Present' - Id = $Id - Name = $Name - SwitchName = $SwitchName - VMName = $VMName - } - } -} diff --git a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 index a07cbf2..2c47252 100644 --- a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 +++ b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 @@ -1,5 +1,5 @@ $Global:DSCModuleName = 'xHyper-V' -$Global:DSCResourceName = 'MSFT_xVMNetworkAdapter' +$Global:DSCResourceName = 'xVMNetworkAdapter' #region HEADER if ( (-not (Test-Path -Path '.\DSCResource.Tests\')) -or ` @@ -29,7 +29,7 @@ try Id = 'HostManagement1' Name = 'Management' SwitchName = 'HostSwitch' - VMName = 'Management OS' + VMName = 'ManagementOS' } $TestAdapter = [PSObject]@{ @@ -74,7 +74,7 @@ try $Result.Ensure | Should Be 'Present' $Result.Name | Should Be $TestAdapter.Name $Result.SwitchName | Should Be $TestAdapter.SwitchName - $Result.VMName | Should Be 'Management OS' + $Result.VMName | Should Be 'ManagementOS' $Result.Id | Should Be $TestAdapter.Id } It 'should call the expected mocks' { @@ -93,7 +93,7 @@ try Id = 'UniqueString' Name = $TestAdapter.Name SwitchName = $TestAdapter.SwitchName - VMName = 'Management OS' + VMName = 'ManagementOS' Ensure = 'Present' } @@ -145,7 +145,7 @@ try Id = 'UniqueString' Name = $TestAdapter.Name SwitchName = $TestAdapter.SwitchName - VMName = 'Management OS' + VMName = 'ManagementOS' Ensure = 'Present' } @@ -185,7 +185,7 @@ try } } - Context 'Adapter does not and no action needed' { + Context 'Adapter does not exist and no action needed' { Mock Get-VMNetworkAdapter It 'should return true' { From 9c5833284d3f6e6029fff03d7a52e42919e201b8 Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Fri, 28 Oct 2016 16:13:24 +0530 Subject: [PATCH 06/14] Update to schema - Added newline in schema MOF - Updated module name in Tests.ps1 --- .../MSFT_xVMNetworkAdapter.schema.mof | Bin 744 -> 394 bytes .../MSFT_xVMNetworkAdapter.Tests.ps1 | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof index c8be918e3c14636743f5e210d30409c76f265034..2d7ed1d34c78975c0c47477b91183ba4896386b0 100644 GIT binary patch literal 394 zcmaKnL2Cjr5QXmx`yYm!6qZsvwx_kNAQD^LvOS2%G#NB>P3$C#UBv(1tmtBCZE^|o zy}b7(P38|3dS4QI<7`h1Zf@Hv`WcMakkwT)#SQhuS1G3yc8))CjoUyh`inGC?Prk1 z=ymx^0C(^#$IBslnvr)kD@v1nnm|1B2{j8S0vo%6vA#b|XY^ScCf%Vn`zkDUCaCql zl34n};f+n8&Re3&wPy1EoN(kBlvvdyal02Uk&+D}6Z!k`aX3-`7wep#tgrc^H^zmA S&Q*jK9vh1rqke=RVu5c7O@2lI literal 744 zcmb7?O-lk%6o%hzLH}WJRUi>9Yo&dFgcTXKkcjDesUf|VGf^V`_3AlS9fNV93^UF> zp7-ONcYc5Nw5y)ZG*GIXt1GWDznMk~+E-1-I@D2l*L0w|5?#`j(HqnUJJB`xA!kE; z!_ubWRp<+zvEJ06FV#C0<2RN^nYJsH6EGck@Ab3+L!uL0+<MFKaeTm#(c$^0+P|E28%&2yWT-m5mb=;pKi}wl z$1B`JoWgcmb=hVoF7CY_C$V(bAuY`=y#r?U?9)=3lF;n}Wf>Qo>)Z`J!?LW*;+L?( s<{RUxZZA;DV{ZPROUoi%WY8qn5iYF~@O(~|f%hSMbi_@% diff --git a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 index 2c47252..8bad180 100644 --- a/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 +++ b/Tests/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.Tests.ps1 @@ -1,5 +1,5 @@ $Global:DSCModuleName = 'xHyper-V' -$Global:DSCResourceName = 'xVMNetworkAdapter' +$Global:DSCResourceName = 'MSFT_xVMNetworkAdapter' #region HEADER if ( (-not (Test-Path -Path '.\DSCResource.Tests\')) -or ` From 9a11107505fd9e4f9c0fde3c1ead975d9ca5d5a5 Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Fri, 28 Oct 2016 16:14:50 +0530 Subject: [PATCH 07/14] updated encoding --- DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 index 70e70e2..30c956e 100644 --- a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 +++ b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 @@ -1,4 +1,4 @@ -#region localizeddata +#region localizeddata if (Test-Path "${PSScriptRoot}\${PSUICulture}") { Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xVMNetworkAdapter.psd1 ` From 38d393029988682679431043a8f606d435aca38a Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Tue, 1 Nov 2016 09:04:20 +0530 Subject: [PATCH 08/14] Updated examples Updated xVMNetworkadapter examples to remove references to cHyper-V --- Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 | 4 ++-- .../Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 | 6 +++--- Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 | 8 ++++---- .../Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 b/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 index d939de4..7be0ae5 100644 --- a/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 +++ b/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 @@ -1,9 +1,9 @@ Configuration HostOSAdapter { - Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration - cVMNetworkAdapter HostOSAdapter { + xVMNetworkAdapter HostOSAdapter { Id = 'Management-NIC' Name = 'Management-NIC' SwitchName = 'SETSwitch' diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 b/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 index bf031b5..a0cd100 100644 --- a/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 +++ b/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 @@ -1,9 +1,9 @@ Configuration HostOSAdapter { - Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration - cVMNetworkAdapter ManagementAdapter { + xVMNetworkAdapter ManagementAdapter { Id = 'Management-NIC' Name = 'Management-NIC' SwitchName = 'SETSwitch' @@ -11,7 +11,7 @@ Ensure = 'Present' } - cVMNetworkAdapter ClusterAdapter { + xVMNetworkAdapter ClusterAdapter { Id = 'Cluster-NIC' Name = 'Cluster-NIC' SwitchName = 'SETSwitch' diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 b/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 index 1720dea..81b7b0b 100644 --- a/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 +++ b/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 @@ -1,9 +1,9 @@ Configuration VMAdapter { - Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration - cVMNetworkAdapter MyVM01NIC { + xVMNetworkAdapter MyVM01NIC { Id = 'MyVM01-NIC' Name = 'MyVM01-NIC' SwitchName = 'SETSwitch' @@ -11,7 +11,7 @@ Ensure = 'Present' } - cVMNetworkAdapter MyVM02NIC { + xVMNetworkAdapter MyVM02NIC { Id = 'MyVM02-NIC' Name = 'NetAdapter' SwitchName = 'SETSwitch' @@ -19,7 +19,7 @@ Ensure = 'Present' } - cVMNetworkAdapter MyVM03NIC { + xVMNetworkAdapter MyVM03NIC { Id = 'MyVM03-NIC' Name = 'NetAdapter' SwitchName = 'SETSwitch' diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 b/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 index c23ad31..80f0ead 100644 --- a/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 +++ b/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 @@ -1,9 +1,9 @@ Configuration VMAdapter { - Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter + Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration - cVMNetworkAdapter MyVM01NIC { + xVMNetworkAdapter MyVM01NIC { Id = 'MyVM01-NIC' Name = 'MyVM01-NIC' SwitchName = 'SETSwitch' @@ -12,7 +12,7 @@ Ensure = 'Present' } - cVMNetworkAdapter MyVM02NIC { + xVMNetworkAdapter MyVM02NIC { Id = 'MyVM02-NIC' Name = 'MyVM02-NIC' SwitchName = 'SETSwitch' From e5116401892b7402b1b9b12f248d7ef8bac7784c Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Mon, 14 Nov 2016 17:40:22 +0530 Subject: [PATCH 09/14] Updates to verbose messages addresses Mike's feedback on adding -Message to Write-Verbose. --- .../MSFT_xVMNetworkAdapter.psm1 | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 index 30c956e..5426416 100644 --- a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 +++ b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 @@ -56,7 +56,7 @@ Function Get-TargetResource if ($netAdapter) { - Write-Verbose $localizedData.FoundVMNetAdapter + Write-Verbose -Message $localizedData.FoundVMNetAdapter if ($VMName -eq 'ManagementOS') { $configuration.Add('MacAddress', $netAdapter.MacAddress) @@ -116,14 +116,14 @@ Function Set-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose $localizedData.GetVMNetAdapter + Write-Verbose -Message $localizedData.GetVMNetAdapter $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($Ensure -eq 'Present') { if ($netAdapterExists) { - Write-Verbose $localizedData.FoundVMNetAdapter + Write-Verbose -Message $localizedData.FoundVMNetAdapter if (($VMName -ne 'ManagementOS')) { if ($MacAddress) @@ -143,20 +143,20 @@ Function Set-TargetResource { if (-not $netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose $localizedData.EnableDynamicMacAddress + Write-Verbose -Message $localizedData.EnableDynamicMacAddress $updateMacAddress = $true } } if ($netAdapterExists.SwitchName -ne $SwitchName) { - Write-Verbose $localizedData.PerformSwitchConnect + Write-Verbose -Message $localizedData.PerformSwitchConnect Connect-VMNetworkAdapter -VMNetworkAdapter $netAdapterExists -SwitchName $SwitchName -ErrorAction Stop -Verbose } if (($updateMacAddress)) { - Write-Verbose $localizedData.PerformVMNetModify + Write-Verbose -Message $localizedData.PerformVMNetModify $setArguments = @{ } $setArguments.Add('VMNetworkAdapter',$netAdapterExists) @@ -186,13 +186,13 @@ Function Set-TargetResource } $arguments.Add('SwitchName',$SwitchName) } - Write-Verbose $localizedData.AddVMNetAdapter + Write-Verbose -Message $localizedData.AddVMNetAdapter Add-VMNetworkAdapter @arguments -ErrorAction Stop } } else { - Write-Verbose $localizedData.RemoveVMNetAdapter + Write-Verbose -Message $localizedData.RemoveVMNetAdapter Remove-VMNetworkAdapter @arguments -ErrorAction Stop } } @@ -236,7 +236,7 @@ Function Test-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose $localizedData.GetVMNetAdapter + Write-Verbose -Message $localizedData.GetVMNetAdapter $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($Ensure -eq 'Present') @@ -249,12 +249,12 @@ Function Test-TargetResource { if ($netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose $localizedData.EnableStaticMacAddress + Write-Verbose -Message $localizedData.EnableStaticMacAddress return $false } elseif ($netAdapterExists.MacAddress -ne $MacAddress) { - Write-Verbose $localizedData.StaticAddressDoesNotMatch + Write-Verbose -Message $localizedData.StaticAddressDoesNotMatch return $false } } @@ -262,31 +262,31 @@ Function Test-TargetResource { if (-not $netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose $localizedData.EnableDynamicMacAddress + Write-Verbose -Message $localizedData.EnableDynamicMacAddress return $false } } if ($netAdapterExists.SwitchName -ne $SwitchName) { - Write-Verbose $localizedData.SwitchIsDifferent + Write-Verbose -Message $localizedData.SwitchIsDifferent return $false } else { - Write-Verbose $localizedData.VMNetAdapterExistsNoActionNeeded + Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded return $true } } else { - Write-Verbose $localizedData.VMNetAdapterExistsNoActionNeeded + Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded return $true } } else { - Write-Verbose $localizedData.VMNetAdapterDoesNotExistShouldAdd + Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistShouldAdd return $false } } @@ -294,12 +294,12 @@ Function Test-TargetResource { if ($netAdapterExists) { - Write-Verbose $localizedData.VMNetAdapterExistsShouldRemove + Write-Verbose -Message $localizedData.VMNetAdapterExistsShouldRemove return $false } else { - Write-Verbose $localizedData.VMNetAdapterDoesNotExistNoActionNeeded + Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistNoActionNeeded return $true } } From b86fd33975c3e567f10fafd486dd4647e7b2c94c Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Mon, 14 Nov 2016 19:45:04 +0530 Subject: [PATCH 10/14] updates to PSM1 Added help before functions --- .../MSFT_xVMNetworkAdapter.psm1 | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 index 5426416..e1b6712 100644 --- a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 +++ b/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 @@ -12,6 +12,23 @@ else } #endregion +<# +.SYNOPSIS + Gets MSFT_xVMNetworkAdapter resource current state. + +.PARAMETER Id + Specifies an unique identifier for the network adapter. + +.PARAMETER Name + Specifies a name for the network adapter that needs to be connected to a VM or management OS. + +.PARAMETER SwitchName + Specifies the name of the switch to which the new VM network adapter will be connected. + +.PARAMETER VMName + Specifies the name of the VM to which the network adapter will be connected. + Specify VMName as ManagementOS if you wish to connect the adapter to host OS. +#> Function Get-TargetResource { [CmdletBinding()] @@ -78,6 +95,30 @@ Function Get-TargetResource return $configuration } +<# +.SYNOPSIS + Sets MSFT_xVMNetworkAdapter resource state. + +.PARAMETER Id + Specifies an unique identifier for the network adapter. + +.PARAMETER Name + Specifies a name for the network adapter that needs to be connected to a VM or management OS. + +.PARAMETER SwitchName + Specifies the name of the switch to which the new VM network adapter will be connected. + +.PARAMETER VMName + Specifies the name of the VM to which the network adapter will be connected. + Specify VMName as ManagementOS if you wish to connect the adapter to host OS. + +.PARAMETER MacAddress + Specifies the MAC address for the network adapter. This is not applicable if VMName + is set to ManagementOS. Use this parameter to specify a static MAC address. + +.PARAMETER Ensure + Specifies if the network adapter should be Present or Absent. +#> Function Set-TargetResource { [CmdletBinding()] @@ -197,6 +238,30 @@ Function Set-TargetResource } } +<# +.SYNOPSIS + Tests if MSFT_xVMNetworkAdapter resource state is indeed desired state or not. + +.PARAMETER Id + Specifies an unique identifier for the network adapter. + +.PARAMETER Name + Specifies a name for the network adapter that needs to be connected to a VM or management OS. + +.PARAMETER SwitchName + Specifies the name of the switch to which the new VM network adapter will be connected. + +.PARAMETER VMName + Specifies the name of the VM to which the network adapter will be connected. + Specify VMName as ManagementOS if you wish to connect the adapter to host OS. + +.PARAMETER MacAddress + Specifies the MAC address for the network adapter. This is not applicable if VMName + is set to ManagementOS. Use this parameter to specify a static MAC address. + +.PARAMETER Ensure + Specifies if the network adapter should be Present or Absent. +#> Function Test-TargetResource { [CmdletBinding()] From 39a4bf0b9cb9001058f0f6732fc905deb5ab6541 Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Tue, 20 Dec 2016 12:13:04 +0530 Subject: [PATCH 11/14] Updated readme to add the key property description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1df14e5..cc7bcd5 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Please see the Examples section for more details. ### xVMNetworkAdapter -* **Id**: Unique string for identifying the resource instance. +* **Id**: Unique string for identifying the resource instance. This is the key property for the instances of this resource. * **Name**: Name of the network adapter as it appears either in the management OS or attached to a VM. * **SwitchName**: Virtual Switch name to connect the adapter to. * **VMName**: Name of the VM to attach to. If you want to attach new VM Network adapter to the management OS, set this property to 'Management OS'. From 4d513a3ac99c0852bf625399be1361dc5ea3683e Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Wed, 25 Jan 2017 14:55:20 -0800 Subject: [PATCH 12/14] Releasing version 3.7.0.0 --- README.md | 2 ++ appveyor.yml | 4 ++-- xHyper-V.psd1 | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 41323ac..74a78db 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ Please see the Examples section for more details. ## Versions ### Unreleased + +### 3.7.0.0 * Adding a new resource * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management OS or VM. diff --git a/appveyor.yml b/appveyor.yml index 8adb579..74f5689 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ #---------------------------------# # environment configuration # #---------------------------------# -version: 3.6.{build}.0 +version: 3.7.{build}.0 install: - git clone https://github.com/PowerShell/DscResource.Tests - ps: | @@ -38,7 +38,7 @@ deploy_script: # Creating project artifact $stagingDirectory = (Resolve-Path ..).Path $manifest = Join-Path $pwd "xHyper-V.psd1" - (Get-Content $manifest -Raw).Replace("3.6.0.0", $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest + (Get-Content $manifest -Raw).Replace("3.7.0.0", $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest $zipFilePath = Join-Path $stagingDirectory "$(Split-Path $pwd -Leaf).zip" Add-Type -assemblyname System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::CreateFromDirectory($pwd, $zipFilePath) diff --git a/xHyper-V.psd1 b/xHyper-V.psd1 index 039effb..1da9bfd 100644 --- a/xHyper-V.psd1 +++ b/xHyper-V.psd1 @@ -1,6 +1,6 @@ @{ # Version number of this module. -ModuleVersion = '3.6.0.0' +ModuleVersion = '3.7.0.0' # ID used to uniquely identify this module GUID = 'f5a5f169-7026-4053-932a-19a7c37b1ca5' @@ -47,7 +47,8 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '* xVHD: Updated incorrect property name MaximumSize in error message + ReleaseNotes = '* Adding a new resource + * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management OS or VM. ' @@ -60,3 +61,4 @@ PrivateData = @{ + From 8da848df980cadf3b8b4de99ffe64f760fd27c9d Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Thu, 26 Jan 2017 10:21:04 -0800 Subject: [PATCH 13/14] Revert Pester version and remove tabs from README --- README.md | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74a78db..05ee024 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Please see the Examples section for more details. ### 3.7.0.0 * Adding a new resource - * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management OS or VM. + * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management OS or VM. ### 3.6.0.0 diff --git a/appveyor.yml b/appveyor.yml index 74f5689..7cf93ac 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,7 @@ install: - ps: | Import-Module -Name .\DscResource.Tests\TestHelper.psm1 -Force Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force - Install-Module -Name Pester -Repository PSGallery -Force + Install-Module -Name Pester -Repository PSGallery -MaximumVersion 3.4.3 -Force #---------------------------------# # build configuration # From 7fb9815db2ecc0c1354ac0b5615e606303c01f35 Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Thu, 26 Jan 2017 10:25:15 -0800 Subject: [PATCH 14/14] Remove tabs from module manifest --- xHyper-V.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xHyper-V.psd1 b/xHyper-V.psd1 index 1da9bfd..5341d74 100644 --- a/xHyper-V.psd1 +++ b/xHyper-V.psd1 @@ -48,7 +48,7 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = '* Adding a new resource - * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management OS or VM. + * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management OS or VM. '