Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts for creating cluster groups and affinity rules.
These scripts create DRS groups for virtual machines and hosts, and host affinity rules.
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
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,43 @@ | ||
<# | ||
.NOTES | ||
=========================================================================== | ||
Script name: New-ClusterHostGroup.ps1 | ||
Created on: 2016-10-25 | ||
Author: Peter D. Jorgensen (@pjorg, pjorg.com) | ||
Dependencies: None known | ||
===Tested Against Environment==== | ||
vSphere Version: 5.5, 6.0 | ||
PowerCLI Version: PowerCLI 6.5R1 | ||
PowerShell Version: 5.0 | ||
OS Version: Windows 10, Windows 7 | ||
=========================================================================== | ||
.DESCRIPTION | ||
Creates a DRS Host Group in a vSphere cluster. | ||
.Example | ||
$ProdCluster = Get-Cluster *prod* | ||
$OddHosts = $ProdCluster | Get-VMHost | ?{ $_.Name -match 'esxi-\d*[13579]+.\lab\.local' } | ||
.\New-ClusterHostGroup.ps1 -Name 'OddProdHosts' -Cluster $ProdCluster -VMHost $OddHosts | ||
#> | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$True,Position=1)] | ||
[String]$Name, | ||
[Parameter(Mandatory=$True,ValueFromPipeline=$True,Position=2)] | ||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$Cluster, | ||
[Parameter(Mandatory=$False,Position=3)] | ||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost[]]$VMHost | ||
) | ||
|
||
$NewGroup = New-Object VMware.Vim.ClusterHostGroup -Property @{ | ||
'Name'=$Name | ||
'Host'=$VMHost.Id | ||
} | ||
|
||
$spec = New-Object VMware.Vim.ClusterConfigSpecEx -Property @{ | ||
'GroupSpec'=(New-Object VMware.Vim.ClusterGroupSpec -Property @{ | ||
'Info'=$NewGroup | ||
}) | ||
} | ||
|
||
$ClusterToReconfig = Get-View -VIObject $Cluster -Property Name | ||
$ClusterToReconfig.ReconfigureComputeResource($spec, $true) |
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,43 @@ | ||
<# | ||
.NOTES | ||
=========================================================================== | ||
Script name: New-ClusterVmGroup.ps1 | ||
Created on: 2016-10-25 | ||
Author: Peter D. Jorgensen (@pjorg, pjorg.com) | ||
Dependencies: None known | ||
===Tested Against Environment==== | ||
vSphere Version: 5.5, 6.0 | ||
PowerCLI Version: PowerCLI 6.5R1 | ||
PowerShell Version: 5.0 | ||
OS Version: Windows 10, Windows 7 | ||
=========================================================================== | ||
.DESCRIPTION | ||
Creates a DRS VM Group in a vSphere cluster. | ||
.Example | ||
$ProdCluster = Get-Cluster *prod* | ||
$EvenVMs = $ProdCluster | Get-VM | ?{ $_.Name -match 'MyVM-\d*[02468]+' } | ||
.\New-ClusterVmGroup.ps1 -Name 'EvenVMs' -Cluster $ProdCluster -VM $EvenVMs | ||
#> | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$True,Position=1)] | ||
[String]$Name, | ||
[Parameter(Mandatory=$True,ValueFromPipeline=$True,Position=2)] | ||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$Cluster, | ||
[Parameter(Mandatory=$False,Position=3)] | ||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine[]]$VM | ||
) | ||
|
||
$NewGroup = New-Object VMware.Vim.ClusterVmGroup -Property @{ | ||
'Name'=$Name | ||
'VM'=$VM.Id | ||
} | ||
|
||
$spec = New-Object VMware.Vim.ClusterConfigSpecEx -Property @{ | ||
'GroupSpec'=(New-Object VMware.Vim.ClusterGroupSpec -Property @{ | ||
'Info'=$NewGroup | ||
}) | ||
} | ||
|
||
$ClusterToReconfig = Get-View -VIObject $Cluster -Property Name | ||
$ClusterToReconfig.ReconfigureComputeResource($spec, $true) |
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,48 @@ | ||
<# | ||
.NOTES | ||
=========================================================================== | ||
Script name: New-ClusterVmHostRule.ps1 | ||
Created on: 2016-10-25 | ||
Author: Peter D. Jorgensen (@pjorg, pjorg.com) | ||
Dependencies: None known | ||
===Tested Against Environment==== | ||
vSphere Version: 5.5, 6.0 | ||
PowerCLI Version: PowerCLI 6.5R1 | ||
PowerShell Version: 5.0 | ||
OS Version: Windows 10, Windows 7 | ||
=========================================================================== | ||
.DESCRIPTION | ||
Creates a VM to Host affinity rule in a vSphere cluster. | ||
.Example | ||
$ProdCluster = Get-Cluster *prod* | ||
.\New-ClusterVmHostRule.ps1 -Name 'Even VMs to Odd Hosts' -AffineHostGroupName 'OddHosts' -VMGroupName 'EvenVMs' -Enabled:$true -Cluster $ProdCluster | ||
#> | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$True,Position=1)] | ||
[String]$Name, | ||
[Parameter(Mandatory=$True,Position=2)] | ||
[String]$AffineHostGroupName, | ||
[Parameter(Mandatory=$True,Position=3)] | ||
[String]$VMGroupName, | ||
[Parameter(Mandatory=$False,Position=4)] | ||
[Switch]$Enabled=$True, | ||
[Parameter(Mandatory=$True,ValueFromPipeline=$True,Position=5)] | ||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$Cluster | ||
) | ||
|
||
$NewRule = New-Object VMware.Vim.ClusterVmHostRuleInfo -Property @{ | ||
'AffineHostGroupName'=$AffineHostGroupName | ||
'VmGroupName'=$VMGroupName | ||
'Enabled'=$Enabled | ||
'Name'=$Name | ||
} | ||
|
||
$spec = New-Object VMware.Vim.ClusterConfigSpecEx -Property @{ | ||
'RulesSpec'=(New-Object VMware.Vim.ClusterRuleSpec -Property @{ | ||
'Info'=$NewRule | ||
}) | ||
} | ||
|
||
$ClusterToReconfig = Get-View -VIObject $Cluster -Property Name | ||
$ClusterToReconfig.ReconfigureComputeResource($spec, $true) |