Skip to content
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

[WIP] Support for additional network adapters in LabConfig #468

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Scripts/3_Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,34 @@ If (-not $isAdmin) {
$global:IP++
}

if($VMConfig.AdditionalNetworkAdapters) {
$networks = $VMConfig.AdditionalNetworkAdapters
if($networks -isnot [array]) {
$networks = @($networks)
}

foreach ($network in $networks) {
$switch = Get-VMSwitch -Name $network.VirtualSwitchName -ErrorAction SilentlyContinue
if(-not $switch) {
WriteErrorAndExit "Hyper-V switch $($network.VirtualSwitchName) not found."
}

$adapter = $vmtemp | Add-VMNetworkAdapter -SwitchName $network.VirtualSwitchName -Passthru

if($network.Mac -and $network.Mac -match "^([0-9A-F][0-9A-F]-){5}[0-9A-F][0-9A-F]$") {
$adapter | Set-VMNetworkAdapter -StaticMacAddress $network.Mac
}

if($network.VlanId -and $network.VlanId -ne 0) {
$adapter | Set-VMNetworkAdapterVlan -VlanId $network.VlanId -Access
}

if($network.IpConfiguration -and $network.IpConfiguration -ne "DHCP" -and $network.IpConfiguration -is [Hashtable]) {
$adapter | Set-VMNetworkConfiguration -IPAddress $network.IpConfiguration.IpAddress -Subnet $network.IpConfiguration.Subnet
}
}
}

#Generate DSC Config
if ($VMConfig.DSCMode -eq 'Pull'){
WriteInfo "`t Setting DSC Mode to Pull"
Expand Down
13 changes: 12 additions & 1 deletion Scripts/LabConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M
# Or Windows Server 2019
#1..4 | ForEach-Object {$VMNames="S2D"; $LABConfig.VMs += @{ VMName = "$VMNames$_" ; Configuration = 'S2D' ; ParentVHD = 'Win2019Core_G2.vhdx'; SSDNumber = 0; SSDSize=800GB ; HDDNumber = 12; HDDSize= 4TB ; MemoryStartupBytes= 512MB }}


### HELP ###

#If you need more help or different configuration options, ping us at jaromir.kaspar@dell.com or vlmach@microsoft.com
Expand Down Expand Up @@ -220,6 +219,18 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M
AdditionalNetworks (Optional)
$True - Additional networks (configured in AdditonalNetworkConfig) are added

AdditionalNetworkAdapters (Optional) - Hashtable or array if multiple network adapters should be connected to this virtual machine
@{
VirtualSwitchName (Mandatory) - Name of the Hyper-V Switch to witch the adapter will be connected
Mac (Optional) - Static MAC address of the interface otherwise default will be generated
VlanId (Optional) - VLAN ID for this adapter
IpConfiguration (Optional) - DHCP or hastable with specific IP configuration
@{
IpAddress (Mandatory) - Static IP Address that would be injected to the OS
Subnet (Mandatory)
}
}

DSCMode (Optional)
If 'Pull', VMs will be configured to Pull config from DC.

Expand Down