Skip to content

Commit e4b8909

Browse files
committed
Add SIG to Lab Account
1 parent 7f11bb6 commit e4b8909

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

samples/ClassroomLabs/Modules/Library/Az.LabServices.psm1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,29 @@ function Publish-AzLab {
996996
end { }
997997
}
998998

999+
function Get-AzLabAccountSharedGallery {
1000+
[CmdletBinding()]
1001+
param(
1002+
[parameter(Mandatory = $true, HelpMessage = "Lab Account to get attached Shared Gallery.", ValueFromPipeline = $true)]
1003+
[ValidateNotNullOrEmpty()]
1004+
$LabAccount
1005+
)
1006+
1007+
begin { . BeginPreamble }
1008+
process {
1009+
try {
1010+
foreach ($la in $LabAccount) {
1011+
$uri = (ConvertToUri -resource $la) + "/SharedGalleries/"
1012+
return InvokeRest -Uri $uri -Method 'Get'
1013+
}
1014+
}
1015+
catch {
1016+
Write-Error -ErrorRecord $_ -EA $callerEA
1017+
}
1018+
}
1019+
end { }
1020+
}
1021+
9991022
function Get-AzLabAccountSharedImage {
10001023
[CmdletBinding()]
10011024
param(
@@ -1709,6 +1732,7 @@ Export-ModuleMember -Function Get-AzLabAccount,
17091732
Get-AzLabForVm,
17101733
New-AzLabAccountSharedGallery,
17111734
Remove-AzLabAccountSharedGallery,
1735+
Get-AzLabAccountSharedGallery,
17121736
Get-AzLabAccountPricingAndAvailability,
17131737
Stop-AzLabTemplateVm,
17141738
Start-AzLabTemplateVm,

samples/ClassroomLabs/Modules/Library/Tools/LabCreationLibrary.psm1

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,29 +338,55 @@ function Publish-Labs {
338338
$ConfigObject
339339
)
340340

341-
$lacs = $ConfigObject | Select-Object -Property ResourceGroupName, LabAccountName -Unique
341+
$lacs = $ConfigObject | Select-Object -Property ResourceGroupName, LabAccountName, SharedGalleryResourceGroupName, SharedGalleryName -Unique
342+
342343
Write-Host "Operating on the following Lab Accounts:"
343344
Write-Host $lacs
344345

345346
$block = {
346-
param($path, $ResourceGroupName, $LabAccountName)
347+
param($path, $ResourceGroupName, $LabAccountName, $SharedGalleryResourceGroupName, $SharedGalleryName)
347348

348349
Set-StrictMode -Version Latest
349350
$ErrorActionPreference = 'Stop'
350351

351352
$modulePath = Join-Path $path '..\Az.LabServices.psm1'
352353
Import-Module $modulePath
353354

354-
if ((Get-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName) -eq $null ){
355-
New-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName | Out-Null
355+
$labAccount = Get-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName
356+
357+
if ($labAccount -eq $null ){
358+
$labAccount = New-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName | Out-Null
359+
Write-Host "$LabAccountName lab account created."
360+
}
361+
else {
362+
Write-Host "$LabAccountName lab account found - skipping create."
363+
}
364+
365+
if ($SharedGalleryResourceGroupName -ne $null && $SharedGalleryName -ne $null){
366+
367+
$gallery = $labAccount | Get-AzLabAccountSharedGallery
368+
if ($gallery -ne $null) {
369+
Write-Host "$LabAccountName lab account already has attached gallery $gallery."
370+
}
371+
else {
372+
$gallery = Get-AzGallery -ResourceGroupName $SharedGalleryResourceGroupName -Name $SharedGalleryName
373+
374+
if ($gallery -ne $null) {
375+
Write-Host "$SharedGalleryName shared gallery found."
376+
New-AzLabAccountSharedGallery -LabAccount $labAccount -SharedGallery $gallery
377+
Write-Host "$SharedGalleryName shared gallery attached."
378+
}
379+
else {
380+
Write-Host "$SharedGalleryName shared gallery not found - skipping attach."
381+
}
382+
}
356383
}
357-
Write-Host "$LabAccountName lab account created or found."
358384
}
359385

360386
Write-Host "Starting lab accounts creation in parallel. Can take a while."
361387
$jobs = @()
362388
$lacs | ForEach-Object {
363-
$jobs += Start-ThreadJob -ScriptBlock $block -ArgumentList $PSScriptRoot, $_.ResourceGroupName, $_.LabAccountName -Name $_.LabAccountName -ThrottleLimit $ThrottleLimit
389+
$jobs += Start-ThreadJob -ScriptBlock $block -ArgumentList $PSScriptRoot, $_.ResourceGroupName, $_.LabAccountName, $_.SharedGalleryResourceGroupName, $_.SharedGalleryName -Name $_.LabAccountName -ThrottleLimit $ThrottleLimit
364390
}
365391

366392
$hours = 1

0 commit comments

Comments
 (0)