Skip to content

Commit ee8ea08

Browse files
dolauliazurepowershell
andauthored
Move migrate to release-2021-05-25 (#15050)
* Move Migrate to release-2021-05-25 * Update Changelog.md Co-authored-by: azurepowershell <[email protected]>
1 parent 4746d10 commit ee8ea08

19 files changed

+218
-41
lines changed

src/Migrate/Az.Migrate.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Microsoft Corporation
55
#
6-
# Generated on: 3/23/2021
6+
# Generated on: 5/19/2021
77
#
88

99
@{
@@ -45,7 +45,7 @@ PowerShellVersion = '5.1'
4545
DotNetFrameworkVersion = '4.7.2'
4646

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

5050
# Processor architecture (None, X86, Amd64) required by this module
5151
# ProcessorArchitecture = ''
@@ -124,7 +124,7 @@ PrivateData = @{
124124
# IconUri = ''
125125

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

129129
# Prerelease string of this module
130130
# Prerelease = ''

src/Migrate/Az.Migrate.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
if(-not $accountsModule) {
3535
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
3636
} elseif (($accountsModule.Version -lt [System.Version]'2.2.3') -and (-not $localAccounts)) {
37-
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
37+
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
3838
}
3939
Write-Information "Loaded Module '$($accountsModule.Name)'"
4040

src/Migrate/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed an issue in Initialize-AzMigrateReplicationInfrastructure.ps1
2122

2223
## Version 1.0.1
2324
* Nullref Bug fixed in get discovered server and initialize replication infrastructure commandlets.

src/Migrate/build-module.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ $moduleName = 'Az.Migrate'
120120
$examplesFolder = Join-Path $PSScriptRoot 'examples'
121121
$null = New-Item -ItemType Directory -Force -Path $examplesFolder
122122

123+
Write-Host -ForegroundColor Green 'Creating cmdlets for specified models...'
124+
$modelCmdlets = @()
125+
. (Join-Path $PSScriptRoot 'create-model-cmdlets.ps1') -Models $modelCmdlets
126+
123127
if($NoDocs) {
124128
Write-Host -ForegroundColor Green 'Creating exports...'
125129
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ExcludeDocs -ExamplesFolder $examplesFolder

src/Migrate/check-dependencies.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $tools = Join-Path $PSScriptRoot 'tools'
5353
$resourceDir = Join-Path $tools 'Resources'
5454
$resourceModule = Join-Path $HOME '.PSSharedModules\Resources\Az.Resources.TestSupport.psm1'
5555

56-
if ($Resources.IsPresent -and (-not (Test-Path -Path $resourceModule))) {
56+
if ($Resources.IsPresent -and ((-not (Test-Path -Path $resourceModule)) -or $RegenerateSupportModule.IsPresent)) {
5757
Write-Host -ForegroundColor Green "Building local Resource module used for test..."
5858
Set-Location $resourceDir
5959
$null = autorest .\readme.md --use:@autorest/powershell@3.0.414 --output-folder=$HOME/.PSSharedModules/Resources

src/Migrate/create-model-cmdlets.ps1

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
param([string[]]$Models)
16+
17+
if ($Models.Count -eq 0)
18+
{
19+
return
20+
}
21+
22+
$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
23+
$ModuleName = 'Az.Migrate'.Split(".")[1]
24+
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
25+
$null = New-Item -ItemType Directory -Force -Path $OutputDir
26+
27+
$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
28+
$Content = ''
29+
$null = $CsFiles | ForEach-Object -Process { if ($_.Name.Split('.').count -eq 2 )
30+
{ $Content += get-content $_.fullname -raw
31+
} }
32+
33+
$Tree = [Microsoft.CodeAnalysis.CSharp.SyntaxFactory]::ParseCompilationUnit($Content)
34+
$Nodes = $Tree.ChildNodes().ChildNodes()
35+
foreach ($Model in $Models)
36+
{
37+
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$Model") }
38+
if ($InterfaceNode.count -eq 0) {
39+
continue
40+
}
41+
# through a queue, we iterate all the parent models.
42+
$Queue = @($InterfaceNode)
43+
$visited = @("I$Model")
44+
$AllInterfaceNodes = @()
45+
while ($Queue.count -ne 0)
46+
{
47+
$AllInterfaceNodes += $Queue[0]
48+
# Baselist contains the direct parent models.
49+
foreach ($parent in $Queue[0].BaseList.Types)
50+
{
51+
if (($parent.Type.Right.Identifier.Value -ne 'IJsonSerializable') -and (-not $visited.Contains($parent.Type.Right.Identifier.Value)))
52+
{
53+
$Queue = [Array]$Queue + ($Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq $parent.Type.Right.Identifier.Value) })
54+
$visited = [Array]$visited + $parent.Type.Right.Identifier.Value
55+
}
56+
}
57+
$first, $Queue = $Queue
58+
}
59+
60+
$Namespace = $InterfaceNode.Parent.Name
61+
$ObjectType = $Model
62+
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
63+
# remove duplicated module name
64+
if ($ObjectType.StartsWith($ModuleName)) {
65+
$ModulePrefix = ''
66+
} else {
67+
$ModulePrefix = $ModuleName
68+
}
69+
$OutputPath = Join-Path -ChildPath "New-Az${ModulePrefix}${ObjectType}Object.ps1" -Path $OutputDir
70+
71+
$ParameterDefineScriptList = New-Object System.Collections.Generic.List[string]
72+
$ParameterAssignScriptList = New-Object System.Collections.Generic.List[string]
73+
foreach ($Node in $AllInterfaceNodes)
74+
{
75+
foreach ($Member in $Node.Members)
76+
{
77+
$Arguments = $Member.AttributeLists.Attributes.ArgumentList.Arguments
78+
$Required = $false
79+
$Description = ""
80+
$Readonly = $False
81+
foreach ($Argument in $Arguments)
82+
{
83+
if ($Argument.NameEquals.Name.Identifier.Value -eq "Required")
84+
{
85+
$Required = $Argument.Expression.Token.Value
86+
}
87+
if ($Argument.NameEquals.Name.Identifier.Value -eq "Description")
88+
{
89+
$Description = $Argument.Expression.Token.Value.Trim('.').replace('"', '`"')
90+
}
91+
if ($Argument.NameEquals.Name.Identifier.Value -eq "Readonly")
92+
{
93+
$Readonly = $Argument.Expression.Token.Value
94+
}
95+
}
96+
if ($Readonly)
97+
{
98+
continue
99+
}
100+
$Identifier = $Member.Identifier.Value
101+
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
102+
$ParameterDefinePropertyList = New-Object System.Collections.Generic.List[string]
103+
if ($Required)
104+
{
105+
$ParameterDefinePropertyList.Add("Mandatory")
106+
}
107+
if ($Description -ne "")
108+
{
109+
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
110+
}
111+
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
112+
$ParameterDefineScript = "
113+
[Parameter($ParameterDefineProperty)]
114+
[${Type}]
115+
`$${Identifier}"
116+
$ParameterDefineScriptList.Add($ParameterDefineScript)
117+
$ParameterAssignScriptList.Add("
118+
`$Object.${Identifier} = `$${Identifier}")
119+
}
120+
}
121+
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
122+
$ParameterAssignScript = $ParameterAssignScriptList | Join-String -Separator ""
123+
124+
$Script = "
125+
# ----------------------------------------------------------------------------------
126+
#
127+
# Copyright Microsoft Corporation
128+
# Licensed under the Apache License, Version 2.0 (the \`"License\`");
129+
# you may not use this file except in compliance with the License.
130+
# You may obtain a copy of the License at
131+
# http://www.apache.org/licenses/LICENSE-2.0
132+
# Unless required by applicable law or agreed to in writing, software
133+
# distributed under the License is distributed on an \`"AS IS\`" BASIS,
134+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135+
# See the License for the specific language governing permissions and
136+
# limitations under the License.
137+
# ----------------------------------------------------------------------------------
138+
139+
<#
140+
.Synopsis
141+
Create a in-memory object for ${ObjectType}
142+
.Description
143+
Create a in-memory object for ${ObjectType}
144+
145+
.Outputs
146+
${ObjectTypeWithNamespace}
147+
.Link
148+
https://docs.microsoft.com/powershell/module/az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
149+
#>
150+
function New-Az${ModulePrefix}${ObjectType}Object {
151+
[OutputType('${ObjectTypeWithNamespace}')]
152+
[CmdletBinding(PositionalBinding=`$false)]
153+
Param(
154+
${ParameterDefineScript}
155+
)
156+
157+
process {
158+
`$Object = [${ObjectTypeWithNamespace}]::New()
159+
${ParameterAssignScript}
160+
return `$Object
161+
}
162+
}
163+
"
164+
Set-Content -Path $OutputPath -Value $Script
165+
}

src/Migrate/custom/Initialize-AzMigrateReplicationInfrastructure.ps1

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,31 +179,33 @@ public static int hashForArtifact(String artifact)
179179
}
180180
"@
181181

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

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

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

196-
if ($null -ne $solution.DetailExtendedDetail["applianceNameToSiteIdMapV3"]) {
197-
$appMapV3 = $solution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] | ConvertFrom-Json
198+
if ($null -ne $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV3"]) {
199+
$appMapV3 = $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] | ConvertFrom-Json
198200
foreach ($item in $appMapV3) {
199201
$t = $item.psobject.properties
200202
$appMap[$t.Name] = $t.Value.SiteId
201203
}
202204
}
203205

204-
if ($null -eq $solution.DetailExtendedDetail["applianceNameToSiteIdMapV2"] -And
205-
$null -eq $solution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] ) {
206-
throw "Server Migration Solution missing Appliance Details. Invalid Solution."
206+
if ($null -eq $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV2"] -And
207+
$null -eq $sdsSolution.DetailExtendedDetail["applianceNameToSiteIdMapV3"] ) {
208+
throw "Server Discovery Solution missing Appliance Details. Invalid Solution."
207209
}
208210

209211
foreach ($eachApp in $appMap.GetEnumerator()) {
@@ -512,4 +514,4 @@ public static int hashForArtifact(String artifact)
512514
Write-Host "Finished successfully."
513515
return $true
514516
}
515-
}
517+
}

src/Migrate/generate-info.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"autorest_powershell": "3.0.424",
3-
"autorest_modelerfour": "4.15.414",
2+
"autorest": "`-- (empty)",
3+
"swagger_commit": "5d617cf399806989dc17934ef5ca38f5545e8175",
4+
"autorest_powershell": "3.0.430",
5+
"autorest_core": "3.4.2",
46
"node": "v14.15.5",
5-
"autorest_core": "3.2.1",
6-
"swagger_commit": "2dd0ae5b100fee900dc0d2369401c6ab63e75f18",
7-
"autorest": "`-- (empty)"
7+
"autorest_modelerfour": "4.15.414"
88
}

0 commit comments

Comments
 (0)