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

[Az.DataProtection] OnBoard workload AzureBlobs to Az.DataProtection preview module #14833

Merged
merged 4 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
490 changes: 290 additions & 200 deletions src/DataProtection/Az.DataProtection.format.ps1xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/DataProtection/Az.DataProtection.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 3/18/2021
# Generated on: 4/26/2021
#

@{
Expand Down Expand Up @@ -73,6 +73,7 @@ FunctionsToExport = 'Backup-AzDataProtectionBackupInstanceAdhoc',
'Edit-AzDataProtectionPolicyRetentionRuleClientObject',
'Edit-AzDataProtectionPolicyTagClientObject',
'Edit-AzDataProtectionPolicyTriggerClientObject',
'Find-AzDataProtectionRestorableTimeRange',
'Get-AzDataProtectionBackupInstance',
'Get-AzDataProtectionBackupPolicy',
'Get-AzDataProtectionBackupVault', 'Get-AzDataProtectionJob',
Expand Down
2 changes: 1 addition & 1 deletion src/DataProtection/Az.DataProtection.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if(-not $accountsModule) {
Write-Error "`nThis module requires $accountsName version 2.2.3 or greater. For installation instructions, please see: https://docs.microsoft.com/en-us/powershell/azure/install-az-ps" -ErrorAction Stop
} elseif (($accountsModule.Version -lt [System.Version]'2.2.3') -and (-not $localAccounts)) {
Write-Error "`nThis module requires $accountsName version 2.2.3 or greater. An earlier version of Az.Accounts is imported in the current PowerShell session. If you are running test, please try to remove '.PSSharedModules' in your home directory. Otherwise please open a new PowerShell session and import this module again.`nAdditionally, this error could indicate that multiple incompatible versions of Azure PowerShell modules are installed on your system. For troubleshooting information, please see: https://aka.ms/azps-version-error" -ErrorAction Stop
Write-Error "`nThis module requires $accountsName version 2.2.3 or greater. An earlier version of Az.Accounts is imported in the current PowerShell session. If you are running test, please try to add the switch '-RegenerateSupportModule' when executing 'test-module.ps1'. Otherwise please open a new PowerShell session and import this module again.`nAdditionally, this error could indicate that multiple incompatible versions of Azure PowerShell modules are installed on your system. For troubleshooting information, please see: https://aka.ms/azps-version-error" -ErrorAction Stop
}
Write-Information "Loaded Module '$($accountsModule.Name)'"

Expand Down
1 change: 1 addition & 0 deletions src/DataProtection/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* OnBoarded workload AzureBlobs

## Version 0.1.0
* First preview release for module Az.DataProtection
Expand Down
4 changes: 4 additions & 0 deletions src/DataProtection/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ $moduleName = 'Az.DataProtection'
$examplesFolder = Join-Path $PSScriptRoot 'examples'
$null = New-Item -ItemType Directory -Force -Path $examplesFolder

Write-Host -ForegroundColor Green 'Creating cmdlets for specified models...'
$modelCmdlets = @()
. (Join-Path $PSScriptRoot 'create-model-cmdlets.ps1') -Models $modelCmdlets

if($NoDocs) {
Write-Host -ForegroundColor Green 'Creating exports...'
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ExcludeDocs -ExamplesFolder $examplesFolder
Expand Down
2 changes: 1 addition & 1 deletion src/DataProtection/check-dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $tools = Join-Path $PSScriptRoot 'tools'
$resourceDir = Join-Path $tools 'Resources'
$resourceModule = Join-Path $HOME '.PSSharedModules\Resources\Az.Resources.TestSupport.psm1'

if ($Resources.IsPresent -and (-not (Test-Path -Path $resourceModule))) {
if ($Resources.IsPresent -and ((-not (Test-Path -Path $resourceModule)) -or $RegenerateSupportModule.IsPresent)) {
Write-Host -ForegroundColor Green "Building local Resource module used for test..."
Set-Location $resourceDir
$null = autorest .\readme.md --use:@autorest/[email protected] --output-folder=$HOME/.PSSharedModules/Resources
Expand Down
165 changes: 165 additions & 0 deletions src/DataProtection/create-model-cmdlets.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

param([string[]]$Models)

if ($Models.Count -eq 0)
{
return
}

$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
$ModuleName = 'Az.DataProtection'.Split(".")[1]
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
$null = New-Item -ItemType Directory -Force -Path $OutputDir

$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
$Content = ''
$null = $CsFiles | ForEach-Object -Process { if ($_.Name.Split('.').count -eq 2 )
{ $Content += get-content $_.fullname -raw
} }

$Tree = [Microsoft.CodeAnalysis.CSharp.SyntaxFactory]::ParseCompilationUnit($Content)
$Nodes = $Tree.ChildNodes().ChildNodes()
foreach ($Model in $Models)
{
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$Model") }
if ($InterfaceNode.count -eq 0) {
continue
}
# through a queue, we iterate all the parent models.
$Queue = @($InterfaceNode)
$visited = @("I$Model")
$AllInterfaceNodes = @()
while ($Queue.count -ne 0)
{
$AllInterfaceNodes += $Queue[0]
# Baselist contains the direct parent models.
foreach ($parent in $Queue[0].BaseList.Types)
{
if (($parent.Type.Right.Identifier.Value -ne 'IJsonSerializable') -and (-not $visited.Contains($parent.Type.Right.Identifier.Value)))
{
$Queue = [Array]$Queue + ($Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq $parent.Type.Right.Identifier.Value) })
$visited = [Array]$visited + $parent.Type.Right.Identifier.Value
}
}
$first, $Queue = $Queue
}

$Namespace = $InterfaceNode.Parent.Name
$ObjectType = $Model
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
# remove duplicated module name
if ($ObjectType.StartsWith($ModuleName)) {
$ModulePrefix = ''
} else {
$ModulePrefix = $ModuleName
}
$OutputPath = Join-Path -ChildPath "New-Az${ModulePrefix}${ObjectType}Object.ps1" -Path $OutputDir

$ParameterDefineScriptList = New-Object System.Collections.Generic.List[string]
$ParameterAssignScriptList = New-Object System.Collections.Generic.List[string]
foreach ($Node in $AllInterfaceNodes)
{
foreach ($Member in $Node.Members)
{
$Arguments = $Member.AttributeLists.Attributes.ArgumentList.Arguments
$Required = $false
$Description = ""
$Readonly = $False
foreach ($Argument in $Arguments)
{
if ($Argument.NameEquals.Name.Identifier.Value -eq "Required")
{
$Required = $Argument.Expression.Token.Value
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Description")
{
$Description = $Argument.Expression.Token.Value.Trim('.').replace('"', '`"')
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Readonly")
{
$Readonly = $Argument.Expression.Token.Value
}
}
if ($Readonly)
{
continue
}
$Identifier = $Member.Identifier.Value
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
$ParameterDefinePropertyList = New-Object System.Collections.Generic.List[string]
if ($Required)
{
$ParameterDefinePropertyList.Add("Mandatory")
}
if ($Description -ne "")
{
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
}
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]
[${Type}]
`$${Identifier}"
$ParameterDefineScriptList.Add($ParameterDefineScript)
$ParameterAssignScriptList.Add("
`$Object.${Identifier} = `$${Identifier}")
}
}
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
$ParameterAssignScript = $ParameterAssignScriptList | Join-String -Separator ""

$Script = "
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the \`"License\`");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an \`"AS IS\`" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Create a in-memory object for ${ObjectType}
.Description
Create a in-memory object for ${ObjectType}

.Outputs
${ObjectTypeWithNamespace}
.Link
https://docs.microsoft.com/powershell/module//az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
#>
function New-Az${ModulePrefix}${ObjectType}Object {
[OutputType('${ObjectTypeWithNamespace}')]
[CmdletBinding(PositionalBinding=`$false)]
Param(
${ParameterDefineScript}
)

process {
`$Object = [${ObjectTypeWithNamespace}]::New()
${ParameterAssignScript}
return `$Object
}
}
"
Set-Content -Path $OutputPath -Value $Script
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
foreach($argResponse in $argInstanceResponse)
{
$jsonStringResponse = $argResponse | ConvertTo-Json -Depth 100
$backupInstances += [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.BackupInstanceResource]::FromJsonString($jsonStringResponse)
$backupInstances += [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.BackupInstanceResource]::FromJsonString($jsonStringResponse)
}
return $backupInstances
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
foreach($jobresponse in $argJobResponse)
{
$jsonStringResponse = $jobresponse | ConvertTo-Json -Depth 100
$backupJobs += [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.AzureBackupJobResource]::FromJsonString($jsonStringResponse)
$backupJobs += [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.AzureBackupJobResource]::FromJsonString($jsonStringResponse)
}
return $backupJobs
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


function Initialize-AzDataProtectionBackupInstance {
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.IBackupInstanceResource')]
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.IBackupInstanceResource')]
[CmdletBinding(PositionalBinding=$false)]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Description('Initializes Backup instance Request object for configuring backup')]

Expand All @@ -29,7 +29,7 @@ function Initialize-AzDataProtectionBackupInstance {
process {

$manifest = LoadManifest -DatasourceType $DatasourceType.ToString()
$backupInstance = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.BackupInstance]::new()
$backupInstance = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.BackupInstance]::new()
$backupInstance.ObjectType = "BackupInstance"

if($PSBoundParameters.ContainsKey("DatasourceId"))
Expand All @@ -50,7 +50,7 @@ function Initialize-AzDataProtectionBackupInstance {



$backupInstanceResource = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.BackupInstanceResource]::new()
$backupInstanceResource = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.BackupInstanceResource]::new()
$backupInstanceResource.Property = $backupInstance

if($PSBoundParameters.ContainsKey("DatasourceId"))
Expand All @@ -68,7 +68,7 @@ function Initialize-AzDataProtectionBackupInstance {

if($DatasourceType.ToString() -eq "AzureDisk")
{
$operationalParam = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.AzureOperationalStoreParameters]::new()
$operationalParam = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.AzureOperationalStoreParameters]::new()
$operationalParam.DataStoreType = "OperationalStore"
$operationalParam.ObjectType = "AzureOperationalStoreParameters"
$operationalParam.ResourceGroupId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function New-AzDataProtectionBackupInstance {
${VaultName},

[Parameter(Mandatory, HelpMessage='Backup instance request object which will be used to configure backup')]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.IBackupInstanceResource]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.IBackupInstanceResource]
${BackupInstance},

[Parameter()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function Update-AzDataProtectionBackupInstanceAssociatedPolicy
{
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210201Preview.IBackupInstanceResource')]
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api202101.IBackupInstanceResource')]
[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess)]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Description('Updates associated policy for a given backup instance')]

Expand Down
Loading