-
Notifications
You must be signed in to change notification settings - Fork 600
Add SIG to Lab Account #749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,29 +338,55 @@ function Publish-Labs { | |
| $ConfigObject | ||
| ) | ||
|
|
||
| $lacs = $ConfigObject | Select-Object -Property ResourceGroupName, LabAccountName -Unique | ||
| $lacs = $ConfigObject | Select-Object -Property ResourceGroupName, LabAccountName, SharedGalleryResourceGroupName, SharedGalleryName -Unique | ||
|
|
||
| Write-Host "Operating on the following Lab Accounts:" | ||
| Write-Host $lacs | ||
|
|
||
| $block = { | ||
| param($path, $ResourceGroupName, $LabAccountName) | ||
| param($path, $ResourceGroupName, $LabAccountName, $SharedGalleryResourceGroupName, $SharedGalleryName) | ||
|
|
||
| Set-StrictMode -Version Latest | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $modulePath = Join-Path $path '..\Az.LabServices.psm1' | ||
| Import-Module $modulePath | ||
|
|
||
| if ((Get-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName) -eq $null ){ | ||
| New-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName | Out-Null | ||
| $labAccount = Get-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName | ||
|
|
||
| if ($labAccount -eq $null ){ | ||
| $labAccount = New-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName | Out-Null | ||
| Write-Host "$LabAccountName lab account created." | ||
| } | ||
| else { | ||
| Write-Host "$LabAccountName lab account found - skipping create." | ||
| } | ||
|
|
||
| if ($SharedGalleryResourceGroupName -ne $null && $SharedGalleryName -ne $null){ | ||
|
|
||
| $gallery = $labAccount | Get-AzLabAccountSharedGallery | ||
| if ($gallery -ne $null) { | ||
| Write-Host "$LabAccountName lab account already has attached gallery $gallery." | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's the wrong gallery that's attached to the lab account, should we change it to what's in the CSV file? I think currently we don't 'fix' settings in other places - but I'm wondering what the user's expectation would be. Perhaps we should consider this as a "Upsert" (update/insert) operation when running the scripts for any changes? The downside is that changing the SIG if there are labs & student VMs means that users couldn't reset the student VMs from SIG anymore...
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was hesitant changing it if it's already set for the reasons you mentioned. I was thinking that if there are failures of some sort (for example, 503 which i've hit occassionally), which we could also include when there is an attached SIG already, that we could output this in a .csv...similar to what you're planning. When you're done with your code, we can likely reuse it here too. |
||
| } | ||
| else { | ||
| $gallery = Get-AzGallery -ResourceGroupName $SharedGalleryResourceGroupName -Name $SharedGalleryName | ||
|
|
||
| if ($gallery -ne $null) { | ||
| Write-Host "$SharedGalleryName shared gallery found." | ||
| New-AzLabAccountSharedGallery -LabAccount $labAccount -SharedGallery $gallery | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to do this by Resource ID instead of by object... The reason is because if the SIG is in a different subscription- we don't want to manually swap subscriptions back and forth to get the object if we don't have to (and I think the API just needs the SIG ID)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch - I've changed it to look by resource id...but, i am still having issues with it working to find a SIG successfully across subs. I've tested it in my subs, but I have different tentants involved. Also, tried it with Roger where we used our Microsoft subs, and still couldn't get it to work. I'd like to talk to you more to see what I'm missing. |
||
| Write-Host "$SharedGalleryName shared gallery attached." | ||
| } | ||
| else { | ||
| Write-Host "$SharedGalleryName shared gallery not found - skipping attach." | ||
| } | ||
| } | ||
| } | ||
| Write-Host "$LabAccountName lab account created or found." | ||
| } | ||
|
|
||
| Write-Host "Starting lab accounts creation in parallel. Can take a while." | ||
| $jobs = @() | ||
| $lacs | ForEach-Object { | ||
| $jobs += Start-ThreadJob -ScriptBlock $block -ArgumentList $PSScriptRoot, $_.ResourceGroupName, $_.LabAccountName -Name $_.LabAccountName -ThrottleLimit $ThrottleLimit | ||
| $jobs += Start-ThreadJob -ScriptBlock $block -ArgumentList $PSScriptRoot, $_.ResourceGroupName, $_.LabAccountName, $_.SharedGalleryResourceGroupName, $_.SharedGalleryName -Name $_.LabAccountName -ThrottleLimit $ThrottleLimit | ||
| } | ||
|
|
||
| $hours = 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should do it this way... This means that the bulk lab creation scripts can only use a shared image gallery from the current subscription. We should either add a "SharedGallerySubscriptionId" or we should consider just having a single field with the full shared image gallery resource ID. (I like the single field idea, because it could just be an empty column or missing entirely if the user doesn't need it - vs needing to do validation across 3 columns to make sure there isn't a missing field...