Skip to content

Commit

Permalink
Merge pull request #51 from tysonjhayes/NetConnectionProfile
Browse files Browse the repository at this point in the history
Adding NetConnectionProfile DSC Resource
  • Loading branch information
Tyson J. Hayes committed Nov 19, 2015
2 parents 39df4b7 + 96068c9 commit 2153bab
Show file tree
Hide file tree
Showing 10 changed files with 487 additions and 7 deletions.
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
}
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;
};
30 changes: 30 additions & 0 deletions Examples/Sample_xNetConnectionProfile.ps1
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
}
}
}
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build status](https://ci.appveyor.com/api/projects/status/obmudad7gy8usbx2/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xnetworking/branch/master)
[![Build status](https://ci.appveyor.com/api/projects/status/obmudad7gy8usbx2/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xnetworking/branch/master)

# xNetworking

Expand All @@ -15,6 +15,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
* **xDnsServerAddress** sets a node's DNS server.
* **xDnsConnectionSuffix** sets a node's network interface connection-specific DNS suffix.
* **xDefaultGatewayAddress** sets a node's default gateway address.
* **xNetConnectionProfile** sets a node's connection profile.

### xIPAddress

Expand Down Expand Up @@ -72,6 +73,13 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
* **RemoteMachine**: Specifies that matching IPsec rules of the indicated computer accounts are created. This parameter specifies that only network packets that are authenticated as incoming from or outgoing to a computer identified in the list of computer accounts (SID) match this rule. This parameter value is specified as an SDDL string.
* **RemoteUser**: Specifies that matching IPsec rules of the indicated user accounts are created. This parameter specifies that only network packets that are authenticated as incoming from or outgoing to a user identified in the list of user accounts match this rule. This parameter value is specified as an SDDL string.

### xNetConnectionProfile
* **InterfaceAlias**: Specifies the alias for the Interface that is being changed.
* **NetworkCategory**: Sets the NetworkCategory for the interface - per [the documentation ](https://technet.microsoft.com/en-us/%5Clibrary/jj899565(v=wps.630).aspx) this can only be set to { Public | Private }
* **IPv4Connectivity**: Specifies the IPv4 Connection Value { Disconnected | NoTraffic | Subnet | LocalNetwork | Internet }
* **IPv6Connectivity**: Specifies the IPv6 Connection Value { Disconnected | NoTraffic | Subnet | LocalNetwork | Internet }


## Known Invalid Configurations

### xFirewall
Expand All @@ -89,12 +97,14 @@ The cmdlet does not fully support the Inquire action for debug messages. Cmdlet
## Versions

### Unreleased Version
* Added the following resources:
* MSFT_xDNSConnectionSuffix resource to manage connection-specific DNS suffixes.
* MSFT_xNetConnectionProfile resource to manage Connection Profiles for interfaces.
* MSFT_xDNSServerAddress: Corrected Verbose logging messages when multiple DNS adddressed specified.
* MSFT_xDNSServerAddress: Change to ensure resource terminates if DNS Server validation fails.
* MSFT_xDNSServerAddress: Added Validate parameter to enable DNS server validation when changing server addresses.
* MSFT_xFirewall: ApplicationPath Parameter renamed to Program for consistency with Cmdlets.
* MSFT_xFirewall: Fix to prevent error when DisplayName parameter is set on an existing rule.
* Added xDnsConnectionSuffix resource to manage connection-specific DNS suffixes.
* MSFT_xFirewall: Setting a different DisplayName parameter on an existing rule now correctly reports as needs change.
* MSFT_xFirewall: Changed DisplayGroup parameter to Group for consistency with Cmdlets and reduce confusion.
* MSFT_xFirewall: Changing the Group of an existing Firewall rule will recreate the Firewall rule rather than change it.
Expand Down Expand Up @@ -546,4 +556,20 @@ configuration Sample_xFirewall_AddFirewallRule_AllParameters
Sample_xFirewall_AddFirewallRule_AllParameters
Start-DscConfiguration -Path Sample_xFirewall_AddFirewallRule_AllParameters -Wait -Verbose -Force
```
```

### Set the NetConnectionProfile to Public

````powershell
configuration MSFT_xNetConnectionProfile_Config {
Import-DscResource -ModuleName xNetworking
node localhost {
xNetConnectionProfile Integration_Test {
InterfaceAlias = 'Wi-Fi'
NetworkCategory = 'Public'
IPv4Connectivity = 'Internet'
IPv6Connectivity = 'Disconncted'
}
}
}
````
21 changes: 21 additions & 0 deletions Templates/integration_config_template.ps1
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
6 changes: 3 additions & 3 deletions Templates/integration_template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Template for creating Integration Tests
.DESCRIPTION
To Use:
1. Copy to \Tests\Integration\ folder and rename MSFT_x<ResourceName>.tests.ps1
1. Copy to \Tests\Integration\ folder and rename MSFT_x<ResourceName>.Integration.tests.ps1
2. Customize TODO sections.
.NOTES
Expand Down Expand Up @@ -96,7 +96,7 @@ try
#>
$ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$DSCResourceName.config.ps1"
. $ConfigFile

Describe "$($DSCResourceName)_Integration" {
#region DEFAULT TESTS
It 'Should compile without throwing' {
Expand Down Expand Up @@ -132,7 +132,7 @@ finally
if ($rollbackExecution)
{
Set-ExecutionPolicy -ExecutionPolicy $executionPolicy -Force
}
}

# Cleanup Working Folder
if (Test-Path -Path $WorkingFolder)
Expand Down
Loading

0 comments on commit 2153bab

Please sign in to comment.