Skip to content

Commit

Permalink
Move migrate to release-2021-05-25 (#15050)
Browse files Browse the repository at this point in the history
* Move Migrate to release-2021-05-25

* Update Changelog.md

Co-authored-by: azurepowershell <azurepowershell@ms.com>
  • Loading branch information
dolauli and azurepowershell authored May 19, 2021
1 parent 4746d10 commit ee8ea08
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/Migrate/Az.Migrate.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 3/23/2021
# Generated on: 5/19/2021
#

@{
Expand Down Expand Up @@ -45,7 +45,7 @@ PowerShellVersion = '5.1'
DotNetFrameworkVersion = '4.7.2'

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''
# ClrVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
Expand Down Expand Up @@ -124,7 +124,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Nullref Bug fixed in get discovered server and initialize replication infrastructure commandlets.'
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''
Expand Down
2 changes: 1 addition & 1 deletion src/Migrate/Az.Migrate.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/Migrate/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
* Fixed an issue in Initialize-AzMigrateReplicationInfrastructure.ps1

## Version 1.0.1
* Nullref Bug fixed in get discovered server and initialize replication infrastructure commandlets.
Expand Down
4 changes: 4 additions & 0 deletions src/Migrate/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ $moduleName = 'Az.Migrate'
$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/Migrate/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/powershell@3.0.414 --output-folder=$HOME/.PSSharedModules/Resources
Expand Down
165 changes: 165 additions & 0 deletions src/Migrate/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.Migrate'.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 @@ -179,31 +179,33 @@ public static int hashForArtifact(String artifact)
}
"@

# Get all appliances and sites in the project
$solution = Get-AzMigrateSolution -MigrateProjectName $ProjectName -ResourceGroupName $ResourceGroupName -Name "Servers-Migration-ServerMigration"
$VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split("/")[8]
#Get vault name from SMS solution.
$smsSolution = Get-AzMigrateSolution -MigrateProjectName $ProjectName -ResourceGroupName $ResourceGroupName -Name "Servers-Migration-ServerMigration"
$VaultName = $smsSolution.DetailExtendedDetail.AdditionalProperties.vaultId.Split("/")[8]

# Get all appliances and sites in the project from SDS solution.
$sdsSolution = Get-AzMigrateSolution -MigrateProjectName $ProjectName -ResourceGroupName $ResourceGroupName -Name "Servers-Discovery-ServerDiscovery"
$appMap = @{}

if ($null -ne $solution.DetailExtendedDetail["applianceNameToSiteIdMapV2"]) {
$appMapV2 = $solution.DetailExtendedDetail["applianceNameToSiteIdMapV2"] | ConvertFrom-Json
if ($null -ne $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV2"]) {
$appMapV2 = $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV2"] | ConvertFrom-Json
# Fetch all appliance from V2 map first. Then these can be updated if found again in V3 map.
foreach ($item in $appMapV2) {
$appMap[$item.ApplianceName] = $item.SiteId
}
}

if ($null -ne $solution.DetailExtendedDetail["applianceNameToSiteIdMapV3"]) {
$appMapV3 = $solution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] | ConvertFrom-Json
if ($null -ne $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV3"]) {
$appMapV3 = $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] | ConvertFrom-Json
foreach ($item in $appMapV3) {
$t = $item.psobject.properties
$appMap[$t.Name] = $t.Value.SiteId
}
}

if ($null -eq $solution.DetailExtendedDetail["applianceNameToSiteIdMapV2"] -And
$null -eq $solution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] ) {
throw "Server Migration Solution missing Appliance Details. Invalid Solution."
if ($null -eq $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV2"] -And
$null -eq $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] ) {
throw "Server Discovery Solution missing Appliance Details. Invalid Solution."
}

foreach ($eachApp in $appMap.GetEnumerator()) {
Expand Down Expand Up @@ -512,4 +514,4 @@ public static int hashForArtifact(String artifact)
Write-Host "Finished successfully."
return $true
}
}
}
10 changes: 5 additions & 5 deletions src/Migrate/generate-info.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"autorest_powershell": "3.0.424",
"autorest_modelerfour": "4.15.414",
"autorest": "`-- (empty)",
"swagger_commit": "5d617cf399806989dc17934ef5ca38f5545e8175",
"autorest_powershell": "3.0.430",
"autorest_core": "3.4.2",
"node": "v14.15.5",
"autorest_core": "3.2.1",
"swagger_commit": "2dd0ae5b100fee900dc0d2369401c6ab63e75f18",
"autorest": "`-- (empty)"
"autorest_modelerfour": "4.15.414"
}
Loading

0 comments on commit ee8ea08

Please sign in to comment.