Skip to content

Commit

Permalink
Merge pull request #7762 from zyxyoshine/Oct2018FRP
Browse files Browse the repository at this point in the history
[AzureStack] Update Fabric Admin Powershell cmdlet
  • Loading branch information
Maddie Clayton committed Nov 16, 2018
2 parents 477ec6a + 38daeb2 commit 622034f
Show file tree
Hide file tree
Showing 24 changed files with 4,112 additions and 275 deletions.
Expand Up @@ -40,8 +40,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AzureStack.Management.Fabric.Admin, Version=0.2.0-preview">
<HintPath>..\..\..\packages\Microsoft.AzureStack.Management.Fabric.Admin.0.2.0-preview\lib\net452\Microsoft.AzureStack.Management.Fabric.Admin.dll</HintPath>
<Reference Include="Microsoft.AzureStack.Management.Fabric.Admin, Version=1.8.0-preview">
<HintPath>..\..\..\packages\Microsoft.AzureStack.Management.Fabric.Admin.1.8.0-preview\lib\net452\Microsoft.AzureStack.Management.Fabric.Admin.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Expand Up @@ -17,7 +17,7 @@ Licensed under the MIT License. See License.txt in the project root for license
RootModule = 'Azs.Fabric.Admin.psm1'

# Version number of this module.
ModuleVersion = '0.2.1'
ModuleVersion = '0.3.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -81,14 +81,15 @@ Licensed under the MIT License. See License.txt in the project root for license
'Get-AzsSlbMuxInstance', 'Get-AzsScaleUnit', 'New-AzsIpPool',
'Start-AzsInfrastructureRoleInstance', 'Get-AzsMacAddressPool',
'Get-AzsEdgeGatewayPool', 'Restart-AzsInfrastructureRole',
'Get-AzsInfrastructureVolume', 'Enable-AzsScaleUnitNode',
'Get-AzsVolume', 'Enable-AzsScaleUnitNode',
'Get-AzsInfrastructureRole', 'Get-AzsIpPool', 'Get-AzsLogicalSubnet',
'Get-AzsEdgeGateway', 'Get-AzsInfrastructureLocation',
'Get-AzsStoragePool', 'Suspend-AzsInfrastructureRoleInstance',
'Start-AzsScaleUnitNode', 'Get-AzsInfrastructureRoleInstance',
'Repair-AzsScaleUnitNode', 'Stop-AzsInfrastructureRoleInstance',
'Stop-AzsScaleUnitNode', 'Add-AzsScaleUnitNode',
'New-AzsScaleUnitNodeObject'
'New-AzsScaleUnitNodeObject', 'Get-AzsDrive',
'Get-AzsStorageSubSystem'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()
Expand All @@ -97,7 +98,9 @@ Licensed under the MIT License. See License.txt in the project root for license
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()
AliasesToExport = @(
'Get-AzsInfrastructureVolume'
)

# DSC resources to export from this module
# DscResourcesToExport = @()
Expand Down Expand Up @@ -126,9 +129,13 @@ Licensed under the MIT License. See License.txt in the project root for license
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '## 2018.10.28
* Bug fixes
* Fixed a bug in Add-AzsScaleUnitNode
ReleaseNotes = '## 2018.11.5
* New cmdlet (The features are supported by Azure Stack 1811+)
* Get-AzsDrive
* Get-AzsVolume
* Get-AzsStorageSubSystem
* Deprecation
* Get-AzsInfrastructureVolume is an alias now to the cmdlet Get-AzsVolume
'

} # End of PSData hashtable
Expand Down
Expand Up @@ -19,6 +19,48 @@
-->
## Current Release

## Version 0.3.0
* New cmdlet (The features are supported by Azure Stack 1811+)
* Get-AzsDrive
* Get-AzsVolume
* Get-AzsStorageSubSystem
* Deprecation
* Get-AzsInfrastructureVolume is an alias now to the cmdlet Get-AzsVolume

## Version 0.2.1
* Bug fixes
* Fixed a bug in Add-AzsScaleUnitNode

## Version 0.2.0
* New Module dependencies
* AzureRM.Profile
* AzureRM.Resources
* New cmdlet
* Add-AzsScaleUnitNode
* New-AzsScaleUnitNodeObject
* Support handling names of nested resources
* Add-AzsScaleUnitNode
* Disable-AzsScaleUnitNode
* Enable-AzsScaleUnitNode
* Get-AzsEdgeGateway
* Get-AzsEdgeGatewayPool
* Get-AzsInfrastructureRole
* Get-AzsInfrastructureRoleInstance
* Get-AzsInfrastructureShare
* Get-AzsInfrastructureVolume
* Get-AzsIpPool
* Get-AzsLogicalNetwork
* Get-AzsLogicalSubnet
* Get-AzsMacAddressPool
* Get-AzsScaleUnit
* Get-AzsScaleUnitNode
* Get-AzsSlbMuxInstance
* Get-AzsStoragePool
* Get-AzsStorageSystem
* Repair-AzsScaleUnitNode
* Restart-AzsInfrastructureRole
* Restart-AzsInfrastructureRoleInstance
* Start-AzsInfrastructureRoleInstance
* Start-AzsScaleUnitNode
* Stop-AzsInfrastructureRoleInstance
* Stop-AzsScaleUnitNode
@@ -0,0 +1,248 @@
<#
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See License.txt in the project root for license information.
#>

<#
.SYNOPSIS
Returns a list of all storage drives for a given cluster.
.DESCRIPTION
Returns a list of all storage drives for a given cluster.
.PARAMETER Name
Name of the storage drive.
.PARAMETER StorageSubSystem
Storage subsystem in which the drive is located.
.PARAMETER ScaleUnit
Name of the scale unit.
.PARAMETER Location
Location of the resource.
.PARAMETER ResourceGroupName
Resource group in which the resource provider has been registered.
.PARAMETER ResourceId
The resource id.
.PARAMETER Filter
OData filter parameter.
.PARAMETER Skip
Skip the first N items as specified by the parameter value.
.PARAMETER Top
Return the top N items as specified by the parameter value. Applies after the -Skip parameter.
.EXAMPLE
PS C:\> Get-AzsDrive -ScaleUnit S-Cluster -StorageSubSystem S-Cluster.azurestack.local
Get a list of all storage drives for a given cluster.
.EXAMPLE
PS C:\> Get-AzsDrive -ScaleUnit S-Cluster -StorageSubSystem S-Cluster.azurestack.local -Name a654528c-60bb-18e1-457c-51b7cdb7e14a
Get a storage drive by name for a given cluster.
#>
function Get-AzsDrive {
[OutputType([Microsoft.AzureStack.Management.Fabric.Admin.Models.Drive])]
[CmdletBinding(DefaultParameterSetName = 'List')]
param(
[Parameter(Mandatory = $true, ParameterSetName = 'Get')]
[ValidateNotNullOrEmpty()]
[System.String]
$Name,

[Parameter(Mandatory = $true, ParameterSetName = 'Get')]
[Parameter(Mandatory = $true, ParameterSetName = 'List')]
[ValidateNotNullOrEmpty()]
[System.String]
$StorageSubSystem,

[Parameter(Mandatory = $true, ParameterSetName = 'Get')]
[Parameter(Mandatory = $true, ParameterSetName = 'List')]
[ValidateNotNullOrEmpty()]
[System.String]
$ScaleUnit,

[Parameter(Mandatory = $false, ParameterSetName = 'Get')]
[Parameter(Mandatory = $false, ParameterSetName = 'List')]
[System.String]
$Location,

[Parameter(Mandatory = $false, ParameterSetName = 'Get')]
[Parameter(Mandatory = $false, ParameterSetName = 'List')]
[ValidateLength(1, 90)]
[System.String]
$ResourceGroupName,

[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'ResourceId')]
[Alias('id')]
[ValidateNotNullOrEmpty()]
[System.String]
$ResourceId,

[Parameter(Mandatory = $false, ParameterSetName = 'List')]
[System.String]
$Filter,

[Parameter(Mandatory = $false, ParameterSetName = 'List')]
[int]
$Skip = -1,

[Parameter(Mandatory = $false, ParameterSetName = 'List')]
[int]
$Top = -1
)

Begin {
Initialize-PSSwaggerDependencies -Azure
$tracerObject = $null
if (('continue' -eq $DebugPreference) -or ('inquire' -eq $DebugPreference)) {
$oldDebugPreference = $global:DebugPreference
$global:DebugPreference = "continue"
$tracerObject = New-PSSwaggerClientTracing
Register-PSSwaggerClientTracing -TracerObject $tracerObject
}
}

Process {

$StorageSubSystem = Get-ResourceNameSuffix -ResourceName $StorageSubSystem
$ScaleUnit = Get-ResourceNameSuffix -ResourceName $ScaleUnit

$NewServiceClient_params = @{
FullClientTypeName = 'Microsoft.AzureStack.Management.Fabric.Admin.FabricAdminClient'
}

$GlobalParameterHashtable = @{}
$NewServiceClient_params['GlobalParameterHashtable'] = $GlobalParameterHashtable

$GlobalParameterHashtable['SubscriptionId'] = $null
if ($PSBoundParameters.ContainsKey('SubscriptionId')) {
$GlobalParameterHashtable['SubscriptionId'] = $PSBoundParameters['SubscriptionId']
}

$FabricAdminClient = New-ServiceClient @NewServiceClient_params

$oDataQuery = ""
if ($Filter) {
$oDataQuery += "&`$Filter=$Filter"
}
$oDataQuery = $oDataQuery.Trim("&")

if ('ResourceId' -eq $PsCmdlet.ParameterSetName) {
$GetArmResourceIdParameterValue_params = @{
IdTemplate = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Fabric.Admin/fabricLocations/{location}/scaleUnits/{scaleUnit}/storageSubSystems/{storageSubSystem}/drives/{drive}'
}

$GetArmResourceIdParameterValue_params['Id'] = $ResourceId
$ArmResourceIdParameterValues = Get-ArmResourceIdParameterValue @GetArmResourceIdParameterValue_params

$ResourceGroupName = $ArmResourceIdParameterValues['resourceGroupName']
$location = $ArmResourceIdParameterValues['location']
$ScaleUnit = $ArmResourceIdParameterValues['scaleUnit']
$StorageSubSystem = $ArmResourceIdParameterValues['storageSubSystem']
$Name = $ArmResourceIdParameterValues['drive']
} else {
if ([System.String]::IsNullOrEmpty($Location)) {
$Location = (Get-AzureRMLocation).Location
}
if ([System.String]::IsNullOrEmpty($ResourceGroupName)) {
$ResourceGroupName = "System.$Location"
}
}

$filterInfos = @(
@{
'Type' = 'powershellWildcard'
'Value' = $Name
'Property' = 'Name'
})
$applicableFilters = Get-ApplicableFilters -Filters $filterInfos
if ($applicableFilters | Where-Object { $_.Strict }) {
Write-Verbose -Message 'Performing server-side call ''Get-AzsDrive -'''
$serverSideCall_params = @{

}

$serverSideResults = Get-AzsDrive @serverSideCall_params
foreach ($serverSideResult in $serverSideResults) {
$valid = $true
foreach ($applicableFilter in $applicableFilters) {
if (-not (Test-FilteredResult -Result $serverSideResult -Filter $applicableFilter.Filter)) {
$valid = $false
break
}
}

if ($valid) {
$serverSideResult
}
}
return
}
if ('Get' -eq $PsCmdlet.ParameterSetName -or 'ResourceId' -eq $PsCmdlet.ParameterSetName) {
$Name = Get-ResourceNameSuffix -ResourceName $Name
Write-Verbose -Message 'Performing operation GetWithHttpMessagesAsync on $FabricAdminClient.'
$TaskResult = $FabricAdminClient.Drives.GetWithHttpMessagesAsync($ResourceGroupName, $Location, $ScaleUnit, $StorageSubSystem, $Name)
} elseif ('List' -eq $PsCmdlet.ParameterSetName) {
Write-Verbose -Message 'Performing operation ListWithHttpMessagesAsync on $FabricAdminClient.'
$TaskResult = $FabricAdminClient.Drives.ListWithHttpMessagesAsync($ResourceGroupName, $Location, $ScaleUnit, $StorageSubSystem, $(if ($oDataQuery) {
New-Object -TypeName "Microsoft.Rest.Azure.OData.ODataQuery``1[Microsoft.AzureStack.Management.Fabric.Admin.Models.Drive]" -ArgumentList $oDataQuery
} else {
$null
}))
} else {
Write-Verbose -Message 'Failed to map parameter set to operation method.'
throw 'Module failed to find operation to execute.'
}

if ($TaskResult) {
$GetTaskResult_params = @{
TaskResult = $TaskResult
}

$TopInfo = @{
'Count' = 0
'Max' = $Top
}
$GetTaskResult_params['TopInfo'] = $TopInfo
$SkipInfo = @{
'Count' = 0
'Max' = $Skip
}
$GetTaskResult_params['SkipInfo'] = $SkipInfo
$PageResult = @{
'Result' = $null
}
$GetTaskResult_params['PageResult'] = $PageResult
$GetTaskResult_params['PageType'] = 'Microsoft.Rest.Azure.IPage[Microsoft.AzureStack.Management.Fabric.Admin.Models.Drive]' -as [Type]
Get-TaskResult @GetTaskResult_params

Write-Verbose -Message 'Flattening paged results.'
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))) {
Write-Debug -Message "Retrieving next page: $($PageResult.Page.'nextPageLink')"
$TaskResult = $FabricAdminClient.Drives.ListNextWithHttpMessagesAsync($PageResult.Page.'nextPageLink')
$PageResult.Page = $null
$GetTaskResult_params['TaskResult'] = $TaskResult
$GetTaskResult_params['PageResult'] = $PageResult
Get-TaskResult @GetTaskResult_params
}
}
}

End {
if ($tracerObject) {
$global:DebugPreference = $oldDebugPreference
Unregister-PSSwaggerClientTracing -TracerObject $tracerObject
}
}
}

0 comments on commit 622034f

Please sign in to comment.