-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
667 additions
and
255 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,41 +1,41 @@ | ||
# DRSRule PowerShell module ReadMe# | ||
# DRSRule PowerShell module ReadMe | ||
The DRSRule module allows you to work with all types of vSphere DRS rules. | ||
The module provides support for VM and VMHost groups. And, it works with affinity/anti-affinity VM rules and VM to VMHost rules. | ||
|
||
### Brief info on module ### | ||
### Brief info on module | ||
The module came from the need for DRS rule/group info gathering, exporting, and recreating. Initially there were some code blocks for exporting rule info and for importing again those rules, but things evolved into a module. | ||
|
||
A couple of examples: | ||
- Export rule/group info: `Export-DrsRule -Path c:\someFolder\myDrsRuleAndGroupInfo.json` | ||
- Import rule/group info: `Import-DrsRule -Path c:\someFolder\myDrsRuleAndGroupInfo.json` | ||
|
||
### How to set up the DRSRule module for use ### | ||
### How to set up the DRSRule module for use | ||
* Download and extract the module .zip file | ||
* `Unblock-File` on the extracted contents | ||
* `Import-Module <path\To\ModuleFolder>` | ||
* Use `Get-Help` as per usual for cmdlet help and examples | ||
|
||
### Cmdlets in this module ### | ||
### Cmdlets in this module | ||
- Export/Import: | ||
- Export-DrsRule | ||
- Import-DrsRule | ||
- `Export-DrsRule` | ||
- `Import-DrsRule` | ||
- Get: | ||
- Get-DrsVMGroup | ||
- Get-DrsVMHostGroup | ||
- Get-DrsVMToVMHostRule | ||
- Get-DrsVMToVMRule | ||
- `Get-DrsVMGroup` | ||
- `Get-DrsVMHostGroup` | ||
- `Get-DrsVMToVMHostRule` | ||
- `Get-DrsVMToVMRule` | ||
- New: | ||
- New-DrsVMGroup | ||
- New-DrsVMHostGroup | ||
- New-DrsVMToVMHostRule | ||
- New-DrsVMToVMRule | ||
- `New-DrsVMGroup` | ||
- `New-DrsVMHostGroup` | ||
- `New-DrsVMToVMHostRule` | ||
- `New-DrsVMToVMRule` | ||
- Remove: | ||
- Remove-DrsVMGroup | ||
- Remove-DrsVMHostGroup | ||
- Remove-DrsVMToVMHostRule | ||
- Remove-DrsVMToVMRule | ||
- `Remove-DrsVMGroup` | ||
- `Remove-DrsVMHostGroup` | ||
- `Remove-DrsVMToVMHostRule` | ||
- `Remove-DrsVMToVMRule` | ||
- Set: | ||
- Set-DrsVMGroup | ||
- Set-DrsVMHostGroup | ||
- Set-DrsVMToVMHostRule | ||
- Set-DrsVMToVMRule | ||
- `Set-DrsVMGroup` | ||
- `Set-DrsVMHostGroup` | ||
- `Set-DrsVMToVMHostRule` | ||
- `Set-DrsVMToVMRule` |
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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
## DRSRule PowerShell module ## | ||
## DRSRule PowerShell module | ||
|
||
### Changelog ### | ||
### Changelog | ||
|
||
### v1.0.1 ### | ||
### v1.1.0 | ||
29 Mar 2017 | ||
- \[enhancement] added support for enhancement suggested in [Issue #7](https://github.com/PowerCLIGoodies/DRSRule/issues/7): get a DRS `VMGroup` by the related VM; while at it, added support for: | ||
- getting a DRS `VMHostGroup` by the related VMHost | ||
- getting DRS `VMToVMRule` by VM | ||
- getting DRS `VMToVMHostRule` by VM or VMHost | ||
- \[improvment] added [Pester](https://github.com/pester/Pester) tests for `Get-Drs*` cmdlets | ||
|
||
### v1.0.1 | ||
|
||
30 Jun 2015 | ||
|
||
- \[bugfix] fixed rare problem with creating new `DRSRule.VMHostGroup` for VMHost group item where `Host` property of corresponding `VMware.Vim.ClusterHostGroup` object is empty and user is using PowerShell v5 (credit [gpduck](https://github.com/gpduck)). This was in `Get-DrsVMHostGroup`. Updated similar situation for functions `Get-DrsVMGroup` and `Get-DrsVMToVMRule`. | ||
|
||
### v1.0.0 ### | ||
### v1.0.0 | ||
|
||
Initial release, 21 Jan 2015. |
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 @@ | ||
<# .Description | ||
Initialization code for use by multiple *.Tests.ps1 files for testing DRSRule PowerShell module | ||
#> | ||
param ( | ||
## Name of the vCenter cluster to use in the DRSRule testing | ||
[parameter(Mandatory=$true)][string]$Cluster | ||
) | ||
|
||
$strThisModuleName = "DRSRule" | ||
## if module not already loaded, try to load it (assumes that module is in PSModulePath) | ||
if (-not ($oModuleInfo = Get-Module $strThisModuleName)) { | ||
$oModuleInfo = Import-Module $strThisModuleName -PassThru | ||
if (-not ($oModuleInfo -is [System.Management.Automation.PSModuleInfo])) {Throw "Could not load module '$strThisModuleName' -- is it available in the PSModulePath? You can manually load the module and start tests again"} | ||
} ## end if | ||
Write-Verbose -Verbose ("Starting testing of module '{0}' (version '{1}' from '{2}')" -f $oModuleInfo.Name, $oModuleInfo.Version, $oModuleInfo.Path) | ||
|
||
## get the VIServer connection to use | ||
$oVIServerConnectionToUse = if (-not (($global:DefaultVIServers | Measure-Object).Count -gt 0)) { | ||
$hshParamForConnectVIServer = @{Server = $(Read-Host -Prompt "vCenter server to which to connect for testing")} | ||
Connect-VIServer @hshParamForConnectVIServer | ||
} ## end if | ||
else {$global:DefaultVIServers[0]} | ||
Write-Verbose -Verbose "Testing using VIServer of name '$($oVIServerConnectionToUse.Name)'" | ||
|
||
|
||
## get the cluster use for testing | ||
$oTmpClusterToUse = Get-Cluster -Name $Cluster | Select-Object -First 1 | ||
Write-Verbose -Verbose "Testing using cluster '$oTmpClusterToUse'" | ||
|
||
return $oTmpClusterToUse |
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,107 @@ | ||
<# .Description | ||
Pester tests for DRSRule PowerShell module. Expects that: | ||
0) DRSRule module is already loaded (but, will try to load it if not) | ||
1) a connection to at least one vCenter is in place (but, will prompt for XMS to which to connect if not) | ||
2) there are one or more existing DRS items of each type to test (VMGroup, VMHostGroup, etc.) in the specified cluster | ||
.Example | ||
Invoke-Pester -Script @{Path = '\\some\path\DRSRule\testing\DRSRule.Tests_Get_Unit.ps1'; Parameters = @{Cluster = "myFavoriteCluster"}} | ||
Invokes the tests in said Tests script, passing the given Cluster parameter value, to be used for the cluster-specific tests | ||
#> | ||
param ( | ||
## Name of the vCenter cluster to use in the DRSRule testing | ||
[parameter(Mandatory=$true)][string]$Cluster | ||
) | ||
|
||
## initialize things, preparing for tests | ||
$oClusterToUse = & $PSScriptRoot\DRSRule.TestingInit.ps1 -Cluster $Cluster | ||
## hashtable of DRSRule object short typename to VMware "real" object full typename info, to be used with -ReturnRawGroup testing | ||
$hshDrsruletypeToVMwareTypeInfo = @{ | ||
VMGroup = "VMware.Vim.ClusterVmGroup" | ||
VMHostGroup = "VMware.Vim.ClusterHostGroup" | ||
VMToVMRule = "VMware.Vim.ClusterAffinityRuleSpec", "VMware.Vim.ClusterAntiAffinityRuleSpec" | ||
VMToVMHostRule = "VMware.Vim.ClusterVmHostRuleInfo" | ||
} ## end hsh | ||
|
||
|
||
## for each of the object types whose typenames match the object name in the cmdlet noun, test getting such an object | ||
$arrObjectTypesToGet = Write-Output VMGroup, VMHostGroup, VMtoVMRule, VMToVMHostRule | ||
$arrObjectTypesToGet | Foreach-Object { | ||
Describe -Tags "Get" -Name "Get-Drs$_" { | ||
It "Gets a DRSRule $_ object" { | ||
$arrReturnTypes = if ($arrTmpObj = Invoke-Command -ScriptBlock {& "Get-Drs$_" | Select-Object -First 2}) {$arrTmpObj | Get-Member -ErrorAction:Stop | Select-Object -Unique -ExpandProperty TypeName} else {$null} | ||
New-Variable -Name "bGetsOnly${_}Type" -Value ($arrReturnTypes -eq "DRSRule.$_") | ||
|
||
## gets only the desired object type should be $true | ||
(Get-Variable -ValueOnly -Name "bGetsOnly${_}Type") | Should Be $true | ||
} | ||
|
||
It "Gets a 'raw' $($hshDrsruletypeToVMwareTypeInfo[$_] -join ' or ') object, via -ReturnRawGroup" { | ||
$strThisTypeShortname = $_ | ||
## should be only one type returned | ||
$arrReturnTypes = if ($arrTmpObj = Invoke-Command -ScriptBlock {& "Get-Drs$_" -ReturnRaw | Select-Object -First 2}) {$arrTmpObj | Get-Member -ErrorAction:Stop | Select-Object -Unique -ExpandProperty TypeName} else {$null} | ||
New-Variable -Name "bGetsOnly${_}Type" -Value (($arrReturnTypes | Foreach-Object {$hshDrsruletypeToVMwareTypeInfo[$strThisTypeShortname] -contains $_}) -notcontains $false) | ||
|
||
## gets only the desired object type should be $true | ||
(Get-Variable -ValueOnly -Name "bGetsOnly${_}Type") | Should Be $true | ||
} | ||
|
||
It "Gets a DRSRule $_ object (from specific cluster, '$oClusterToUse')" { | ||
$arrReturnTypes = if ($arrTmpObj = Invoke-Command -ScriptBlock {& "Get-Drs$_" -Cluster $oClusterToUse | Select-Object -First 1}) {$arrTmpObj | Get-Member -ErrorAction:Stop | Select-Object -Unique -ExpandProperty TypeName} else {$null} | ||
New-Variable -Name "bGetsOnly${_}Type" -Value ($arrReturnTypes -eq "DRSRule.$_") | ||
$bGetsItemFromSpecifiedCluster = $arrTmpObj.Cluster -eq $oClusterToUse.Name | ||
|
||
## gets only the desired object type should be $true | ||
(Get-Variable -ValueOnly -Name "bGetsOnly${_}Type") | Should Be $true | ||
$bGetsItemFromSpecifiedCluster | Should Be $true | ||
} | ||
|
||
It "Gets a DRSRule $_ object (from specific cluster, '$oClusterToUse', taking cluster from pipeline)" { | ||
$arrReturnTypes = if ($arrTmpObj = Invoke-Command -ScriptBlock {$oClusterToUse | & "Get-Drs$_" | Select-Object -First 1}) {$arrTmpObj | Get-Member -ErrorAction:Stop | Select-Object -Unique -ExpandProperty TypeName} else {$null} | ||
New-Variable -Name "bGetsOnly${_}Type" -Value ($arrReturnTypes -eq "DRSRule.$_") | ||
$bGetsItemFromSpecifiedCluster = $arrTmpObj.Cluster -eq $oClusterToUse.Name | ||
|
||
## gets only the desired object type should be $true | ||
(Get-Variable -ValueOnly -Name "bGetsOnly${_}Type") | Should Be $true | ||
$bGetsItemFromSpecifiedCluster | Should Be $true | ||
} | ||
} | ||
} | ||
|
||
|
||
Describe -Tags "Get" -Name "Get-DrsVMToVMRule" { | ||
It "Gets a DRS VM-To-VM Rule from related VM" { | ||
$oSomeRule = Get-DrsVMToVMRule -ReturnRaw | Select-Object -First 1 | ||
$morefVMInRule = $oSomeRule.Vm | Select-Object -Last 1 | ||
|
||
$bGetsRuleByRelatedVM = (Get-VM -Id $morefVMInRule | Get-DrsVMToVMRule).Name -contains $oSomeRule.Name | ||
|
||
## gets only the desired object type should be $true | ||
$bGetsRuleByRelatedVM | Should Be $true | ||
} | ||
} | ||
|
||
|
||
Describe -Tags "Get" -Name "Get-DrsVMToVMHostRule" { | ||
It "Gets a DRS VM-To-VMHost Rule from related VM" { | ||
## get a DRS VM-to-VMHost rule where the associated DRS VMGroup has one or more VMs in it | ||
$oSomeRule = Get-DrsVMToVMHostRule | Where-Object {(Get-DrsVMGroup -Name $_.VmGroupName -Cluster $_.Cluster -ReturnRaw).Vm.Count -gt 0} | Select-Object -First 1 | ||
$morefVMInRule = (Get-DrsVMGroup -Name $oSomeRule.VmGroupName -Cluster $oSomeRule.Cluster -ReturnRaw).Vm | Select-Object -Last 1 | ||
|
||
$bGetsRuleByRelatedVM = (Get-VM -Id $morefVMInRule | Get-DrsVMToVMHostRule).Name -contains $oSomeRule.Name | ||
|
||
## gets only the desired object type should be $true | ||
$bGetsRuleByRelatedVM | Should Be $true | ||
} | ||
|
||
It "Gets a DRS VM-To-VMHost Rule from related VMHost" { | ||
## get a DRS VM-to-VMHost rule where the associated DRS VMHostGroup has one or more VMHosts in it | ||
$oSomeRule = Get-DrsVMToVMHostRule | Where-Object {(Get-DrsVMHostGroup -Name ($_.AffineHostGroupName,$_.AntiAffineHostGroupName | Where-Object {-not [String]::IsNullOrEmpty($_)}) -Cluster $_.Cluster -ReturnRaw).Host.Count -gt 0} | Select-Object -First 1 | ||
$morefVMHostInRule = (Get-DrsVMHostGroup -Name ($oSomeRule.AffineHostGroupName,$oSomeRule.AntiAffineHostGroupName | Where-Object {-not [String]::IsNullOrEmpty($_)}) -Cluster $oSomeRule.Cluster -ReturnRaw).Host | Select-Object -Last 1 | ||
|
||
$bGetsRuleByRelatedVMHost = (Get-VMHost -Id $morefVMHostInRule | Get-DrsVMToVMHostRule).Name -contains $oSomeRule.Name | ||
|
||
## gets only the desired object type should be $true | ||
$bGetsRuleByRelatedVMHost | Should Be $true | ||
} | ||
} |
Oops, something went wrong.