en-us/about_AutomatedLab_restapi.help.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
TOPIC
    about_automatedlab_restapi
 
SHORT DESCRIPTION
    Generic help about the Role 'restapi' in AutomatedLab
 
LONG DESCRIPTION
Lab building with the REST API
    With the custom role 'LabBuilder' it is now possible to create a simple REST
    API powered by
    Polaris
    on any virtualization host. The REST API provides the following
    functionality:
 
    CREATE
    $request = @{
        LabScript = Get-Content "$labsources\Sample Scripts\Introduction\01 Single Win10 Client.ps1" -Raw
    } | ConvertTo-Json
     
    ## Queue new job, use GUID to request status update with GET method
    $guid = Invoke-RestMethod -Method Post -Uri http://NestedBuilder/Lab -Body $request -ContentType application/json
 
    READ
    ## All labs (Get-Lab -List)
    Invoke-RestMethod -Method Get -Uri http://NestedBuilder/Labs
    ## Specific lab
    Invoke-RestMethod -Method Get -Uri http://NestedBuilder/Lab?Name=Win10
    ## Lab creation job (monitoring long running jobs)
    Invoke-RestMethod -Method Get -Uri http://NestedBuilder/Lab?Id=5b89babb-7402-4a7a-9c16-86e1d52613fa
 
    DELETE
    ## As query parameter
    Invoke-RestMethod -Method Delete -Uri http://NestedBuilder/Lab?Name=Win10
     
    ## Or as JSON body
    $request = @{Name = 'Win10'} | ConvertTo-Json
    Invoke-RestMethod -Method Delete -Uri http://NestedBuilder/Lab -Body $request -ContentType application/json
 
    LAB SCENARIO INCLUDING THE BUILDER
    The following lab scenario configures a simple VM to test-drive this
    feature. Be aware that when using this on Azure your lab sources need to be
    uploaded first. Otherwise you will need to manually copy all necessary ISO
    files to your Azure VM.
 
    <#
    Build a lab with the help of nested virtualization. Adjust the machine memory if necessary.
    The build worker will use Polaris as a simple REST endpoint that takes your lab data to deploy.
     
    AutomatedLab will be copied to the machine. Lab sources will be mirrored to the machine as well, so that lab deployments can start immediately
    ##>
    param
    (
        [string]
        $LabName = 'LabAsAService',
     
        [ValidateSet('yes','no')]
        $TelemetryOptOut = 'no' # Opt out of telemetry for build worker by saying yes here
    )
     
    New-LabDefinition -Name $labName -DefaultVirtualizationEngine HyperV
    Add-LabVirtualNetworkDefinition -Name $labName -HyperVProperties @{ SwitchType = 'External'; AdapterName = 'Ethernet' }
     
    $role = Get-LabPostInstallationActivity -CustomRole LabBuilder -Properties @{TelemetryOptOut = $TelemetryOptOut}
     
    $machineParameters = @{
        Name = 'NestedBuilder'
        PostInstallationActivity = $role
        OperatingSystem = 'Windows Server 2016 Datacenter (Desktop Experience)'
        Memory = 16GB
        Network = $labName
        DiskName = 'vmDisk'
    }
     
    $estimatedSize = [Math]::Round(((Get-ChildItem $labsources -File -Recurse | Measure-Object -Property Length -Sum).Sum / 1GB + 20), 0)
    $disk = Add-LabDiskDefinition -Name vmDisk -DiskSizeInGb $estimatedSize -PassThru
     
    Add-LabMachineDefinition @machineParameters
     
    Install-Lab