Skip to content

Instantly share code, notes, and snippets.

@glennswest
Created July 25, 2018 17:39
Show Gist options
  • Save glennswest/b7f606ff41167f7abfc68fb646a4ec2b to your computer and use it in GitHub Desktop.
Save glennswest/b7f606ff41167f7abfc68fb646a4ec2b to your computer and use it in GitHub Desktop.
$a = Test-Path "C:\k\network_setup.lock"
IF ($a -eq "True") {Write-Host "Network Already Installed";exit}
Write-Host "Installing Network"
date > c:\k\network_setup.lock
$ErrorActionPreference = "SilentlyContinue"
$roughname = Get-NetAdapter | where adminstatus -eq "up" | Format-List -Property "Name" | Out
-String
$INTERFACE_ALIAS= $roughname.Substring(11)
Stop-Service ovs-vswitchd -force; Get-VMSwitch -SwitchType External | Disable-VMSwitchExtension "Cloudbase Open vSwitch Extension"
Get-VMSwitch -SwitchType External | Set-VMSwitch -AllowManagementOS $false
# Ignore the error from the first command
Get-VMSwitch -SwitchType External | Set-VMSwitch -AllowManagementOS $false
ovs-vsctl --no-wait --may-exist add-br br-ex
ovs-vsctl --no-wait add-port br-ex "$INTERFACE_ALIAS"
Get-VMSwitch -SwitchType External | Enable-VMSwitchExtension "Cloudbase Open vSwitch Extension"; sleep 2; Restart-Service ovs-vswitchd
# Clone the MAC Address of $INTERFACE_ALIAS on br-ex
$MAC_ADDRESS=$(Get-NetAdapter "$INTERFACE_ALIAS").MacAddress
$FAKE_MAC_ADDRESS=$MAC_ADDRESS.Substring(0,15)+"99"
Set-NetAdapter -Name "$INTERFACE_ALIAS" -MacAddress $FAKE_MAC_ADDRESS -Confirm:$false
Set-NetAdapter -Name br-ex -MacAddress $MAC_ADDRESS -Confirm:$false
# br-ex will get all the interface details from the DHCP server now
Enable-NetAdapter br-ex
# Make sure arp etc is update to date
ping 8.8.8.8
Write-Host "SDN Network is setup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment