Skip to content

Commit dff1cf2

Browse files
hvedatiHarika VedatiLei JinmsJinLei
authored
Report Image Download Progress (#24180)
* working image download progress * adding reporting download progress logic * adding image recording test * adding marketplace test * Use fixed autorest.powershell version to generate * updating env and recording files * Revert change to README.md * updatig variables and image recording * image test * storage path test * disk recording * updating env variables * logical network test * nic test * fixing networkinterface test * vm test * fixing image test * image recording * fixing image * fix --------- Co-authored-by: Harika Vedati <[email protected]> Co-authored-by: Lei Jin <[email protected]> Co-authored-by: Jin Lei <[email protected]>
1 parent d95b044 commit dff1cf2

13 files changed

+4457
-3379
lines changed

src/StackHCIVM/StackHCIVM.Autorest/custom/New-AzStackHCIVMImage.ps1

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,47 @@ function New-AzStackHCIVMImage{
303303

304304
if ($PSCmdlet.ParameterSetName -eq "Marketplace")
305305
{
306-
return Az.StackHCIVM.internal\New-AzStackHCIVMMarketplaceGalleryImage @PSBoundParameters
306+
$PSBoundParameters['NoWait'] = $true
307+
$PSBoundParameters['ErrorAction'] = 'Stop'
308+
try {
309+
Az.StackHCIVM.internal\New-AzStackHCIVMMarketplaceGalleryImage @PSBoundParameters
310+
Start-Sleep -Seconds 60
311+
$PercentCompleted = 0
312+
Write-Progress -Activity "Download Percentage: " -Status "$PercentCompleted % Complete:" -PercentComplete $PercentCompleted
313+
$null = $PSBoundParameters.Remove("Version")
314+
$null = $PSBoundParameters.Remove("URN")
315+
$null = $PSBoundParameters.Remove("Tag")
316+
$null = $PSBoundParameters.Remove("StoragePathId")
317+
$null = $PSBoundParameters.Remove("Sku")
318+
$null = $PSBoundParameters.Remove("Publisher")
319+
$null = $PSBoundParameters.Remove("Offer")
320+
$null = $PSBoundParameters.Remove("OSType")
321+
$null = $PSBoundParameters.Remove("ImagePath")
322+
$null = $PSBoundParameters.Remove("CustomLocationId")
323+
$null = $PSBoundParameters.Remove("CloudInitDataSource")
324+
$null = $PSBoundParameters.Remove("Location")
325+
$null = $PSBoundParameters.Remove("NoWait")
326+
while ($PercentCompleted -ne 100 ) {
327+
$image = Az.StackHCIVM.internal\Get-AzStackHCIVMMarketplaceGalleryImage @PSBoundParameters
328+
$PercentCompleted = $image.StatusProgressPercentage
329+
if ($PercentCompleted -eq $null){
330+
$PercentCompleted = 0
331+
}
332+
Write-Progress -Activity "Download Percentage: " -Status "$PercentCompleted % Complete" -PercentComplete $PercentCompleted
333+
Start-Sleep -Seconds 5
334+
if ($image.ProvisioningStatus -eq "Failed") {
335+
Break
336+
}
337+
}
338+
if ($image.ProvisioningStatus -eq "Failed"){
339+
Write-Error $image.StatusErrorMessage -ErrorAction Stop
340+
}
341+
342+
} catch {
343+
Write-Error $_.Exception.Message -ErrorAction Stop
344+
}
307345

346+
308347
} elseif ($PSCmdlet.ParameterSetName -eq "MarketplaceURN") {
309348
if ($URN -match $urnRegex){
310349
$publisher = $Matches.publisher.ToLower()
@@ -320,15 +359,54 @@ function New-AzStackHCIVMImage{
320359
} else {
321360
Write-Error "Invalid URN provided: $URN. Valid URN format is Publisher:Offer:Sku:Version ." -ErrorAction Stop
322361
}
362+
363+
$PSBoundParameters['NoWait'] = $true
364+
$PSBoundParameters['ErrorAction'] = 'Stop'
365+
try {
366+
Az.StackHCIVM.internal\New-AzStackHCIVMMarketplaceGalleryImage @PSBoundParameters
367+
Start-Sleep -Seconds 60
368+
$PercentCompleted = 0
369+
Write-Progress -Activity "Download Percentage: " -Status "$PercentCompleted % Complete:" -PercentComplete $PercentCompleted
370+
$null = $PSBoundParameters.Remove("Version")
371+
$null = $PSBoundParameters.Remove("URN")
372+
$null = $PSBoundParameters.Remove("Tag")
373+
$null = $PSBoundParameters.Remove("StoragePathId")
374+
$null = $PSBoundParameters.Remove("Sku")
375+
$null = $PSBoundParameters.Remove("Publisher")
376+
$null = $PSBoundParameters.Remove("Offer")
377+
$null = $PSBoundParameters.Remove("OSType")
378+
$null = $PSBoundParameters.Remove("ImagePath")
379+
$null = $PSBoundParameters.Remove("CustomLocationId")
380+
$null = $PSBoundParameters.Remove("CloudInitDataSource")
381+
$null = $PSBoundParameters.Remove("Location")
382+
$null = $PSBoundParameters.Remove("NoWait")
383+
while ($PercentCompleted -ne 100 ) {
384+
$image = Az.StackHCIVM.internal\Get-AzStackHCIVMMarketplaceGalleryImage @PSBoundParameters
385+
$PercentCompleted = $image.StatusProgressPercentage
386+
if ($PercentCompleted -eq $null){
387+
$PercentCompleted = 0
388+
}
389+
Write-Progress -Activity "Download Percentage: " -Status "$PercentCompleted % Complete" -PercentComplete $PercentCompleted
390+
Start-Sleep -Seconds 5
391+
if ($image.ProvisioningStatus -eq "Failed") {
392+
Break
393+
}
394+
}
395+
if ($image.ProvisioningStatus -eq "Failed"){
396+
Write-Error $image.StatusErrorMessage -ErrorAction Stop
397+
}
398+
399+
} catch {
400+
Write-Error $_.Exception.Message -ErrorAction Stop
401+
}
323402

324-
return Az.StackHCIVM.internal\New-AzStackHCIVMMarketplaceGalleryImage @PSBoundParameters
325403

326404
}
327405

328406
if ($PSCmdlet.ParameterSetName -eq "GalleryImage")
329407
{
330408

331-
return Az.StackHCIVM.internal\New-AzStackHCIVMGalleryImage @PSBoundParameters
409+
Az.StackHCIVM.internal\New-AzStackHCIVMGalleryImage @PSBoundParameters
332410
}
333411

334412

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Examples
2+
This directory contains examples from the exported cmdlets of the module. When `build-module.ps1` is ran, example stub files will be generated here. If your module support Azure Profiles, the example stubs will be in individual profile folders. These example stubs should be updated to show how the cmdlet is used. The examples are imported into the documentation when `generate-help.ps1` is ran.
3+
4+
## Info
5+
- Modifiable: yes
6+
- Generated: partial
7+
- Committed: yes
8+
- Packaged: no
9+
10+
## Purpose
11+
This separates the example documentation details from the generated documentation information provided directly from the generated cmdlets. Since the cmdlets don't have examples from the REST spec, this provides a means to add examples easily. The example stubs provide the markdown format that is required. The 3 core elements are: the name of the example, the code information of the example, and the description of the example. That information, if the markdown format is followed, will be available to documentation generation and be part of the documents in the `..\docs` folder.

0 commit comments

Comments
 (0)