|
| 1 | +<# |
| 2 | +Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +#> |
| 5 | + |
| 6 | +<# |
| 7 | +.SYNOPSIS |
| 8 | + Returns a list of all storage drives for a given cluster. |
| 9 | +
|
| 10 | +.DESCRIPTION |
| 11 | + Returns a list of all storage drives for a given cluster. |
| 12 | +
|
| 13 | +.PARAMETER Name |
| 14 | + Name of the storage drive. |
| 15 | +
|
| 16 | +.PARAMETER StorageSubSystem |
| 17 | + Storage subsystem in which the drive is located. |
| 18 | +
|
| 19 | +.PARAMETER ScaleUnit |
| 20 | + Name of the scale unit. |
| 21 | +
|
| 22 | +.PARAMETER Location |
| 23 | + Location of the resource. |
| 24 | +
|
| 25 | +.PARAMETER ResourceGroupName |
| 26 | + Resource group in which the resource provider has been registered. |
| 27 | +
|
| 28 | +.PARAMETER ResourceId |
| 29 | + The resource id. |
| 30 | +
|
| 31 | +.PARAMETER Filter |
| 32 | + OData filter parameter. |
| 33 | +
|
| 34 | +.PARAMETER Skip |
| 35 | + Skip the first N items as specified by the parameter value. |
| 36 | +
|
| 37 | +.PARAMETER Top |
| 38 | + Return the top N items as specified by the parameter value. Applies after the -Skip parameter. |
| 39 | +
|
| 40 | +.EXAMPLE |
| 41 | +
|
| 42 | + PS C:\> Get-AzsDrive -ScaleUnit S-Cluster -StorageSubSystem S-Cluster.azurestack.local |
| 43 | +
|
| 44 | + Get a list of all storage drives for a given cluster. |
| 45 | +
|
| 46 | +.EXAMPLE |
| 47 | +
|
| 48 | + PS C:\> Get-AzsDrive -ScaleUnit S-Cluster -StorageSubSystem S-Cluster.azurestack.local -Name a654528c-60bb-18e1-457c-51b7cdb7e14a |
| 49 | +
|
| 50 | + Get a storage drive by name for a given cluster. |
| 51 | +
|
| 52 | +#> |
| 53 | +function Get-AzsDrive { |
| 54 | + [OutputType([Microsoft.AzureStack.Management.Fabric.Admin.Models.Drive])] |
| 55 | + [CmdletBinding(DefaultParameterSetName = 'List')] |
| 56 | + param( |
| 57 | + [Parameter(Mandatory = $true, ParameterSetName = 'Get')] |
| 58 | + [ValidateNotNullOrEmpty()] |
| 59 | + [System.String] |
| 60 | + $Name, |
| 61 | + |
| 62 | + [Parameter(Mandatory = $true, ParameterSetName = 'Get')] |
| 63 | + [Parameter(Mandatory = $true, ParameterSetName = 'List')] |
| 64 | + [ValidateNotNullOrEmpty()] |
| 65 | + [System.String] |
| 66 | + $StorageSubSystem, |
| 67 | + |
| 68 | + [Parameter(Mandatory = $true, ParameterSetName = 'Get')] |
| 69 | + [Parameter(Mandatory = $true, ParameterSetName = 'List')] |
| 70 | + [ValidateNotNullOrEmpty()] |
| 71 | + [System.String] |
| 72 | + $ScaleUnit, |
| 73 | + |
| 74 | + [Parameter(Mandatory = $false, ParameterSetName = 'Get')] |
| 75 | + [Parameter(Mandatory = $false, ParameterSetName = 'List')] |
| 76 | + [System.String] |
| 77 | + $Location, |
| 78 | + |
| 79 | + [Parameter(Mandatory = $false, ParameterSetName = 'Get')] |
| 80 | + [Parameter(Mandatory = $false, ParameterSetName = 'List')] |
| 81 | + [ValidateLength(1, 90)] |
| 82 | + [System.String] |
| 83 | + $ResourceGroupName, |
| 84 | + |
| 85 | + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'ResourceId')] |
| 86 | + [Alias('id')] |
| 87 | + [ValidateNotNullOrEmpty()] |
| 88 | + [System.String] |
| 89 | + $ResourceId, |
| 90 | + |
| 91 | + [Parameter(Mandatory = $false, ParameterSetName = 'List')] |
| 92 | + [System.String] |
| 93 | + $Filter, |
| 94 | + |
| 95 | + [Parameter(Mandatory = $false, ParameterSetName = 'List')] |
| 96 | + [int] |
| 97 | + $Skip = -1, |
| 98 | + |
| 99 | + [Parameter(Mandatory = $false, ParameterSetName = 'List')] |
| 100 | + [int] |
| 101 | + $Top = -1 |
| 102 | + ) |
| 103 | + |
| 104 | + Begin { |
| 105 | + Initialize-PSSwaggerDependencies -Azure |
| 106 | + $tracerObject = $null |
| 107 | + if (('continue' -eq $DebugPreference) -or ('inquire' -eq $DebugPreference)) { |
| 108 | + $oldDebugPreference = $global:DebugPreference |
| 109 | + $global:DebugPreference = "continue" |
| 110 | + $tracerObject = New-PSSwaggerClientTracing |
| 111 | + Register-PSSwaggerClientTracing -TracerObject $tracerObject |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + Process { |
| 116 | + |
| 117 | + $StorageSubSystem = Get-ResourceNameSuffix -ResourceName $StorageSubSystem |
| 118 | + $ScaleUnit = Get-ResourceNameSuffix -ResourceName $ScaleUnit |
| 119 | + |
| 120 | + $NewServiceClient_params = @{ |
| 121 | + FullClientTypeName = 'Microsoft.AzureStack.Management.Fabric.Admin.FabricAdminClient' |
| 122 | + } |
| 123 | + |
| 124 | + $GlobalParameterHashtable = @{} |
| 125 | + $NewServiceClient_params['GlobalParameterHashtable'] = $GlobalParameterHashtable |
| 126 | + |
| 127 | + $GlobalParameterHashtable['SubscriptionId'] = $null |
| 128 | + if ($PSBoundParameters.ContainsKey('SubscriptionId')) { |
| 129 | + $GlobalParameterHashtable['SubscriptionId'] = $PSBoundParameters['SubscriptionId'] |
| 130 | + } |
| 131 | + |
| 132 | + $FabricAdminClient = New-ServiceClient @NewServiceClient_params |
| 133 | + |
| 134 | + $oDataQuery = "" |
| 135 | + if ($Filter) { |
| 136 | + $oDataQuery += "&`$Filter=$Filter" |
| 137 | + } |
| 138 | + $oDataQuery = $oDataQuery.Trim("&") |
| 139 | + |
| 140 | + if ('ResourceId' -eq $PsCmdlet.ParameterSetName) { |
| 141 | + $GetArmResourceIdParameterValue_params = @{ |
| 142 | + IdTemplate = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Fabric.Admin/fabricLocations/{location}/scaleUnits/{scaleUnit}/storageSubSystems/{storageSubSystem}/drives/{drive}' |
| 143 | + } |
| 144 | + |
| 145 | + $GetArmResourceIdParameterValue_params['Id'] = $ResourceId |
| 146 | + $ArmResourceIdParameterValues = Get-ArmResourceIdParameterValue @GetArmResourceIdParameterValue_params |
| 147 | + |
| 148 | + $ResourceGroupName = $ArmResourceIdParameterValues['resourceGroupName'] |
| 149 | + $location = $ArmResourceIdParameterValues['location'] |
| 150 | + $ScaleUnit = $ArmResourceIdParameterValues['scaleUnit'] |
| 151 | + $StorageSubSystem = $ArmResourceIdParameterValues['storageSubSystem'] |
| 152 | + $Name = $ArmResourceIdParameterValues['drive'] |
| 153 | + } else { |
| 154 | + if ([System.String]::IsNullOrEmpty($Location)) { |
| 155 | + $Location = (Get-AzureRMLocation).Location |
| 156 | + } |
| 157 | + if ([System.String]::IsNullOrEmpty($ResourceGroupName)) { |
| 158 | + $ResourceGroupName = "System.$Location" |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + $filterInfos = @( |
| 163 | + @{ |
| 164 | + 'Type' = 'powershellWildcard' |
| 165 | + 'Value' = $Name |
| 166 | + 'Property' = 'Name' |
| 167 | + }) |
| 168 | + $applicableFilters = Get-ApplicableFilters -Filters $filterInfos |
| 169 | + if ($applicableFilters | Where-Object { $_.Strict }) { |
| 170 | + Write-Verbose -Message 'Performing server-side call ''Get-AzsDrive -''' |
| 171 | + $serverSideCall_params = @{ |
| 172 | + |
| 173 | + } |
| 174 | + |
| 175 | + $serverSideResults = Get-AzsDrive @serverSideCall_params |
| 176 | + foreach ($serverSideResult in $serverSideResults) { |
| 177 | + $valid = $true |
| 178 | + foreach ($applicableFilter in $applicableFilters) { |
| 179 | + if (-not (Test-FilteredResult -Result $serverSideResult -Filter $applicableFilter.Filter)) { |
| 180 | + $valid = $false |
| 181 | + break |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + if ($valid) { |
| 186 | + $serverSideResult |
| 187 | + } |
| 188 | + } |
| 189 | + return |
| 190 | + } |
| 191 | + if ('Get' -eq $PsCmdlet.ParameterSetName -or 'ResourceId' -eq $PsCmdlet.ParameterSetName) { |
| 192 | + $Name = Get-ResourceNameSuffix -ResourceName $Name |
| 193 | + Write-Verbose -Message 'Performing operation GetWithHttpMessagesAsync on $FabricAdminClient.' |
| 194 | + $TaskResult = $FabricAdminClient.Drives.GetWithHttpMessagesAsync($ResourceGroupName, $Location, $ScaleUnit, $StorageSubSystem, $Name) |
| 195 | + } elseif ('List' -eq $PsCmdlet.ParameterSetName) { |
| 196 | + Write-Verbose -Message 'Performing operation ListWithHttpMessagesAsync on $FabricAdminClient.' |
| 197 | + $TaskResult = $FabricAdminClient.Drives.ListWithHttpMessagesAsync($ResourceGroupName, $Location, $ScaleUnit, $StorageSubSystem, $(if ($oDataQuery) { |
| 198 | + New-Object -TypeName "Microsoft.Rest.Azure.OData.ODataQuery``1[Microsoft.AzureStack.Management.Fabric.Admin.Models.Drive]" -ArgumentList $oDataQuery |
| 199 | + } else { |
| 200 | + $null |
| 201 | + })) |
| 202 | + } else { |
| 203 | + Write-Verbose -Message 'Failed to map parameter set to operation method.' |
| 204 | + throw 'Module failed to find operation to execute.' |
| 205 | + } |
| 206 | + |
| 207 | + if ($TaskResult) { |
| 208 | + $GetTaskResult_params = @{ |
| 209 | + TaskResult = $TaskResult |
| 210 | + } |
| 211 | + |
| 212 | + $TopInfo = @{ |
| 213 | + 'Count' = 0 |
| 214 | + 'Max' = $Top |
| 215 | + } |
| 216 | + $GetTaskResult_params['TopInfo'] = $TopInfo |
| 217 | + $SkipInfo = @{ |
| 218 | + 'Count' = 0 |
| 219 | + 'Max' = $Skip |
| 220 | + } |
| 221 | + $GetTaskResult_params['SkipInfo'] = $SkipInfo |
| 222 | + $PageResult = @{ |
| 223 | + 'Result' = $null |
| 224 | + } |
| 225 | + $GetTaskResult_params['PageResult'] = $PageResult |
| 226 | + $GetTaskResult_params['PageType'] = 'Microsoft.Rest.Azure.IPage[Microsoft.AzureStack.Management.Fabric.Admin.Models.Drive]' -as [Type] |
| 227 | + Get-TaskResult @GetTaskResult_params |
| 228 | + |
| 229 | + Write-Verbose -Message 'Flattening paged results.' |
| 230 | + while ($PageResult -and ($PageResult.ContainsKey('Page')) -and (Get-Member -InputObject $PageResult.Page -Name 'nextPageLink') -and $PageResult.Page.'nextPageLink' -and (($TopInfo -eq $null) -or ($TopInfo.Max -eq -1) -or ($TopInfo.Count -lt $TopInfo.Max))) { |
| 231 | + Write-Debug -Message "Retrieving next page: $($PageResult.Page.'nextPageLink')" |
| 232 | + $TaskResult = $FabricAdminClient.Drives.ListNextWithHttpMessagesAsync($PageResult.Page.'nextPageLink') |
| 233 | + $PageResult.Page = $null |
| 234 | + $GetTaskResult_params['TaskResult'] = $TaskResult |
| 235 | + $GetTaskResult_params['PageResult'] = $PageResult |
| 236 | + Get-TaskResult @GetTaskResult_params |
| 237 | + } |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + End { |
| 242 | + if ($tracerObject) { |
| 243 | + $global:DebugPreference = $oldDebugPreference |
| 244 | + Unregister-PSSwaggerClientTracing -TracerObject $tracerObject |
| 245 | + } |
| 246 | + } |
| 247 | +} |
| 248 | + |
0 commit comments