Skip to content

Commit e820710

Browse files
Migrate Migrate from generation to main (#25087)
* Move Migrate to main * Update ChangeLog.md --------- Co-authored-by: NoriZC <[email protected]>
1 parent 1fa33ee commit e820710

File tree

55 files changed

+978
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+978
-339
lines changed

src/Migrate/Migrate.Autorest/build-module.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
1313
# is regenerated.
1414
# ----------------------------------------------------------------------------------
15-
param([switch]$Isolated, [switch]$Run, [switch]$Test, [switch]$Docs, [switch]$Pack, [switch]$Code, [switch]$Release, [switch]$Debugger, [switch]$NoDocs)
15+
param([switch]$Isolated, [switch]$Run, [switch]$Test, [switch]$Docs, [switch]$Pack, [switch]$Code, [switch]$Release, [switch]$Debugger, [switch]$NoDocs, [Switch]$DisableAfterBuildTasks)
1616
$ErrorActionPreference = 'Stop'
1717

1818
if($PSEdition -ne 'Core') {
@@ -169,4 +169,14 @@ if (Test-Path (Join-Path $PSScriptRoot 'generate-portal-ux.ps1'))
169169
. (Join-Path $PSScriptRoot 'generate-portal-ux.ps1')
170170
}
171171

172+
if (-not $DisableAfterBuildTasks){
173+
$afterBuildTasksPath = Join-Path $PSScriptRoot ''
174+
$afterBuildTasksArgs = ConvertFrom-Json 'true' -AsHashtable
175+
if(Test-Path -Path $afterBuildTasksPath -PathType leaf){
176+
Write-Host -ForegroundColor Green 'Running after build tasks...'
177+
. $afterBuildTasksPath @afterBuildTasksArgs
178+
}
179+
}
180+
181+
172182
Write-Host -ForegroundColor Green '-------------Done-------------'

src/Migrate/Migrate.Autorest/custom/Get-AzMigrateHCIServerReplication.ps1

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -162,58 +162,45 @@ function Get-AzMigrateHCIServerReplication {
162162

163163
# Occasionally, Get Machine Site will not return machine site even when the site exist,
164164
# hence retry get machine site.
165-
$attempts = 4
166-
for ($i = 1; $i -le $attempts; $i++) {
167-
try {
168-
if ($siteType -eq $SiteTypes.VMwareSites) {
169-
$siteObject = Az.Migrate\Get-AzMigrateSite @PSBoundParameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
170-
}
171-
elseif ($siteType -eq $SiteTypes.HyperVSites) {
172-
$siteObject = Az.Migrate.Internal\Get-AzMigrateHyperVSite @PSBoundParameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
173-
}
165+
if ($siteType -eq $SiteTypes.VMwareSites) {
166+
$siteObject = InvokeAzMigrateGetCommandWithRetries `
167+
-CommandName 'Az.Migrate\Get-AzMigrateSite' `
168+
-Parameters $PSBoundParameters `
169+
-ErrorMessage "Machine site '$siteName' with Type '$siteType' not found."
170+
} elseif ($siteType -eq $SiteTypes.HyperVSites) {
171+
$siteObject = InvokeAzMigrateGetCommandWithRetries `
172+
-CommandName 'Az.Migrate.Internal\Get-AzMigrateHyperVSite' `
173+
-Parameters $PSBoundParameters `
174+
-ErrorMessage "Machine site '$siteName' with Type '$siteType' not found."
175+
}
174176

175-
if ($null -eq $siteObject) {
176-
throw "Machine site not found."
177-
}
178-
else {
179-
$ProjectName = $siteObject.DiscoverySolutionId.Split("/")[8]
180-
}
177+
# $siteObject is not null or exception would have been thrown
178+
$ProjectName = $siteObject.DiscoverySolutionId.Split("/")[8]
181179

182-
break;
183-
}
184-
catch {
185-
if ($i -lt $attempts)
186-
{
187-
Write-Host "Machine site not found. Retrying in 30 seconds..."
188-
Start-Sleep -Seconds 30
189-
}
190-
else
191-
{
192-
throw "Machine site '$siteName' with Type '$siteType' not found."
193-
}
194-
}
195-
}
196-
197180
$null = $PSBoundParameters.Remove('SiteName')
198181

199-
$null = $PSBoundParameters.Add("Name", "Servers-Migration-ServerMigration_DataReplication")
182+
# Get the migrate solution.
183+
$amhSolutionName = "Servers-Migration-ServerMigration_DataReplication"
184+
$null = $PSBoundParameters.Add("Name", $amhSolutionName)
200185
$null = $PSBoundParameters.Add("MigrateProjectName", $ProjectName)
201-
202-
$solution = Az.Migrate\Get-AzMigrateSolution @PSBoundParameters
203-
if ($solution -and ($solution.Count -ge 1)) {
204-
$VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split("/")[8]
205-
}
206-
else {
207-
throw "Solution not found."
208-
}
186+
187+
$solution = InvokeAzMigrateGetCommandWithRetries `
188+
-CommandName 'Az.Migrate\Get-AzMigrateSolution' `
189+
-Parameters $PSBoundParameters `
190+
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found in resource group '$ResourceGroupName' and project '$ProjectName'. Please verify your appliance setup."
209191

210192
$null = $PSBoundParameters.Remove("Name")
211193
$null = $PSBoundParameters.Remove("MigrateProjectName")
194+
195+
$VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split("/")[8]
196+
if ([string]::IsNullOrEmpty($VaultName)) {
197+
throw "Azure Migrate Project not configured: missing replication vault. Setup Azure Migrate Project and run the Initialize-AzMigrateHCIReplicationInfrastructure script before proceeding."
198+
}
212199

213200
$null = $PSBoundParameters.Add("VaultName", $VaultName)
214201
$null = $PSBoundParameters.Add("Name", $ProtectedItemName)
215202

216-
return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
203+
return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters
217204
}
218205

219206
if (($parameterSet -match 'List') -or ($parameterSet -eq 'GetByMachineName')) {
@@ -234,23 +221,27 @@ function Get-AzMigrateHCIServerReplication {
234221
$ProjectName = $projectIdArray[8]
235222
}
236223

224+
$amhSolutionName = "Servers-Migration-ServerMigration_DataReplication"
237225
$null = $PSBoundParameters.Add("ResourceGroupName", $ResourceGroupName)
238-
$null = $PSBoundParameters.Add("Name", "Servers-Migration-ServerMigration_DataReplication")
226+
$null = $PSBoundParameters.Add("Name", $amhSolutionName)
239227
$null = $PSBoundParameters.Add("MigrateProjectName", $ProjectName)
240-
241-
$solution = Az.Migrate\Get-AzMigrateSolution @PSBoundParameters
242-
if ($solution -and ($solution.Count -ge 1)) {
243-
$VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split("/")[8]
244-
}
245-
else {
246-
throw "Solution not found."
247-
}
228+
229+
$solution = InvokeAzMigrateGetCommandWithRetries `
230+
-CommandName 'Az.Migrate\Get-AzMigrateSolution' `
231+
-Parameters $PSBoundParameters `
232+
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found in resource group '$ResourceGroupName' and project '$ProjectName'. Please verify your appliance setup."
248233

249234
$null = $PSBoundParameters.Remove("Name")
250235
$null = $PSBoundParameters.Remove("MigrateProjectName")
236+
237+
$VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split("/")[8]
238+
if ([string]::IsNullOrEmpty($VaultName)) {
239+
throw "Azure Migrate Project not configured: missing replication vault. Setup Azure Migrate Project and run the Initialize-AzMigrateHCIReplicationInfrastructure script before proceeding."
240+
}
241+
251242
$null = $PSBoundParameters.Add("VaultName", $VaultName)
252243

253-
$replicatingItems = Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
244+
$replicatingItems = Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters
254245

255246
if ($parameterSet -eq "GetByMachineName") {
256247
$replicatingItems = $replicatingItems | Where-Object { $_.Property.FabricObjectName -eq $MachineName }
@@ -274,7 +265,7 @@ function Get-AzMigrateHCIServerReplication {
274265
$null = $PSBoundParameters.Add("VaultName", $VaultName)
275266
$null = $PSBoundParameters.Add("Name", $ProtectedItemName)
276267

277-
return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
268+
return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters
278269
}
279270
}
280271
}

src/Migrate/Migrate.Autorest/custom/Helper/AzStackHCICommonSettings.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ enum StorageAccountProvisioningState
7575
Creating
7676
ResolvingDNS
7777
Succeeded
78+
}
79+
80+
# Selection state for VM NIC
81+
$VMNicSelection = @{
82+
SelectedByUser = "SelectedByUser";
83+
NotSelected = "NotSelected";
7884
}

src/Migrate/Migrate.Autorest/custom/Helper/CommonHelper.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,58 @@ function GenerateHashForArtifact {
176176
else {
177177
return $hashCode
178178
}
179+
}
180+
181+
function InvokeAzMigrateGetCommandWithRetries {
182+
[Microsoft.Azure.PowerShell.Cmdlets.Migrate.DoNotExportAttribute()]
183+
param(
184+
[Parameter(Mandatory)]
185+
[System.String]
186+
# Specifies the name of Az.Migrate command.
187+
${CommandName},
188+
189+
[Parameter(Mandatory)]
190+
[System.Collections.Hashtable]
191+
# Specifies the parameters for Az.Migrate command.
192+
${Parameters},
193+
194+
[Parameter()]
195+
[System.Int32]
196+
# Specifies the maximum number of retries.
197+
${MaxRetryCount} = 3,
198+
199+
[Parameter()]
200+
[System.Int32]
201+
# Specifies the delay between retries in seconds.
202+
${RetryDelayInSeconds} = 30,
203+
204+
[Parameter()]
205+
[System.String]
206+
# Specifies the error message to throw if command fails.
207+
${ErrorMessage} = "Internal Az.Migrate commands failed to execute."
208+
)
209+
210+
process {
211+
for ($i = 0; $i -le $MaxRetryCount; $i++) {
212+
try {
213+
$result = & $CommandName @Parameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
214+
215+
if ($null -eq $result) {
216+
throw $ErrorMessage
217+
}
218+
219+
break
220+
}
221+
catch {
222+
if ($i -lt $MaxRetryCount) {
223+
Start-Sleep -Seconds $RetryDelayInSeconds
224+
}
225+
else {
226+
throw $ErrorMessage
227+
}
228+
}
229+
}
230+
231+
return $result
232+
}
179233
}

0 commit comments

Comments
 (0)