Skip to content

Commit

Permalink
xClusterPreferredOwner: Enabled localization (#117)
Browse files Browse the repository at this point in the history
- Changes to xClusterPreferredOwner
  - Enabled localization for all strings (issue #86).
  - Fixed typo in the returned hash table from Get-TargetResource.
  • Loading branch information
johlju authored Jul 26, 2017
1 parent 4e977ad commit 64b42ca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
- 3-SetQuorumToNodeAndFileShareMajority.ps1
- 4-SetQuorumToDiskOnly.ps1
- Added links to examples from README.md.
- Changes to xClusterPreferredOwner
- Enabled localization for all strings ([issue #86](https://github.com/PowerShell/xFailOverCluster/issues/86)).
- Fixed typo in the returned hash table from Get-TargetResource.

## 1.7.0.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath 'CommonResourceHelper.psm1')

$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xClusterPreferredOwner'

<#
.SYNOPSIS
Returns the current state of the failover cluster group and cluster
Expand Down Expand Up @@ -46,11 +51,10 @@ function Get-TargetResource
$Ensure = 'Present'
)

Write-Verbose -Message "Retrieving Owner information for cluster $ClusterName..."
Write-Verbose -Message ($script:localizedData.GetOwnerInformationForCluster -f $ClusterName)

$ownerNodes = @(

Write-Verbose -Message "Retrieving Owner information for Cluster Group $ClusterGroup"
Write-Verbose -Message ($script:localizedData.GetOwnerInformationForClusterGroup -f $ClusterGroup)
(((Get-ClusterGroup -Cluster $ClusterName) | Where-Object -FilterScript {
$_.Name -like $ClusterGroup
} | Get-ClusterOwnerNode).OwnerNodes).Name
Expand All @@ -59,7 +63,7 @@ function Get-TargetResource
{
foreach ($resource in $ClusterResources)
{
Write-Verbose -Message "Retrieving Owner information for Cluster Resource $resource"
Write-Verbose -Message ($script:localizedData.GetOwnerInformationForClusterResource -f $resource)
(((Get-ClusterResource -Cluster $ClusterName) | Where-Object -FilterScript {
$_.Name -like $resource
} | Get-ClusterOwnerNode).OwnerNodes).Name
Expand All @@ -71,7 +75,7 @@ function Get-TargetResource

@{
ClusterGroup = $ClusterGroup
Clustername = $ClusterName
ClusterName = $ClusterName
Nodes = $ownerNodes
ClusterResources = $ClusterResources
Ensure = $Ensure
Expand Down Expand Up @@ -125,12 +129,12 @@ function Set-TargetResource
$Ensure = 'Present'
)

Write-Verbose -Message "Retrieving all owners from cluster $ClusterName"
Write-Verbose -Message ($script:localizedData.GetAllNodesOfCluster -f $ClusterName)
$allNodes = (Get-ClusterNode -Cluster $ClusterName).Name

if ($Ensure -eq 'Present')
{
Write-Verbose -Message "Setting Cluster owners for Group $ClusterGroup to $Nodes"
Write-Verbose -Message ($script:localizedData.SetOwnerForClusterGroup -f $ClusterGroup, $Nodes)
$null = (Get-ClusterGroup -Cluster $ClusterName) | Where-Object -FilterScript {
$_.Name -like $ClusterGroup
} | Set-ClusterOwnerNode -Owners $Nodes
Expand All @@ -139,14 +143,14 @@ function Set-TargetResource
$_.OwnerGroup -like $ClusterGroup
} | Set-ClusterOwnerNode -Owners $allNodes

Write-Verbose -Message "Moving Cluster Group $ClusterGroup to node $($Nodes[0])"
Write-Verbose -Message ($script:localizedData.MoveClusterGroup -f $ClusterGroup, $Nodes[0])
$null = (Get-ClusterGroup -Cluster $ClusterName) | Where-Object -FilterScript {
$_.name -like $ClusterGroup
} | Move-ClusterGroup -Node $Nodes[0]

foreach ($resource in $ClusterResources)
{
Write-Verbose -Message "Setting Cluster owners for Resource $resource to $Nodes"
Write-Verbose -Message ($script:localizedData.SetOwnerForClusterResource -f $resource, $Nodes)
$null = (Get-ClusterResource -Cluster $ClusterName) | Where-Object -FilterScript {
$_.Name -like $resource
} | Set-ClusterOwnerNode -Owners $Nodes
Expand All @@ -155,7 +159,7 @@ function Set-TargetResource

if ($Ensure -eq 'Absent')
{
Write-Verbose -Message "Retrieving current cluster owners for group $ClusterGroup"
Write-Verbose -Message ($script:localizedData.GetOwnerInformationForClusterGroup -f $ClusterGroup)
$currentOwners = (((Get-ClusterGroup -Cluster $ClusterName) | Where-Object -FilterScript {
$_.Name -like $ClusterGroup
} | Get-ClusterOwnerNode).OwnerNodes).Name | Sort-Object -Unique
Expand All @@ -170,24 +174,24 @@ function Set-TargetResource
}
)

Write-Verbose -Message "Removing owners from group $($ClusterGroup): $Nodes"
Write-Verbose -Message ($script:localizedData.RemoveOwnerFromClusterGroup -f $ClusterGroup, $Nodes)
$null = (Get-ClusterGroup -Cluster $ClusterName) | Where-Object -FilterScript {
$_.Name -like $ClusterGroup
} | Set-ClusterOwnerNode $newOwners

Write-Verbose -Message "Setting Cluster owners for Group $ClusterGroup to $newOwners"
Write-Verbose -Message ($script:localizedData.SetOwnerForClusterGroup -f $ClusterGroup, $newOwners)
$null = (Get-ClusterResource) | Where-Object -FilterScript {
$_.OwnerGroup -like $ClusterGroup
} | Set-ClusterOwnerNode $allNodes

Write-Verbose -Message "Moving Cluster Group $ClusterGroup to node $($newOwners[0])"
Write-Verbose -Message ($script:localizedData.MoveClusterGroup -f $ClusterGroup, $newOwners[0])
$null = (Get-ClusterGroup -Cluster $ClusterName) | Where-Object -FilterScript {
$_.Name -like $ClusterGroup
} | Move-ClusterGroup -Node $newOwners[0]

foreach ($resource in $ClusterResources)
{
Write-Verbose -Message "Retrieving current cluster owners for resource $resource"
Write-Verbose -Message ($script:localizedData.GetOwnerInformationForClusterResource -f $resource)
$currentOwners = ((Get-ClusterResource -Cluster $ClusterName | Where-Object -FilterScript {
$_.Name -like $resource
} | Get-ClusterOwnerNode).OwnerNodes).Name | Sort-Object -Unique
Expand All @@ -202,7 +206,7 @@ function Set-TargetResource
}
)

Write-Verbose -Message "Setting Cluster owners for Resource $resource to $newOwners"
Write-Verbose -Message ($script:localizedData.SetOwnerForClusterResource -f $resource, $newOwners)
$null = Get-ClusterResource -Cluster $ClusterName | Where-Object -FilterScript {
$_.Name -like $resource
} | Set-ClusterOwnerNode -Owners $newOwners
Expand Down Expand Up @@ -259,7 +263,7 @@ function Test-TargetResource
$Ensure = 'Present'
)

Write-Verbose -Message "Testing Owner information for cluster $ClusterName..."
Write-Verbose -Message ($script:localizedData.TestOwnerInformationForCluster -f $ClusterName)

$getTargetResourceResult = (Get-TargetResource @PSBoundParameters).Nodes
$result = $true
Expand All @@ -270,7 +274,7 @@ function Test-TargetResource
{
if ($Nodes -notcontains $object)
{
Write-Verbose -Message "$object was NOT found as possible owner"
Write-Verbose -Message ($script:localizedData.WasNotFoundAsPossibleOwner -f $object)
$result = $false
}
}
Expand All @@ -279,7 +283,7 @@ function Test-TargetResource
{
if ($getTargetResourceResult -notcontains $object)
{
Write-Verbose -Message "$object was NOT found as possible owner"
Write-Verbose -Message ($script:localizedData.WasNotFoundAsPossibleOwner -f $object)
$result = $false
}
}
Expand All @@ -291,7 +295,7 @@ function Test-TargetResource
{
if ($Nodes -contains $object)
{
Write-Verbose -Message "$object WAS found as possible owner"
Write-Verbose -Message ($script:localizedData.WasFoundAsPossibleOwner -f $object)
$result = $false
}
}
Expand All @@ -300,7 +304,7 @@ function Test-TargetResource
{
if ($getTargetResourceResult -contains $object)
{
Write-Verbose -Message "$object WAS found as possible owner"
Write-Verbose -Message ($script:localizedData.WasFoundAsPossibleOwner -f $object)
$result = $false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Localized resources for xClusterPreferredOwner

ConvertFrom-StringData @'
GetOwnerInformationForCluster = Retrieving owner information for cluster {0}.
GetOwnerInformationForClusterGroup = Retrieving owner information for cluster role/group {0}.
GetOwnerInformationForClusterResource = Retrieving owner information for cluster resource {0}.
GetAllNodesOfCluster = Retrieving all nodes from cluster {0}.
SetOwnerForClusterGroup = Setting owners for cluster role/group {0} to {1}.
SetOwnerForClusterResource = Setting owners for cluster resource {0} to {1}.
MoveClusterGroup = Moving cluster role/group {0} to node {1}.
RemoveOwnerFromClusterGroup = Removing owners {1} from cluster role/group {0}.
TestOwnerInformationForCluster = Testing Owner information for cluster {0}.
WasFoundAsPossibleOwner = {0} was found as possible owner.
WasNotFoundAsPossibleOwner = {0} was NOT found as possible owner.
'@

0 comments on commit 64b42ca

Please sign in to comment.