diff --git a/CHANGELOG.md b/CHANGELOG.md index a00fdde74..9f2043511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,14 +26,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/). * Now uses new private function instead of the custom code in the function +## 2019-08-08 + +### Changed [Get-RubrikManagedVolume] + +* Changed behavior of `-Relic` switch, by default now retrieves both relic and non-relics. `-Relic` or `-Relic:$false` in addition to that +* Added additional unit test +* Created parameter sets and improved parameter validation [Issue 351](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/351) + ## 2019-08-06 ### Changed [Get-RubrikSnapshot] -* Added -Latest parameter to return latest snapshot data -* Added -Range to use with -Date. This specifies how many days away from the given date to search for the closest matching snapshot. Defaults to one day. -* Added -ExactMatch to use with -Date. This causes no results to be returned if a matching date isn't found. Otherwise, all snapshots are returned if no match is made. -* Added unit tests for Get-RubrikSnapshot -* Updated Test-DateDifference, a private function used by Get-RubrikSnapshot, to support the -Range parameter + +* Added `-Latest` parameter to return latest snapshot data +* Added `-Range` to use with `-Date`. This specifies how many days away from the given date to search for the closest matching snapshot. Defaults to one day. +* Added `-ExactMatch` to use with `-Date`. This causes no results to be returned if a matching date isn't found. Otherwise, all snapshots are returned if no match is made. +* Added unit tests for `Get-RubrikSnapshot` +* Updated `Test-DateDifference`, a private function used by `Get-RubrikSnapshot`, to support the `-Range` parameter ## 2019-07-31 diff --git a/Rubrik/Public/Get-RubrikManagedVolume.ps1 b/Rubrik/Public/Get-RubrikManagedVolume.ps1 index 2b739e7e8..96440ebeb 100644 --- a/Rubrik/Public/Get-RubrikManagedVolume.ps1 +++ b/Rubrik/Public/Get-RubrikManagedVolume.ps1 @@ -18,6 +18,21 @@ function Get-RubrikManagedVolume .LINK http://rubrikinc.github.io/rubrik-sdk-for-powershell/ + .EXAMPLE + Get-RubrikManagedVolume + + Retrieves all Rubrik Managed Volumes, active and relics + + .EXAMPLE + Get-RubrikManagedVolume -Relic + + Retrieves all Rubrik Managed Volumes that are relics + + .EXAMPLE + Get-RubrikManagedVolume -Relic:$false + + Retrieves all Rubrik Managed Volumes that are not relics + .EXAMPLE Get-RubrikManagedVolume -name sqltest @@ -34,23 +49,46 @@ function Get-RubrikManagedVolume Get the managed volume named 'Bar'. #> - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'Name')] Param( # id of managed volume - [Parameter(ValueFromPipelineByPropertyName = $true)] + [Parameter( + ParameterSetName='ID', + Mandatory = $true, + Position = 0, + ValueFromPipelineByPropertyName = $true + )] + [ValidateNotNullOrEmpty()] [String]$id, # Name of managed volume + [Parameter( + ParameterSetName='Name', + Position = 0, + ValueFromPipelineByPropertyName = $true + )] + [ValidateNotNullOrEmpty()] [String]$Name, # SLA name that the managed volume is protected under + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='ID')] + [ValidateNotNullOrEmpty()] [String]$SLA, # SLA id that the managed volume is protected under + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='ID')] [Alias('effective_sla_domain_id')] + [ValidateNotNullOrEmpty()] [String]$SLAID, # Filter results to include only relic (removed) databases + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='ID')] [Alias('is_relic')] [Switch]$Relic, - # Filter the summary information based on the primarycluster_id of the primary Rubrik cluster. Use **_local** as the primary_cluster_id of the Rubrik cluster that is hosting the current REST API session. + # Filter the summary information based on the primarycluster_id of the primary Rubrik cluster. Use local as the primary_cluster_id of the Rubrik cluster that is hosting the current REST API session. [Alias('primary_cluster_id')] + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='ID')] + [ValidateNotNullOrEmpty()] [String]$PrimaryClusterID, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, @@ -76,6 +114,10 @@ function Get-RubrikManagedVolume Write-Verbose -Message "Load API data for $($resources.Function)" Write-Verbose -Message "Description: $($resources.Description)" + # If the switch parameter was not explicitly specified remove from query params + if(-not $PSBoundParameters.ContainsKey('Relic')) { + $Resources.Query.Remove('is_relic') + } } Process { diff --git a/Tests/Get-RubrikManagedVolume.Tests.ps1 b/Tests/Get-RubrikManagedVolume.Tests.ps1 index faaeeb44b..24f08424e 100644 --- a/Tests/Get-RubrikManagedVolume.Tests.ps1 +++ b/Tests/Get-RubrikManagedVolume.Tests.ps1 @@ -22,7 +22,7 @@ Describe -Name 'Public/Get-RubrikManagedVolume' -Tag 'Public', 'Get-RubrikManage Context -Name 'Results Filtering' { Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith {} Mock -CommandName Test-RubrikSLA -Verifiable -ModuleName 'Rubrik' -MockWith { - @{ 'slaid' = '12345678-1234-abcd-8910-1234567890ab' } + @{ 'slaid' = '12345678-1234-abcd-8910-1234567890cab' } } Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith { @{ @@ -31,8 +31,8 @@ Describe -Name 'Public/Get-RubrikManagedVolume' -Tag 'Public', 'Get-RubrikManage 'primaryClusterId' = 'local' 'name' = 'OracleMV' 'isRelic' = 'False' - 'effectiveSlaDomainId' = '12345678-1234-abcd-8910-1234567890ab' - 'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890ab' + 'effectiveSlaDomainId' = '12345678-1234-abcd-8910-1234567890cab' + 'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890cab' 'effectiveSlaDomainName' = 'Gold' 'configuredSlaDomainName' = 'Gold' }, @@ -46,33 +46,48 @@ Describe -Name 'Public/Get-RubrikManagedVolume' -Tag 'Public', 'Get-RubrikManage 'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890abc' 'effectiveSlaDomainName' = 'Bronze' 'configuredSlaDomainName' = 'Bronze' + }, + @{ + 'id' = 'ManagedVolume:::33333' + 'isDeleted' = 'False' + 'primaryClusterId' = 'local' + 'name' = 'LinMV' + 'isRelic' = 'True' + 'effectiveSlaDomainId' = '12345678-1234-abcd-8910-1234567890bac' + 'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890bac' + 'effectiveSlaDomainName' = 'Silver' + 'configuredSlaDomainName' = 'Silver' } } It -Name 'Should Return count of 2' -Test { (Get-RubrikManagedVolume).Count | - Should -BeExactly 2 + Should -BeExactly 3 } It -Name 'Name filter non existant should return count of 0' -Test { (Get-RubrikManagedVolume -Name 'nonexistant').Count | Should -BeExactly 0 - } + } It -Name 'Name Filter - ID should be ManagedVolume:::22222' -Test { (Get-RubrikManagedVolume -name 'SQLMV').id | Should -BeExactly 'ManagedVolume:::22222' - } + } It -Name 'SLA Filter should be count of 1' -Test { (Get-RubrikManagedVolume -SLA "Bronze" | Measure-Object).Count | Should -BeExactly 1 - } + } It -Name 'Missing ID Exception' -Test { { Get-RubrikManagedVolume -id } | Should -Throw "Missing an argument for parameter 'id'. Specify a parameter of type 'System.String' and try again." - } + } + It -Name 'Null or empty ID Exception' -Test { + { Get-RubrikManagedVolume -id '' } | + Should -Throw "Cannot validate argument on parameter 'id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again." + } Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 4 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 4 } } \ No newline at end of file