Skip to content

Commit

Permalink
Refactor the LabCreator.ps1 sample to a set of reusable functions (Az…
Browse files Browse the repository at this point in the history
…ure#744)

* First checkin. Todo add select functions

* Add SelectLab

* Adding ShowMenu

* Force loading of AzLab module in the calling script as we cannot know where the user has stored it

* Add first examples

* Finish samples

* Add Json sample

* Update table of contents

* Change library to module in title

* Removing LabCreator & csv files and adding timing to PublishAll.ps1

* Fix Nichole comments
  • Loading branch information
lucabol authored Feb 19, 2021
1 parent ff6975b commit 7f11bb6
Show file tree
Hide file tree
Showing 16 changed files with 974 additions and 414 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ packages/
*.csproj.user
**/obj/*
**/Properties/PublishProfiles/*
*.cred
*.cred
debug.log
11 changes: 11 additions & 0 deletions samples/ClassroomLabs/Modules/Library/Tools/Examples/PickALab.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$CsvConfigFile
)

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

$CsvConfigFile | Import-LabsCsv | Show-LabMenu -PickLab | Publish-Labs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$CsvConfigFile,

[Parameter(Mandatory = $false, HelpMessage = "Which lab properties to show a prompt for")]
[ValidateNotNullOrEmpty()]
[string[]]
$Properties
)

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

$CsvConfigFile `
| Import-LabsCsv `
| Show-LabMenu -PickLab -Properties $Properties `
| Publish-Labs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$CsvConfigFile,

[Parameter(Mandatory = $false, HelpMessage = "Which lab properties to show a prompt for")]
[ValidateNotNullOrEmpty()]
[string[]]
$Properties
)

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

$CsvConfigFile `
| Import-LabsCsv `
| Show-LabMenu -Properties $Properties `
| Publish-Labs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$CsvConfigFile,

[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[int]
$ThrottleLimit = 5
)

$outerScriptstartTime = Get-Date
Write-Host "Executing Lab Creation Script, starting at $outerScriptstartTime" -ForegroundColor Green

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

$CsvConfigFile | Import-LabsCsv | Publish-Labs

Write-Host "Completed running Bulk Lab Creation script, total duration $(((Get-Date) - $outerScriptstartTime).TotalMinutes) minutes" -ForegroundColor Green
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$JsonConfigFile,

[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[int]
$ThrottleLimit = 5
)

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

Get-Content -Raw -Path $JsonConfigFile | ConvertFrom-Json | Publish-Labs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$CsvConfigFile,

[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "If a lab contains any of these tags, it will be selected")]
[ValidateNotNullOrEmpty()]
[string]
$AnId
)

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

$CsvConfigFile `
| Import-LabsCsv `
| Select-Lab -Id $AnId `
| Set-LabProperty -ResourceGroup Staging -MaxUsers 50 `
| Publish-Labs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$CsvConfigFile,

[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "If a lab contains any of these tags, it will be selected")]
[ValidateNotNullOrEmpty()]
[string[]]
$SomeTags,

[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[int]
$ThrottleLimit = 5
)

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

$CsvConfigFile | Import-LabsCsv | Select-Lab -SomeTags $SomeTags | Publish-Labs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$CsvConfigFile,

[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "If a lab contains any of these tags, it will be selected")]
[ValidateNotNullOrEmpty()]
[string]
$AnId,

[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[int]
$ThrottleLimit = 5

)

Import-Module ../../Az.LabServices.psm1 -Force
Import-Module ../LabCreationLibrary.psm1 -Force

$CsvConfigFile | Import-LabsCsv | Select-Lab -AnId $AnId | Publish-Labs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Id,Tags,ResourceGroupName,Location,LabAccountName,LabName,ImageName,AadGroupId,MaxUsers,UsageQuota,UsageMode,SharedPassword,Size,Title,Descr,TemplateVmState, UserName,Password,LinuxRdp, Emails,LabOwnerEmails, idleGracePeriod, idleOsGracePeriod, idleNoConnectGracePeriod, Invitation, Schedules
id001,[email protected];[email protected],hogwarts-rg2,westeurope,Muggle,"History of Magic",CentOS-Based*,00000000-0000-0000-0000-000000000000,2,20,Restricted,FALSE,Basic,"History of Magic","Those who don't know history ...",Enabled,test0000,Test00000000,TRUE,"[email protected];[email protected]","[email protected];[email protected]",7,8,9,"History of Magic",
id002,[email protected];[email protected],hogwarts-rg2,westeurope,Wizardy,Transfiguration,CentOS-Based*,,2,20,Restricted,FALSE,Basic,"Transfiguration","Who are you?",, test0000,Test00000000,TRUE,"[email protected];[email protected]",,7,8,9,"Transfiguration",
id003,[email protected];[email protected],hogwarts-rg2,westeurope,Wizardy,Charms,CentOS-Based*,,2,20,Restricted,FALSE,Basic,"Charms","Encanted",Disabled,test0000,Test00000000,TRUE,"[email protected]",,15,0,10, "Charms", charms
101 changes: 101 additions & 0 deletions samples/ClassroomLabs/Modules/Library/Tools/Examples/hogwarts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[
{
"Id": "id001",
"Tags": "[email protected];[email protected]",
"ResourceGroupName": "hogwarts-rg2",
"Location": "westeurope",
"LabAccountName": "Muggle",
"LabName": "History of Magic",
"ImageName": "CentOS-Based*",
"AadGroupId": "00000000-0000-0000-0000-000000000000",
"MaxUsers": "2",
"UsageQuota": "20",
"UsageMode": "Restricted",
"SharedPassword": false,
"Size": "Basic",
"Title": "History of Magic",
"Descr": "Those who don't know history ...",
"TemplateVmState": "Enabled",
"UserName": "test0000",
"Password": "Test00000000",
"LinuxRdp": true,
"Emails": [
"[email protected]",
"[email protected]"
],
"LabOwnerEmails": [
"[email protected]",
"[email protected]"
],
"idleGracePeriod": "7",
"idleOsGracePeriod": "8",
"idleNoConnectGracePeriod": "9",
"Invitation": "History of Magic",
"Schedules": "",
"GpuDriverEnabled": false
},
{
"Id": "id002",
"Tags": "[email protected];[email protected]",
"ResourceGroupName": "hogwarts-rg2",
"Location": "westeurope",
"LabAccountName": "Wizardy",
"LabName": "Transfiguration",
"ImageName": "CentOS-Based*",
"AadGroupId": "",
"MaxUsers": "2",
"UsageQuota": "20",
"UsageMode": "Restricted",
"SharedPassword": false,
"Size": "Basic",
"Title": "Transfiguration",
"Descr": "Who are you?",
"TemplateVmState": "",
"UserName": "test0000",
"Password": "Test00000000",
"LinuxRdp": true,
"Emails": [
"[email protected]",
"[email protected]"
],
"LabOwnerEmails": "",
"idleGracePeriod": "7",
"idleOsGracePeriod": "8",
"idleNoConnectGracePeriod": "9",
"Invitation": "Transfiguration",
"Schedules": "",
"GpuDriverEnabled": false
},
{
"Id": "id003",
"Tags": "[email protected];[email protected]",
"ResourceGroupName": "hogwarts-rg2",
"Location": "westeurope",
"LabAccountName": "Wizardy",
"LabName": "Charms",
"ImageName": "CentOS-Based*",
"AadGroupId": "",
"MaxUsers": "2",
"UsageQuota": "20",
"UsageMode": "Restricted",
"SharedPassword": false,
"Size": "Basic",
"Title": "Charms",
"Descr": "Encanted",
"TemplateVmState": "Disabled",
"UserName": "test0000",
"Password": "Test00000000",
"LinuxRdp": true,
"Emails": "[email protected]",
"LabOwnerEmails": "",
"idleGracePeriod": "15",
"idleOsGracePeriod": "0",
"idleNoConnectGracePeriod": "10",
"Invitation": "Charms",
"Schedules": [
"@{Frequency=Weekly; FromDate=1/1/2021; ToDate=12/12/2021; StartTime=10:00; EndTime=12:00; WeekDays=System.Object[]; TimeZoneId=W. Europe Standard Time; Notes=A recurrent class}",
"@{Frequency=Once; FromDate=1/1/2021; ToDate=12/12/2021; StartTime=10:00; EndTime=12:00; WeekDays=; TimeZoneId=W. Europe Standard Time; Notes=A workshop}"
],
"GpuDriverEnabled": false
}
]
Loading

0 comments on commit 7f11bb6

Please sign in to comment.