-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from tysonjhayes/NetConnectionProfile
Adding NetConnectionProfile DSC Resource
- Loading branch information
Showing
10 changed files
with
487 additions
and
7 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
DSCResources/MSFT_xNetConnectionProfile/MSFT_xNetConnectionProfile.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
data LocalizedData | ||
{ | ||
# culture="en-US" | ||
ConvertFrom-StringData -StringData @' | ||
GettingNetConnectionProfile = Getting NetConnectionProfile from interface '{0}'. | ||
TestIPv4Connectivity = IPv4Connectivity '{0}' does not match set IPv4Connectivity '{1}' | ||
TestIPv6Connectivity = IPv6Connectivity '{0}' does not match set IPv6Connectivity '{1}' | ||
TestNetworkCategory = NetworkCategory '{0}' does not match set NetworkCategory '{1}' | ||
SetNetConnectionProfile = Setting NetConnectionProfile on interface '{0}' | ||
'@ | ||
} | ||
|
||
|
||
function Get-TargetResource | ||
{ | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[parameter(Position = 0, Mandatory = $true)] | ||
[string] $InterfaceAlias | ||
) | ||
|
||
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " | ||
$($LocalizedData.GettingNetConnectionProfile) -f $InterfaceAlias | ||
) -join '') | ||
|
||
$result = Get-NetConnectionProfile -InterfaceAlias $InterfaceAlias | ||
|
||
return @{ | ||
InterfaceAlias = $result.InterfaceAlias | ||
NetworkCategory = $result.NetworkCategory | ||
IPv4Connectivity = $result.IPv4Connectivity | ||
IPv6Connectivity = $result.IPv6Connectivity | ||
} | ||
} | ||
|
||
function Set-TargetResource | ||
{ | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[string] $InterfaceAlias, | ||
|
||
[ValidateSet('Disconnected', 'NoTraffic', 'Subnet', 'LocalNetwork', 'Internet')] | ||
[string] $IPv4Connectivity, | ||
|
||
[ValidateSet('Disconnected', 'NoTraffic', 'Subnet', 'LocalNetwork', 'Internet')] | ||
[string] $IPv6Connectivity, | ||
|
||
[ValidateSet('Public', 'Private')] | ||
[string] $NetworkCategory | ||
) | ||
|
||
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " | ||
$($LocalizedData.SetNetConnectionProfile) -f $InterfaceAlias | ||
) -join '') | ||
|
||
Set-NetConnectionProfile @PSBoundParameters | ||
} | ||
|
||
|
||
function Test-TargetResource | ||
{ | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[string] $InterfaceAlias, | ||
|
||
[ValidateSet('Disconnected', 'NoTraffic', 'Subnet', 'LocalNetwork', 'Internet')] | ||
[string] $IPv4Connectivity, | ||
|
||
[ValidateSet('Disconnected', 'NoTraffic', 'Subnet', 'LocalNetwork', 'Internet')] | ||
[string] $IPv6Connectivity, | ||
|
||
[ValidateSet('Public', 'Private')] | ||
[string] $NetworkCategory | ||
) | ||
|
||
$current = Get-TargetResource -InterfaceAlias $InterfaceAlias | ||
|
||
if ($IPv4Connectivity -ne $current.IPv4Connectivity) | ||
{ | ||
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " | ||
$($LocalizedData.TestIPv4Connectivity) -f $IPv4Connectivity, $current.IPv4Connectivity | ||
) -join '') | ||
|
||
return $false | ||
} | ||
|
||
if ($IPv6Connectivity -ne $current.IPv6Connectivity) | ||
{ | ||
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " | ||
$($LocalizedData.TestIPv6Connectivity) -f $IPv6Connectivity, $current.IPv6Connectivity | ||
) -join '') | ||
|
||
return $false | ||
} | ||
|
||
if ($NetworkCategory -ne $current.NetworkCategory) | ||
{ | ||
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " | ||
$($LocalizedData.TestNetworkCategory) -f $NetworkCategory, $current.NetworkCategory | ||
) -join '') | ||
|
||
return $false | ||
} | ||
|
||
return $true | ||
} |
8 changes: 8 additions & 0 deletions
8
DSCResources/MSFT_xNetConnectionProfile/MSFT_xNetConnectionProfile.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ClassVersion("1.0"), FriendlyName("xNetConnectionProfile")] | ||
class MSFT_xNetConnectionProfile : OMI_BaseResource | ||
{ | ||
[Key] string InterfaceAlias; | ||
[Write,ValueMap{"Disconnected", "NoTraffic", "Subnet", "LocalNetwork", "Internet"},Values{"Disconnected", "NoTraffic", "Subnet", "LocalNetwork", "Internet"}] string IPv4Connectivity; | ||
[Write,ValueMap{"Disconnected", "NoTraffic", "Subnet", "LocalNetwork", "Internet"},Values{"Disconnected", "NoTraffic", "Subnet", "LocalNetwork", "Internet"}] string IPv6Connectivity; | ||
[Write,ValueMap{"Public", "Private"},Values{"Public", "Private"}] string NetworkCategory; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
configuration Sample_xNetConnectionProfile | ||
{ | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[string] $InterfaceAlias, | ||
|
||
[ValidateSet('Disconnected', 'NoTraffic', 'Subnet', 'LocalNetwork', 'Internet')] | ||
[string] $IPv4Connectivity, | ||
|
||
[ValidateSet('Disconnected', 'NoTraffic', 'Subnet', 'LocalNetwork', 'Internet')] | ||
[string] $IPv6Connectivity, | ||
|
||
[ValidateSet('Public', 'Private')] | ||
[string] $NetworkCategory | ||
) | ||
|
||
Import-DscResource -Module xNetworking | ||
|
||
Node $NodeName | ||
{ | ||
xNetConnectionProfile Integration_Test | ||
{ | ||
InterfaceAlias = $InterfaceAlias | ||
NetworkCategory = $NetworkCategory | ||
IPv4Connectivity = $IPv4Connectivity | ||
IPv6Connectivity = $IPv6Connectivity | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<# | ||
This file exists so we can load the test file without necessarily having xNetworking in | ||
the $env:PSModulePath. Otherwise PowerShell will throw an error when reading the Pester File | ||
#> | ||
|
||
$rule = @{ | ||
# TODO: Populate $rule with config data. | ||
} | ||
|
||
# TODO: Modify ResourceName | ||
configuration 'MSFT_<xResourceName>' { | ||
Import-DscResource -ModuleName xNetworking | ||
node localhost { | ||
# TODO: Modify ResourceName | ||
'<xResourceName>' Integration_Test { | ||
# TODO: Fill Configuration Code Here | ||
} | ||
} | ||
} | ||
|
||
# TODO: (Optional): Add More Configuration Templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.