diff --git a/CHANGELOG.md b/CHANGELOG.md index 740b7c81..cf317ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - IPAddress - Improved integration test structure. +### Added + +- NetIPInterface + - Added `InterfaceMetric` parameter- fixes [Issue #473](https://github.com/PowerShell/xNetworking/issues/473). + ### Fixed - NetIPInterface diff --git a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.data.psd1 b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.data.psd1 index 9f79d3d7..b533a0d4 100644 --- a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.data.psd1 +++ b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.data.psd1 @@ -63,6 +63,10 @@ @{ ParameterName = 'NlMtuBytes' PropertyName = 'NlMtu' + }, + @{ + ParameterName = 'InterfaceMetric' + PropertyName = 'InterfaceMetric' } ) } diff --git a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 index 2f72b422..5cb3caad 100644 --- a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 +++ b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 @@ -118,6 +118,9 @@ function Get-TargetResource .PARAMETER NlMtu Specifies the network layer Maximum Transmission Unit (MTU) value, in bytes, for an IP interface. + + .PARAMETER InterfaceMetric + Specifies the metric for an IP interface. #> function Set-TargetResource { @@ -211,7 +214,11 @@ function Set-TargetResource [Parameter()] [System.UInt32] - $NlMtu + $NlMtu, + + [Parameter()] + [System.UInt32] + $InterfaceMetric ) Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " @@ -322,6 +329,9 @@ function Set-TargetResource .PARAMETER NlMtu Specifies the network layer Maximum Transmission Unit (MTU) value, in bytes, for an IP interface. + + .PARAMETER InterfaceMetric + Specifies the metric for an IP interface. #> function Test-TargetResource { @@ -416,7 +426,11 @@ function Test-TargetResource [Parameter()] [System.UInt32] - $NlMtu + $NlMtu, + + [Parameter()] + [System.UInt32] + $InterfaceMetric ) Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " diff --git a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.schema.mof b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.schema.mof index 92db80b3..35dd6796 100644 --- a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.schema.mof +++ b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.schema.mof @@ -19,4 +19,5 @@ class DSC_NetIPInterface : OMI_BaseResource [Write, Description("Specifies the receive value for a weak host model."), ValueMap{"Enabled", "Disabled"},Values{"Enabled", "Disabled"}] String WeakHostReceive; [Write, Description("Specifies the send value for a weak host model."), ValueMap{"Enabled", "Disabled"},Values{"Enabled", "Disabled"}] String WeakHostSend; [Write, Description("Specifies the network layer Maximum Transmission Unit (MTU) value, in bytes, for an IP interface.")] UInt32 NlMtu; + [Write, Description("Specifies the metric for an IP interface.")] UInt32 InterfaceMetric; }; diff --git a/source/DSCResources/DSC_NetIPInterface/README.MD b/source/DSCResources/DSC_NetIPInterface/README.MD index 1db3e7cc..5d936d14 100644 --- a/source/DSCResources/DSC_NetIPInterface/README.MD +++ b/source/DSCResources/DSC_NetIPInterface/README.MD @@ -1,3 +1,9 @@ # Description This resource is used to configure the IP interface settings for a network interface. + +## Known Issues + +- If you define a value for `InterfaceMetric`, the `AutomaticMetric` +setting is ignored. PowerShell ignores `AutomaticMetric` when you +use both arguments with the `Set-NetIPInterface` cmdlet. diff --git a/source/Examples/Resources/NetIPInterface/5-NetIPInterface_SetInterfaceMetric.ps1 b/source/Examples/Resources/NetIPInterface/5-NetIPInterface_SetInterfaceMetric.ps1 new file mode 100644 index 00000000..9cc988e4 --- /dev/null +++ b/source/Examples/Resources/NetIPInterface/5-NetIPInterface_SetInterfaceMetric.ps1 @@ -0,0 +1,46 @@ +<#PSScriptInfo +.VERSION 1.0.0 +.GUID c67b7df4-bafa-4bca-bb43-349b44df3530 +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. +.TAGS DSCConfiguration +.LICENSEURI https://github.com/dsccommunity/NetworkingDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/NetworkingDsc +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES First version. +.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core +#> + +#Requires -module NetworkingDsc + +<# + .DESCRIPTION + Set a specified interface metrics for the network adapters with alias 'Ethernet' and 'Ethernet 2'. +#> +Configuration NetIPInterface_SetInterfaceMetric +{ + Import-DscResource -Module NetworkingDsc + + Node localhost + { + NetIPInterface EthernetMetric + { + InterfaceAlias = 'Ethernet' + AddressFamily = 'IPv4' + AutomaticMetric = 'Disabled' + InterfaceMetric = 10 + } + + NetIPInterface Ethernet2Metric + { + InterfaceAlias = 'Ethernet 2' + AddressFamily = 'IPv4' + AutomaticMetric = 'Disabled' + InterfaceMetric = 20 + } + } +} diff --git a/tests/Integration/DSC_NetIPInterface.Integration.Tests.ps1 b/tests/Integration/DSC_NetIPInterface.Integration.Tests.ps1 index 390b3a34..6db33275 100644 --- a/tests/Integration/DSC_NetIPInterface.Integration.Tests.ps1 +++ b/tests/Integration/DSC_NetIPInterface.Integration.Tests.ps1 @@ -136,6 +136,7 @@ try InterfaceAlias = 'NetworkingDscLBA' AddressFamily = 'IPv4' AdvertiseDefaultRoute = 'Disabled' + AutomaticMetric = 'Disabled' Dhcp = 'Disabled' DirectedMacWolPattern = 'Disabled' EcnMarking = 'Disabled' @@ -148,6 +149,7 @@ try WeakHostReceive = 'Disabled' WeakHostSend = 'Disabled' NlMtu = 1500 + InterfaceMetric = 20 } ) } @@ -179,6 +181,7 @@ try $current.InterfaceAlias | Should -Be $script:configData.AllNodes[0].InterfaceAlias $current.AddressFamily | Should -Be $script:configData.AllNodes[0].AddressFamily $current.AdvertiseDefaultRoute | Should -Be $script:configData.AllNodes[0].AdvertiseDefaultRoute + $current.AutomaticMetric | Should -Be $script:configData.AllNodes[0].AutomaticMetric $current.Dhcp | Should -Be $script:configData.AllNodes[0].Dhcp $current.DirectedMacWolPattern | Should -Be $script:configData.AllNodes[0].DirectedMacWolPattern $current.EcnMarking | Should -Be $script:configData.AllNodes[0].EcnMarking @@ -191,6 +194,7 @@ try $current.WeakHostReceive | Should -Be $script:configData.AllNodes[0].WeakHostReceive $current.WeakHostSend | Should -Be $script:configData.AllNodes[0].WeakHostSend $current.NlMtu | Should -Be $script:configData.AllNodes[0].NlMtu + $current.InterfaceMetric | Should -Be $script:configData.AllNodes[0].InterfaceMetric } } } diff --git a/tests/Integration/DSC_NetIPInterface.config.ps1 b/tests/Integration/DSC_NetIPInterface.config.ps1 index 220d6285..4a9cfbae 100644 --- a/tests/Integration/DSC_NetIPInterface.config.ps1 +++ b/tests/Integration/DSC_NetIPInterface.config.ps1 @@ -21,6 +21,7 @@ configuration DSC_NetIPInterface_Config_Enabled { WeakHostReceive = $Node.WeakHostReceive WeakHostSend = $Node.WeakHostSend NlMtu = $Node.NlMtu + InterfaceMetric = $Node.InterfaceMetric } } } @@ -46,6 +47,7 @@ configuration DSC_NetIPInterface_Config_Disabled { WeakHostReceive = $Node.WeakHostReceive WeakHostSend = $Node.WeakHostSend NlMtu = $Node.NlMtu + InterfaceMetric = $Node.InterfaceMetric } } } diff --git a/tests/Unit/DSC_NetIPInterface.Tests.ps1 b/tests/Unit/DSC_NetIPInterface.Tests.ps1 index 5724d5e3..c5081d4f 100644 --- a/tests/Unit/DSC_NetIPInterface.Tests.ps1 +++ b/tests/Unit/DSC_NetIPInterface.Tests.ps1 @@ -171,6 +171,14 @@ try ParameterFilter = { $InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $NlMtuBytes -eq 1500 } + }, + @{ + Name = 'InterfaceMetric' + MockedValue = [System.Uint32] 20 + TestValue = [System.Uint32] 15 + ParameterFilter = { + $InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $InterfaceMetric -eq 15 + } } )