Skip to content

Commit

Permalink
Merge pull request #91 from PowerShell/dev
Browse files Browse the repository at this point in the history
Merging release pull request
  • Loading branch information
KarolKaczmarek committed Feb 3, 2016
2 parents 344eb91 + 04aa21f commit b801a07
Show file tree
Hide file tree
Showing 12 changed files with 787 additions and 9 deletions.
227 changes: 227 additions & 0 deletions DSCResources/MSFT_xNetworkTeam/MSFT_xNetworkTeam.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xNetworkTeam.psd1 -BaseDirectory $PSScriptRoot -Verbose

Function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
Param
(
[Parameter(Mandatory)]
[string]$Name,

[Parameter(Mandatory)]
[String[]]$TeamMembers
)

$configuration = @{
name = $Name
teamMembers = $TeamMembers
}

Write-Verbose -Message ($localizedData.GetTeamInfo -f $Name)
$networkTeam = Get-NetLBFOTeam -Name $Name -ErrorAction SilentlyContinue

if ($networkTeam)
{
Write-Verbose -Message ($localizedData.FoundTeam -f $Name)
if ($null -eq (Compare-Object -ReferenceObject $TeamMembers -DifferenceObject $networkTeam.Members))
{
Write-Verbose -Message ($localizedData.teamMembersExist -f $Name)
$configuration.Add('loadBalancingAlgorithm', $networkTeam.loadBalancingAlgorithm)
$configuration.Add('teamingMode', $networkTeam.teamingMode)
$configuration.Add('ensure','Present')
}
}
else
{
Write-Verbose -Message ($localizedData.TeamNotFound -f $Name)
$configuration.Add('ensure','Absent')
}
$configuration
}

Function Set-TargetResource
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory)]
[string]$Name,

[Parameter(Mandatory)]
[String[]]$TeamMembers,

[Parameter()]
[ValidateSet("SwitchIndependent", "LACP", "Static")]
[String]$TeamingMode = "SwitchIndependent",

[Parameter()]
[ValidateSet("Dynamic", "HyperVPort", "IPAddresses", "MacAddresses", "TransportPorts")]
[String]$LoadBalancingAlgorithm = "HyperVPort",

[ValidateSet('Present', 'Absent')]
[String]$Ensure = 'Present'
)
Write-Verbose -Message ($localizedData.GetTeamInfo -f $Name)
$networkTeam = Get-NetLBFOTeam -Name $Name -ErrorAction SilentlyContinue

if ($Ensure -eq 'Present')
{
if ($networkTeam)
{
Write-Verbose -Message ($localizedData.foundTeam -f $Name)
$setArguments = @{
'name' = $Name
}

if ($networkTeam.loadBalancingAlgorithm -ne $LoadBalancingAlgorithm)
{
Write-Verbose -Message ($localizedData.lbAlgoDifferent -f $LoadBalancingAlgorithm)
$SetArguments.Add('loadBalancingAlgorithm', $LoadBalancingAlgorithm)
$isNetModifyRequired = $true
}

if ($networkTeam.TeamingMode -ne $TeamingMode)
{
Write-Verbose -Message ($localizedData.teamingModeDifferent -f $TeamingMode)
$setArguments.Add('teamingMode', $TeamingMode)
$isNetModifyRequired = $true
}

if ($isNetModifyRequired)
{
Write-Verbose -Message ($localizedData.modifyTeam -f $Name)
Set-NetLbfoTeam @setArguments -ErrorAction Stop -Confirm:$false
}

$netTeamMembers = Compare-Object `
-ReferenceObject $TeamMembers `
-DifferenceObject $networkTeam.Members
if ($null -ne $netTeamMembers)
{
Write-Verbose -Message ($localizedData.membersDifferent -f $Name)
$membersToRemove = ($netTeamMembers | Where-Object {$_.SideIndicator -eq '=>'}).InputObject
if ($membersToRemove)
{
Write-Verbose -Message ($localizedData.removingMembers -f ($membersToRemove -join ','))
$null = Remove-NetLbfoTeamMember -Name $membersToRemove `
-Team $Name `
-ErrorAction Stop `
-Confirm:$false
}

$membersToAdd = ($netTeamMembers | Where-Object {$_.SideIndicator -eq '<='}).InputObject
if ($membersToAdd)
{
Write-Verbose -Message ($localizedData.addingMembers -f ($membersToAdd -join ','))
$null = Add-NetLbfoTeamMember -Name $membersToAdd `
-Team $Name `
-ErrorAction Stop `
-Confirm:$false
}
}

}
else
{
Write-Verbose -Message ($localizedData.createTeam -f $Name)
try
{
$null = New-NetLbfoTeam `
-Name $Name `
-TeamMembers $teamMembers `
-TeamingMode $TeamingMode `
-LoadBalancingAlgorithm $loadBalancingAlgorithm `
-ErrorAction Stop `
-Confirm:$false
Write-Verbose -Message $localizedData.createdNetTeam
}

catch
{
$errorId = 'TeamCreateError'
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidOperation
$errorMessage = $localizedData.failedToCreateTeam
$exception = New-Object -TypeName System.InvalidOperationException `
-ArgumentList $errorMessage
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
-ArgumentList $exception, $errorId, $errorCategory, $null

$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}
}
else
{
Write-Verbose -Message ($localizedData.removeTeam -f $Name)
$null = Remove-NetLbfoTeam -Name $name -ErrorAction Stop -Confirm:$false
}
}

Function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
Param
(
[Parameter(Mandatory)]
[string]$Name,

[Parameter(Mandatory)]
[String[]]$TeamMembers,

[Parameter()]
[ValidateSet("SwitchIndependent", "LACP", "Static")]
[String]$TeamingMode = "SwitchIndependent",

[Parameter()]
[ValidateSet("Dynamic", "HyperVPort", "IPAddresses", "MacAddresses", "TransportPorts")]
[String]$LoadBalancingAlgorithm = "HyperVPort",

[ValidateSet('Present', 'Absent')]
[String]$Ensure = 'Present'
)

Write-Verbose -Message ($localizedData.GetTeamInfo -f $Name)
$networkTeam = Get-NetLbfoTeam -Name $Name -ErrorAction SilentlyContinue

if ($ensure -eq 'Present')
{
if ($networkTeam)
{
Write-Verbose -Message ($localizedData.foundTeam -f $Name)
if (
($networkTeam.LoadBalancingAlgorithm -eq $LoadBalancingAlgorithm) -and
($networkTeam.teamingMode -eq $TeamingMode) -and
($null -eq (Compare-Object -ReferenceObject $TeamMembers -DifferenceObject $networkTeam.Members))
)
{
Write-Verbose -Message ($localizedData.teamExistsNoAction -f $Name)
return $true
}
else
{
Write-Verbose -Message ($localizedData.teamExistsWithDifferentConfig -f $Name)
return $false
}
}
else
{
Write-Verbose -Message ($localizedData.teamDoesNotExistShouldCreate -f $Name)
return $false
}
}
else
{
if ($networkTeam)
{
Write-Verbose -Message ($localizedData.teamExistsShouldRemove -f $Name)
return $false
}
else
{
Write-Verbose -Message ($localizedData.teamDoesNotExistNoAction -f $Name)
return $true
}
}
}
9 changes: 9 additions & 0 deletions DSCResources/MSFT_xNetworkTeam/MSFT_xNetworkTeam.schema.mof
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[ClassVersion("1.1"), FriendlyName("xNetworkTeam")]
class MSFT_xNetworkTeam : OMI_BaseResource
{
[Key] String Name;
[Write, ValueMap{"SwitchIndependent","LACP","Static"}, Values{"SwitchIndependent","LACP","Static"}] String TeamingMode;
[Write, ValueMap{"Dynamic","HyperVPort","IPAddresses","MacAddresses","TransportPorts"}, Values{"Dynamic","HyperVPort","IPAddresses","MacAddresses","TransportPorts"}] String LoadBalancingAlgorithm;
[Required] String TeamMembers[];
[Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
};
22 changes: 22 additions & 0 deletions DSCResources/MSFT_xNetworkTeam/en-US/MSFT_xNetworkTeam.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ConvertFrom-StringData @'
getTeamInfo=Getting network team information for {0}.
foundTeam=Found a network team with name {0}.
teamMembersExist=Members in the network team {0} exist as per the configuration.
teamNotFound=Network team with name {0} not found.
lbAlgoDifferent=Load Balancing Algo is different from the requested {0} algo.
teamingModeDifferent=Teaming mode is different from the requested {0} mode.
modifyTeam=Modifying the network team named {0}.
membersDifferent=Members within the team named {0} are different from that requested in the configuration.
removingMembers=Removing members {0} not specified in the configuration.
addingMembers=Adding members {0} that are not a part of the team configuration.
createTeam=Creating a network team with the name {0}.
removeTeam=Removing a network team with the name {0}.
teamExistsNoAction=Network team with name {0} exists. No action needed.
teamExistsWithDifferentConfig=Network team with name {0} exists but with different configuration. This will be modified.
teamDoesNotExistShouldCreate=Network team with name {0} does not exist. It will be created.
teamExistsShouldRemove=Network team with name {0} exists. It will be removed.
teamDoesNotExistNoAction=Network team with name {0} does not exist. No action needed.
waitingForTeam=Waiting for network team status to change to up.
createdNetTeam=Network Team was created successfully.
failedToCreateTeam=Failed to create the network team with specific configuration.
'@
24 changes: 24 additions & 0 deletions Examples/Sample_xNetworkTeam_AddTeam.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
configuration Sample_xNetworkTeam_AddTeam
{
param
(
[string[]]$NodeName = 'localhost'
)

Import-DSCResource -ModuleName xNetworking

Node $NodeName
{
xNetworkTeam HostTeam
{
Name = 'HostTeam'
TeamingMode = 'SwitchIndependent'
LoadBalancingAlgorithm = 'HyperVPort'
TeamMembers = 'NIC1','NIC2'
Ensure = 'Present'
}
}
}

Sample_xNetworkTeam_AddTeam
Start-DscConfiguration -Path Sample_xNetworkTeam_AddTeam -Wait -Verbose -Force
21 changes: 21 additions & 0 deletions Examples/Sample_xNetworkTeam_RemoveTeam.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
configuration Sample_xNetworkTeam_RemoveTeam
{
param
(
[string[]]$NodeName = 'localhost'
)

Import-DSCResource -ModuleName xNetworking

Node $NodeName
{
xNetworkTeam HostTeam
{
Name = 'HostTeam'
Ensure = 'Absent'
}
}
}

Sample_xNetworkTeam_RemoveTeam
Start-DscConfiguration -Path Sample_xNetworkTeam_RemoveTeam -Wait -Verbose -Force
24 changes: 24 additions & 0 deletions Examples/Sample_xNetworkTeam_UpdateTeamMembers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
configuration Sample_xNetworkTeam_UpdateTeamMembers
{
param
(
[string[]]$NodeName = 'localhost'
)

Import-DSCResource -ModuleName xNetworking

Node $NodeName
{
xNetworkTeam HostTeam
{
Name = 'HostTeam'
TeamingMode = 'SwitchIndependent'
LoadBalancingAlgorithm = 'HyperVPort'
TeamMembers = 'NIC1','NIC2','NIC3'
Ensure = 'Present'
}
}
}

Sample_xNetworkTeam_UpdateTeamMembers
Start-DscConfiguration -Path Sample_xNetworkTeam_UpdateTeamMembers -Wait -Verbose -Force
Loading

0 comments on commit b801a07

Please sign in to comment.