-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Windows OVS Container to run on pristine Host Environment
Signed-off-by: Naman Agarwal <naman.agarwal75@gmail.com>
- Loading branch information
Showing
3 changed files
with
163 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
$ErrorActionPreference = "Stop" | ||
$OVSVersion = "3.0.5-antrea.0" | ||
$OVSDownloadURL = "https://downloads.antrea.io/ovs/ovs-$OVSVersion-win64.zip" | ||
$OVSPublishedHash = 'fd27703ef7314b26b98cffb7aea27d569530ebd3ac3c98daa981ca2654373032' | ||
$WorkDir = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) | ||
$OVSDownloadDir = $WorkDir | ||
$OVSInstallDir = "C:\openvswitch" | ||
$OVSZip = "$OVSDownloadDir\ovs-win64.zip" | ||
$ImportCertificate = $true | ||
$CheckFileHash = $true | ||
$PowerShellModuleBase = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules" | ||
$InstallLog = "$OVSDownloadDir\install_ovs.log" | ||
|
||
function Log($Info) { | ||
$time = $(get-date -Format g) | ||
"$time $Info `n`r" | Tee-Object $InstallLog -Append | Write-Host | ||
} | ||
|
||
function CreatePath($Path){ | ||
if ($(Test-Path $Path)) { | ||
mv $Path $($Path + "_bak") | ||
} | ||
mkdir -p $Path | Out-Null | ||
} | ||
|
||
function SetEnvVar($key, $value) { | ||
[Environment]::SetEnvironmentVariable($key, $value, [EnvironmentVariableTarget]::Machine) | ||
} | ||
|
||
function WaitExpandFiles($Src, $Dest) { | ||
Log "Extract $Src to $Dest" | ||
Expand-Archive -Path $Src -DestinationPath $Dest | Out-Null | ||
} | ||
|
||
function CheckIfOVSInstalled() { | ||
if (Test-Path -Path $OVSInstallDir) { | ||
Log "$OVSInstallDir already exists, exit OVS installation." | ||
exit 1 | ||
} | ||
} | ||
|
||
If (!(Test-Path $OVSDownloadDir)) { | ||
mkdir -p $OVSDownloadDir | ||
} | ||
Log "Downloading OVS package from $OVSDownloadURL to $OVSZip" | ||
curl.exe -sLo $OVSZip $OVSDownloadURL | ||
If (!$?) { | ||
Log "Download OVS failed, URL: $OVSDownloadURL" | ||
exit 1 | ||
} | ||
|
||
if ($CheckFileHash) { | ||
$FileHash = Get-FileHash $OVSZip | ||
If ($OVSPublishedHash -ne "" -And $FileHash.Hash -ne $OVSPublishedHash) { | ||
Log "SHA256 mismatch for OVS download" | ||
exit 1 | ||
} | ||
} | ||
|
||
WaitExpandFiles $OVSZip $OVSDownloadDir | ||
# Copy OVS package to target dir. | ||
Log "Copying OVS package from $OVSDownloadDir\openvswitch to $OVSInstallDir" | ||
mv "$OVSDownloadDir\openvswitch" $OVSInstallDir | ||
rm $OVSZip | ||
# Create log and run dir. | ||
$OVS_LOG_PATH = $OVSInstallDir + "\var\log\openvswitch" | ||
CreatePath $OVS_LOG_PATH | ||
$OVSRunDir = $OVSInstallDir + "\var\run\openvswitch" | ||
CreatePath $OVSRunDir | ||
$OVSDriverDir = "$OVSInstallDir\driver" | ||
|
||
# Install OVS driver certificate. | ||
$DriverFile="$OVSDriverDir\OVSExt.sys" | ||
if ($ImportCertificate) { | ||
$CertificateFile = "$OVSDriverDir\package.cer" | ||
if (!(Test-Path $CertificateFile)) { | ||
$ExportType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert; | ||
$Cert = (Get-AuthenticodeSignature $DriverFile).SignerCertificate; | ||
[System.IO.File]::WriteAllBytes($CertificateFile, $Cert.Export($ExportType)); | ||
} | ||
Log "Installing OVS driver certificate." | ||
Import-Certificate -FilePath "$CertificateFile" -CertStoreLocation cert:\LocalMachine\TrustedPublisher | ||
Import-Certificate -FilePath "$CertificateFile" -CertStoreLocation cert:\LocalMachine\Root | ||
} | ||
|
||
# Install Microsoft Visual C++ Redistributable Package. | ||
if (Test-Path $OVSInstallDir\redist) { | ||
Log "Installing Microsoft Visual C++ Redistributable Package." | ||
$RedistFiles = Get-ChildItem "$OVSInstallDir\redist" -Filter *.exe | ||
$RedistFiles | ForEach-Object { | ||
Log "Installing $_" | ||
Start-Process -FilePath $_.FullName -Args '/install /passive /norestart' -Verb RunAs -Wait | ||
} | ||
} | ||
|
||
# Install powershell modules | ||
if (Test-Path $OVSInstallDir\scripts) { | ||
Log "Installing powershell modules." | ||
$PSModuleFiles = Get-ChildItem "$OVSInstallDir\scripts" -Filter *.psm1 | ||
$PSModuleFiles | ForEach-Object { | ||
$PSModulePath = Join-Path -Path $PowerShellModuleBase -ChildPath $_.BaseName | ||
if (!(Test-Path $PSModulePath)) { | ||
Log "Installing $_" | ||
mkdir -p $PSModulePath | ||
Copy-Item $_.FullName $PSModulePath | ||
} | ||
} | ||
} | ||
|
||
# Install OVS kernel driver. | ||
Log "Installing OVS kernel driver" | ||
$VMMSStatus = $(Get-Service vmms -ErrorAction SilentlyContinue).Status | ||
if (!$VMMSStatus) { | ||
$VMMSStatus = "not exist" | ||
} | ||
Log "Hyper-V Virtual Machine Management service status: $VMMSStatus" | ||
if ($VMMSStatus -eq "Running") { | ||
cmd /c "cd $OVSDriverDir && install.cmd" | ||
} else { | ||
cd $OVSDriverDir ; netcfg -l .\ovsext.inf -c s -i OVSExt; cd $WorkDir | ||
} | ||
if (!$?) { | ||
Log "Install OVS kernel driver failed, exit" | ||
exit 1 | ||
} | ||
|
||
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT | ||
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/') | ||
$env:PATH = $env:PATH + ";$mountPath/Windows/System32;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin" | ||
$OVS_DB_SCHEMA_PATH = "$mountPath/openvswitch/usr/share/openvswitch/vswitch.ovsschema" | ||
$OVS_DB_PATH = "C:\openvswitch\etc\openvswitch\conf.db" | ||
if ($(Test-Path $OVS_DB_SCHEMA_PATH) -and !$(Test-Path $OVS_DB_PATH)) { | ||
ovsdb-tool create "$OVS_DB_PATH" "$OVS_DB_SCHEMA_PATH" | ||
} | ||
ovsdb-server $OVS_DB_PATH -vfile:info --remote=punix:db.sock --log-file=/var/log/antrea/openvswitch/ovsdb-server.log --pidfile --detach | ||
ovs-vsctl --no-wait init | ||
|
||
# Set OVS version. | ||
$OVS_VERSION=$(Get-Item $mountPath\openvswitch\driver\OVSExt.sys).VersionInfo.ProductVersion | ||
ovs-vsctl --no-wait set Open_vSwitch . ovs_version=$OVS_VERSION | ||
|
||
ovs-vswitchd --log-file=/var/log/antrea/openvswitch/ovs-vswitchd.log --pidfile -vfile:info --detach | ||
|
||
$SleepInterval = 30 | ||
Write-Host "Started the loop that checks OVS status every $SleepInterval seconds" | ||
while ($true) { | ||
if ( !( Get-Process ovsdb-server ) ) { | ||
Write-Host "ovsdb-server is not running, starting it again..." | ||
ovsdb-server $OVS_DB_PATH -vfile:info --remote=punix:db.sock --log-file=/var/log/antrea/openvswitch/ovsdb-server.log --pidfile --detach | ||
} | ||
if ( !( Get-Process ovs-vswitchd ) ) { | ||
Write-Host "ovs-vswitchd is not running, starting it again..." | ||
ovs-vswitchd --log-file=/var/log/antrea/openvswitch/ovs-vswitchd.log --pidfile -vfile:info --detach | ||
} | ||
Start-Sleep -Seconds $SleepInterval | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters