Skip to content

Commit 0193d43

Browse files
authored
Merge pull request #586 from microsoft/dev
Dev
2 parents 3b64396 + 682f576 commit 0193d43

File tree

2 files changed

+6
-90
lines changed

2 files changed

+6
-90
lines changed

Scripts/3_Deploy.ps1

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -753,28 +753,9 @@ If (-not $isAdmin) {
753753
$oeminformation=$null
754754
}
755755
#configure native VLAN and AllowedVLANs
756-
WriteInfo "`t Configuring NativeVLAN and AllowedVLANs"
757-
if ($ManagementSubnetIDs){
758-
$number1=$(($HighestVLAN+1))
759-
$number2=$($HighestVLAN+$($ManagementSubnetIDs.Count))
760-
if ($number1 -eq $number2){
761-
$number=$number1
762-
}else{
763-
$number="$number1-$number2"
764-
}
765-
$AllowedVLANs="$($LabConfig.AllowedVLANs),$number"
766-
}else{
767756
$AllowedVLANs=$($LabConfig.AllowedVLANs)
768-
}
769-
770-
if ($VMConfig.ManagementSubnetID -gt 0){
771-
$NativeVlanId=($HighestVLAN+$VMConfig.ManagementSubnetID)
772-
WriteInfo "`t`t Subnet ID is $($VMConfig.ManagementSubnetID) with NativeVLAN $NativeVLanID. AllowedVLANIDList is $($LabConfig.AllowedVLANs),$NativeVLANID"
773-
$VMTemp | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Management*" -Trunk -NativeVlanId $NativeVlanId -AllowedVlanIdList "$AllowedVLANs"
774-
}else{
775757
WriteInfo "`t`t Subnet ID is 0 with NativeVLAN 0. AllowedVlanIDList is $($LabConfig.AllowedVLANs)"
776758
$VMTemp | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Management*" -Trunk -NativeVlanId 0 -AllowedVlanIdList "$AllowedVLANs"
777-
}
778759

779760
#Create Unattend file
780761
if ($VMConfig.Unattend -eq "NoDjoin" -or $VMConfig.SkipDjoin){
@@ -923,12 +904,6 @@ If (-not $isAdmin) {
923904
#Calculate highest VLAN (for additional subnets)
924905
[int]$HighestVLAN=$LabConfig.AllowedVLANs -split "," -split "-" | Select-Object -Last 1
925906

926-
#Grab defined Management Subnet IDs and ignore 0
927-
$ManagementSubnetIDs=$labconfig.vms.ManagementSubnetID + $LabConfig.ManagementSubnetIDs | Select-Object -Unique | Sort-Object | Where-Object {$_ -ne 0}
928-
if ($ManagementSubnetIDs){
929-
WriteInfo "`t Requested ManagementSubnetIDs: $ManagementSubnetIDs"
930-
}
931-
932907
#endregion
933908

934909
#region Some Additional checks and prereqs configuration
@@ -1314,19 +1289,11 @@ If (-not $isAdmin) {
13141289
$DC=get-vm -Name ($labconfig.prefix+"DC")
13151290
}
13161291

1317-
#add addtional subnets if specified
1318-
if ($ManagementSubnetIDs){
1319-
WriteInfo "`t Adding adapters for additional subnets"
1320-
foreach ($number in $ManagementSubnetIDs){
1321-
if ($DC | Get-VMNetworkadapter -Name "Subnet$number" -ErrorAction Ignore){
1322-
WriteInfo "`t`t Adapters Subnet$number already present"
1323-
}else{
1324-
WriteInfo "`t`t Adding adapter Subnet$number and configuring Access VLANID $($HighestVLAN+$number)"
1325-
$DC | Add-VMNetworkAdapter -SwitchName $SwitchName -Name "Subnet$number" -DeviceNaming On
1326-
$DC | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Subnet$number" -Access -VlanId ($HighestVLAN+$number)
1327-
}
1328-
}
1329-
}
1292+
#add VLANs to DC
1293+
WriteInfo "`t Configuring VLANs on DC"
1294+
$AllowedVLANs=$($LabConfig.AllowedVLANs)
1295+
WriteInfo "`t`t Subnet ID is 0 with NativeVLAN 0. AllowedVlanIDList is $($LabConfig.AllowedVLANs)"
1296+
$DC | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Management*" -Trunk -NativeVlanId 0 -AllowedVlanIdList "$AllowedVLANs"
13301297

13311298
#Start DC if it is not running
13321299
if ($DC.State -ne "Running"){
@@ -1462,48 +1429,6 @@ If (-not $isAdmin) {
14621429
}
14631430
}
14641431

1465-
#configure NICs and routing if ManagementSubnetIDs are specified
1466-
if ($ManagementSubnetIDs){
1467-
WriteInfoHighlighted "`t Configuring subnets in DC"
1468-
#configure static IPs on SubnetX adapters
1469-
Invoke-Command -VMGuid $DC.id -Credential $cred -ScriptBlock {
1470-
Foreach ($number in $using:ManagementSubnetIDs){
1471-
$IP="10.0.$number.1"
1472-
$AdapterName="Subnet$Number"
1473-
$NetAdapterName=(Get-NetAdapterAdvancedProperty | Where-Object displayvalue -eq $AdapterName).Name
1474-
if (Get-NetIPAddress -InterfaceAlias $NetAdapterName -IPAddress $IP -ErrorAction Ignore){
1475-
Write-Output "`t`t Subnet $AdapterName already configured"
1476-
}else{
1477-
Write-Output "`t`t Configuring static IP address $IP on Adapter $NetAdapterName"
1478-
New-NetIPAddress -InterfaceAlias $NetAdapterName -IPAddress $IP -PrefixLength 24
1479-
#add dhcp scope
1480-
Write-Output "`t`t Adding DHCP Scope ID 10.0.$number.0 and it's DHCP options"
1481-
Add-DhcpServerv4Scope -StartRange "10.0.$number.10" -EndRange "10.0.$number.254" -Name "Scope$number" -State Active -SubnetMask 255.255.255.0
1482-
}
1483-
}
1484-
#make sure RRAS features are installed
1485-
Write-Output "`t`t Making sure routing features are installed"
1486-
Install-WindowsFeature -Name Routing,RSAT-RemoteAccess -IncludeAllSubFeature -WarningAction Ignore
1487-
#enable routing
1488-
Write-Output "`t`t Making sure routing is enabled"
1489-
$routingEnabled = (Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters -Name IPEnableRouter).IPEnableRouter
1490-
if ($routingEnabled -match "0") {
1491-
New-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters -Name IPEnableRouter -value 1 -Force
1492-
}
1493-
#restart routing... just to make sure
1494-
Write-Output "`t`t Restarting service RemoteAccess"
1495-
Restart-Service RemoteAccess
1496-
1497-
#configure DHCP Options
1498-
Foreach ($number in $using:ManagementSubnetIDs){
1499-
Set-DhcpServerv4OptionValue -OptionId 6 -Value "10.0.$number.1" -ScopeId "10.0.$number.0"
1500-
Set-DhcpServerv4OptionValue -OptionId 3 -Value "10.0.$number.1" -ScopeId "10.0.$number.0"
1501-
Set-DhcpServerv4OptionValue -OptionId 15 -Value "$($using:Labconfig.DomainName)" -ScopeId "10.0.$number.0"
1502-
}
1503-
}
1504-
}
1505-
1506-
15071432
#endregion
15081433

15091434
#region Provision VMs
@@ -1804,7 +1729,7 @@ If (-not $isAdmin) {
18041729
$telemetryEvent = Initialize-TelemetryEvent -Event "Deploy.End" -Metrics $metrics -Properties $properties -NickName $LabConfig.TelemetryNickName
18051730
$vmDeploymentEvents += $telemetryEvent
18061731

1807-
Send-TelemetryEvent -Events $vmDeploymentEvents | Out-Null
1732+
Send-TelemetryEvents -Events $vmDeploymentEvents | Out-Null
18081733
}
18091734

18101735
#write how much it took to deploy

Scripts/LabConfig.ps1

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M
4242
TelemetryNickname=""; # (Optional) If configured, telemetry will be sent with NickName to correlate data to specified NickName. So when leaderboards will be published, MSLab users will be able to see their own stats
4343
AutoStartAfterDeploy=$false; # (Optional) If $false, no VM will be started; if $true or 'All' all lab VMs will be started after Deploy script; if 'DeployedOnly' only newly created VMs will be started.
4444
InternetVLAN=""; # (Optional) If set, it will apply VLAN on Interent adapter connected to DC
45-
ManagementSubnetIDs=""; # (Optional) If set, it will add another dhcp-enable management networks.
4645
Linux=$false; # (Optional) If set to $true, required prerequisities for building Linux images with Packer will be configured.
4746
LinuxAdminName="linuxadmin"; # (Optional) If set, local user account with that name will be created in Linux image. If not, DomainAdminName will be used as a local account.
4847
SshKeyPath="$($env:USERPROFILE)\.ssh\id_rsa" # (Optional) If set, specified SSH key will be used to build and access Linux images.
@@ -193,10 +192,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M
193192
Example: TelemetryNickname="Jaromirk"
194193
If configured, telemetry will be sent with NickName to correlate data to specified NickName. So when leaderboards will be published, MSLab users will be able to see their own stats
195194
196-
ManagementSubnetIDs
197-
Example: ManagementSubnetIDs=0..3
198-
If configured, it will add another management subnet. For example if configured 0..3, it will add 3 more subnets 10.0.1.0/24 to 10.0.3.0/24 on VLANs that 11,12, and 13. (Because allowed VLANs are 1-10)
199-
200195
Linux (optional)
201196
Example: Linux=$true
202197
If set to $true, additional prerequisities (SSH Client, SSH Key, Packer, Packer templates) required for building Linux images will be downloaded and configured.
@@ -342,10 +337,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M
342337
Example (single command) CustomPowerShellCommands="New-Item -Name Temp -Path c:\ -ItemType Directory"
343338
Example (multiple commands) CustomPowerShellCommands="New-Item -Name Temp -Path c:\ -ItemType Directory","New-Item -Name Temp1 -Path c:\ -ItemType Directory"
344339
345-
ManagementSubnetID (Optional)
346-
This will set Management NICs to defined subnet id by configuring native VLAN ID. Default is 0. If configured to 1, it will increase highest allowed VLAN by one and configure.
347-
For example ManagementSubnetID=1, AllowedVlans=10, then ManagementSubnetID VLAN will be configured 11.
348-
349340
#DisableTimeIC (Optional)
350341
Example DisableTimeIC=$true
351342
if $true, time Hyper-V Time Synchronization Integration Service (VMICTimeProvider) will be disabled

0 commit comments

Comments
 (0)