Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 487 - Expose volume letter in "Get-RubrikVolumeGroup" #492

Merged
merged 19 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## 2019-10-30

### Added [-DetailedObject parameter in Get-RubrikVolumeGroup]

* Changed default display of Get-RubrikVolumeGroup
* Added `-DetailedObject` parameter to `Get-RubrikVolumeGroup`
* Addresses [Issue 487](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/487)

### Fixed [Documenation referencing _local]

* Replaced occurances of _local with local within documenation around the primary_cluster_id.
Expand Down
10 changes: 8 additions & 2 deletions Rubrik/ObjectDefinitions/Rubrik.VolumeGroup.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
<TableColumnHeader>
<Label>SLA Domain</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Includes</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
Expand All @@ -34,8 +37,11 @@
<PropertyName>effectiveSlaDomainName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>id</PropertyName>
<PropertyName>includes</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
Expand Down
39 changes: 32 additions & 7 deletions Rubrik/Public/Get-RubrikVolumeGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Get-RubrikVolumeGroup
Retrieves details on one or more volume groups known to a Rubrik cluster

.DESCRIPTION
The Get-RubrikVolumeGroup cmdlet is used to pull a detailed data set from a Rubrik cluster on any number of volume groups
The Get-RubrikVolumeGroup cmdlet is used to pull a detailed data set from a Rubrik cluster on any number of volume groups. By default the 'Includes' property is not populated, unless when querying by ID or by using the -DetailedObject parameter

.NOTES
Written by Pierre Flammer for community usage
Expand All @@ -26,6 +26,14 @@ function Get-RubrikVolumeGroup
.EXAMPLE
Get-RubrikVolumeGroup -Relic
This will return all removed volume groups that were formerly protected by Rubrik.

.EXAMPLE
Get-RubrikVolumeGroup -DetailedObject
This will return full details on all volume groups available on the Rubrik Cluster, this query will take longer as multiple API calls are required. The 'Includes' property will be populated

.EXAMPLE
Get-RubrikVolumeGroup -Id VolumeGroup:::205b0b65-b90c-48c5-9cab-66b95ed18c0f
This will return full details on for the specified VolumeGroup ID
#>

[CmdletBinding()]
Expand All @@ -39,7 +47,7 @@ function Get-RubrikVolumeGroup
[Switch]$Relic,
# SLA Domain policy assigned to the volume group
[String]$SLA,
# 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')]
[String]$PrimaryClusterID,
# Volume group id
Expand All @@ -48,6 +56,8 @@ function Get-RubrikVolumeGroup
# SLA id value
[Alias('effective_sla_domain_id')]
[String]$SLAID,
# DetailedObject will retrieved the detailed VolumeGroup object, the default behavior of the API is to only retrieve a subset of the full VolumeGroup object unless we query directly by ID. Using this parameter does affect performance as more data will be retrieved and more API-queries will be performed.
[Switch]$DetailedObject,
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
# API version
Expand All @@ -71,7 +81,6 @@ function Get-RubrikVolumeGroup
$resources = Get-RubrikAPIData -endpoint $function
Write-Verbose -Message "Load API data for $($resources.Function)"
Write-Verbose -Message "Description: $($resources.Description)"

}

Process {
Expand All @@ -89,9 +98,25 @@ function Get-RubrikVolumeGroup
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result
$result = Set-ObjectTypeName -TypeName $resources.ObjectTName -result $result

return $result


# If the Get-RubrikVolumeGroup function has been called with the -DetailedObject parameter a separate API query will be performed if the initial query was not based on ID
if (($DetailedObject) -and (-not $PSBoundParameters.containskey('id'))) {
for ($i = 0; $i -lt @($result).Count; $i++) {
$Percentage = [int]($i/@($result).count*100)
Write-Progress -Activity "DetailedObject queries in Progress, $($i+1) out of $(@($result).count)" -Status "$Percentage% Complete:" -PercentComplete $Percentage
$updatedresult = Get-RubrikVolumeGroup -id $result[$i].id | ForEach-Object {
Select-Object -InputObject $_ -Property *,@{
name = 'includes'
expression = {
if ($null -ne $_.volumes) {$_.volumes.mountPoints}
}
}
}
Set-ObjectTypeName -TypeName $resources.ObjectTName -result $updatedresult
}
} else {
$result = Set-ObjectTypeName -TypeName $resources.ObjectTName -result $result
return $result
}
} # End of process
} # End of function
49 changes: 42 additions & 7 deletions Tests/Get-RubrikVolumeGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Describe -Name 'Public/Get-RubrikVolumeGroup' -Tag 'Public', 'Get-RubrikVolumeGr
@{ 'slaid' = 'SLA1' }
}
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
@{
@{
'name' = 'VG01'
'id' = 'VolumeGroup:::11111'
'hostname' = 'VG01.domain.local'
Expand All @@ -41,15 +41,15 @@ Describe -Name 'Public/Get-RubrikVolumeGroup' -Tag 'Public', 'Get-RubrikVolumeGr
'effectiveSlaDomainId' = 'SLA1'
'hostId' = 'host02'
},
@{
@{
'name' = 'VG03'
'id' = 'VolumeGroup:::33333'
'hostname' = 'VG03.domain.local'
'effectiveSlaDomainName' = 'Silver'
'effectiveSlaDomainId' = 'SLA2'
'hostId' = 'host03'
},
@{
@{
'name' = 'VG04'
'id' = 'VolumeGroup:::44444'
'hostname' = 'VG04.domain.local'
Expand All @@ -73,13 +73,48 @@ Describe -Name 'Public/Get-RubrikVolumeGroup' -Tag 'Public', 'Get-RubrikVolumeGr
It -Name 'Missing ID Exception' -Test {
{ Get-RubrikVolumeGroup -id } |
Should -Throw "Missing an argument for parameter 'id'. Specify a parameter of type 'System.String' and try again."
}
}
It -Name 'Missing Name Exception' -Test {
{ Get-RubrikVolumeGroup -name } |
Should -Throw "Missing an argument for parameter 'name'. Specify a parameter of type 'System.String' and try 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 3
Assert-MockCalled -CommandName Test-RubrikSLA -ModuleName 'Rubrik' -Exactly 1
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 3
}
Context -Name 'DetailedObject querying' {
Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith {}
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
@{
'name' = 'VG01'
'id' = 'VolumeGroup:::11111'
'hostname' = 'VG01.domain.local'
'effectiveSlaDomainName' = 'Gold'
'effectiveSlaDomainId' = 'SLA1'
'hostId' = 'host01'
'volumes' = @{
'mountPoints' = '/etc'
}
}
}

It -Name 'Requesting all should return count of 1' -Test {
@( Get-RubrikVolumeGroup).Count |
Should -BeExactly 1
}

It -Name 'Requesting volumes property should be /etc when queried by id' -Test {
( Get-RubrikVolumeGroup -id VolumeGroup:::11111).Volumes.mountPoints |
Should -BeExactly '/etc'
}

It -Name 'Requesting volumes property should be /etc when using -DetailedObject' -Test {
( Get-RubrikVolumeGroup -DetailedObject).Volumes.mountPoints |
Should -BeExactly '/etc'
}
Assert-VerifiableMock
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 4
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 4
}
}