Skip to content

Instantly share code, notes, and snippets.

@rosskirkpat
Created April 13, 2021 17:18
Show Gist options
  • Save rosskirkpat/063416fdf5512adc99fab85a411f7947 to your computer and use it in GitHub Desktop.
Save rosskirkpat/063416fdf5512adc99fab85a411f7947 to your computer and use it in GitHub Desktop.
Invoke-WebRequest -useb https://github.com/containernetworking/plugins/releases/download/v0.9.1/cni-plugins-windows-amd64-v0.9.1.tgz -OutFile c:\opt\cni\bin\cni-plugins.tgz
$sourceVipJson = [io.Path]::Combine($Global:BaseDir, "sourceVip.json")
$sourceVipRequest = [io.Path]::Combine($Global:BaseDir, "sourceVipRequest.json")
$hnsNetwork = Get-HnsNetwork | ? Name -EQ flannel.4096
$subnet = $hnsNetwork.Subnets[0].AddressPrefix
$ipamConfig = @"
{"cniVersion": "0.3.0", "name": "flannel.4096", "ipam":{"type":"host-local","ranges":[[{"subnet":"10.42.2.0/24"}]],"dataDir":"/var/lib/cni/networks"}}
"@
$ipamConfig | Out-File sourceVipRequest.json
pushd
$env:CNI_COMMAND="ADD"
$env:CNI_CONTAINERID="dummy"
$env:CNI_NETNS="dummy"
$env:CNI_IFNAME="dummy"
$env:CNI_PATH="c:\opt\cni\bin"
Get-Content sourceVipRequest.json | .\host-local.exe | Out-File sourceVip.json
$sourceVipJSONData = Get-Content sourceVip.json | ConvertFrom-Json
Remove-Item env:CNI_COMMAND
Remove-Item env:CNI_CONTAINERID
Remove-Item env:CNI_NETNS
Remove-Item env:CNI_IFNAME
Remove-Item env:CNI_PATH
popd
return $sourceVipJSONData.ips[0].address.Split("/")[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment