-
Notifications
You must be signed in to change notification settings - Fork 1
Salmanmkc/1 cleanup #2
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
base: user/bosira/remote-powershell-script
Are you sure you want to change the base?
Changes from all commits
171097d
9db7163
89ddd9a
cbc90fd
e804945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
|
|
||
| param( | ||
| [string]$SwitchName = "Default Switch", | ||
|
|
||
| [Parameter(Mandatory=$true)] | ||
| [string]$VMName, | ||
|
|
||
| [Parameter()] | ||
| [string]$Platform = "Hyper-V" | ||
| ) | ||
|
|
||
| if ($VMName) { | ||
| try{ | ||
salmanmkc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if ($Platform -eq "Hyper-V") { | ||
| $dirPath = "C:\Users\$env:USERNAME\.minikube\machines\$VMName" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split HyperV and Virtual box to seperate functions to make it easier to mange each of them
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, eventually will do, this is in draft state, not finished |
||
| Stop-VM -Name $VMName -Force | ||
| Remove-Vm -Name $VMName -Force | ||
| } | ||
| elseif ($Platform -eq "VirtualBox") { | ||
| $dirPath = "C:\Users\$env:USERNAME\VirtualBox VMs\$VMName" | ||
| & VBoxManage controlvm $VMName poweroff --type headless | ||
| & VBoxManage unregistervm $VMName --delete | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log message for success and if the plaform is not supported
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a validated set to this file too |
||
| Start-Sleep -Seconds 10 | ||
| } | ||
| catch { | ||
| Write-Warning "Couldn't stop the $VMName Virtual Machine. It doesn't exist. $_" | ||
salmanmkc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| try{ | ||
| if (Test-Path $dirPath) { | ||
| Remove-Item -Path $dirPath -Recurse -Force | ||
| "{0} - * The $dirPath directory has been removed." -f (Get-Date) >> logs | ||
| $VHDPath = "${env:homepath}\VirtualBox VMs\$VMName\VHD.vhdx" | ||
| # Unregister and delete the existing hard disk if it exists | ||
| if (Test-Path $VHDPath) { | ||
| & VBoxManage closemedium disk $VHDPath --delete | ||
| } | ||
| } | ||
| else { | ||
| Write-Warning "The $dirPath directory doesn't exist." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya good point |
||
| } | ||
|
|
||
| "{0} - * The $VMName Virtual Machine has been removed." -f (Get-Date) > logs | ||
| } | ||
| catch { | ||
| Write-Warning "Couldn't remove the $VMName directory. It doesn't exist. $_" | ||
| } | ||
| } | ||
| else { | ||
| Write-Warning "VMName is required" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ function Install-Containerd { | |
|
|
||
| $Version = $Version.TrimStart('v') | ||
| Write-Output "* Downloading and installing Containerd v$version at $InstallPath" | ||
| "Downloading and installing Containerd v$version at $InstallPath" >> logs | ||
| "{0} - Downloading and installing Containerd v$version at $InstallPath" -f (Get-Date) >> logs | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The timestamp is a good addition. However, we do not need to redirect each message to a logger, since we can do this: |
||
|
|
||
|
|
||
| # Download file from repo | ||
|
|
@@ -50,10 +50,10 @@ function Install-Containerd { | |
| Install-RequiredFeature @params | Out-Null | ||
|
|
||
| Write-Output "* Containerd v$version successfully installed at $InstallPath" | ||
| "Containerd v$version successfully installed at $InstallPath" >> logs | ||
| "{0} Containerd v$version successfully installed at $InstallPath" -f (Get-Date) >> logs | ||
| containerd.exe -v >> logs | ||
|
|
||
| "For containerd usage: run 'containerd -h'" >> logs | ||
| "{0} - For containerd usage: run 'containerd -h'" -f (Get-Date) >> logs | ||
| } | ||
|
|
||
| function Start-ContainerdService { | ||
|
|
@@ -69,15 +69,15 @@ function Start-ContainerdService { | |
| } | ||
|
|
||
| Write-Output "* Containerd is installed and the service is started ..." | ||
| "Containerd is installed and the service is started" >> logs | ||
| "{0} - Containerd is installed and the service is started" -f (Get-Date) >> logs | ||
|
|
||
| } | ||
|
|
||
| function Stop-ContainerdService { | ||
| $containerdStatus = Get-Service containerd -ErrorAction SilentlyContinue | ||
| if (!$containerdStatus) { | ||
| Write-Warning "Containerd service does not exist as an installed service." | ||
| "Containerd service does not exist as an installed service." >> logs | ||
| "{0} - Containerd service does not exist as an installed service." -f (Get-Date) >> logs | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -99,7 +99,7 @@ function Initialize-ContainerdService { | |
| $ContainerdPath = "$Env:ProgramFiles\containerd" | ||
| ) | ||
|
|
||
| "Configuring the containerd service" >> logs | ||
| "{0} - Configuring the containerd service" -f (Get-Date) >> logs | ||
|
|
||
| #Configure containerd service | ||
| $containerdConfigFile = "$ContainerdPath\config.toml" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,28 +36,49 @@ function Start-VirtualMachine { | |
|
|
||
| [String] | ||
| [ValidateNotNullOrEmpty()] | ||
| $ISOFile | ||
| $ISOFile, | ||
|
|
||
| [String] | ||
| [ValidateNotNullOrEmpty()] | ||
| $Platform = "Hyper-V" | ||
| ) | ||
|
|
||
| # set the vm switch first | ||
| $Switch = Set-VmSwitch -SwitchName $SwitchName | ||
| if($Platform -eq "Hyper-V"){ | ||
| # set the vm switch first | ||
| $Switch = Set-VmSwitch -SwitchName $SwitchName | ||
| $VM = @{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split HyperV and Virtual box to seperate functions to make it easier to mange each of them
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya will do eventually, wanted to push code a bit earlier, will clean up eventually when finished with everything else on this PR |
||
| Name = $VMName | ||
| MemoryStartupBytes = 1GB | ||
| NewVHDPath = "${env:homepath}\.minikube\machines\$VMName\VHD.vhdx" | ||
| NewVHDSizeBytes = 10GB | ||
| BootDevice = "VHD" | ||
| Path = "${env:homepath}\.minikube\machines\" | ||
| SwitchName = $Switch.Name | ||
| } | ||
|
|
||
| $VM = @{ | ||
| Name = $VMName | ||
| MemoryStartupBytes = 1GB | ||
| NewVHDPath = "${env:homepath}\.minikube\machines\$VMName\VHD.vhdx" | ||
| NewVHDSizeBytes = 10GB | ||
| BootDevice = "VHD" | ||
| Path = "${env:homepath}\.minikube\machines\" | ||
| SwitchName = $Switch.Name | ||
| New-VM @VM | ||
|
|
||
| Set-VM -Name $VMName -ProcessorCount 2 -AutomaticCheckpointsEnabled $false | ||
| Set-VMProcessor -VMName $VMName -ExposeVirtualizationExtensions $true | ||
| Set-VMDvdDrive -VMName $VMName -Path $ISOFile | ||
| Start-VM -Name $VMName | ||
| } | ||
| elseif ($Platform -eq "VirtualBox") { | ||
| $VM = @{ | ||
| Name = $VMName; | ||
| OSType = "Windows10_64"; | ||
| Register = $true; | ||
| BaseFolder = "${env:homepath}\VirtualBox VMs"; | ||
| } | ||
| & VBoxManage createvm --name $VM.Name --ostype $VM.OSType --register --basefolder $VM.BaseFolder | ||
| & VBoxManage modifyvm $VMName --cpus 2 --memory 1024 | Out-Null | ||
| & VBoxManage createmedium disk --filename "${env:homepath}\VirtualBox VMs\$VMName\VHD.vhdx" --size 15000 | Out-Null | ||
| & VBoxManage storagectl $VMName --name "IDE Controller" --add ide | ||
| & VBoxManage storageattach $VMName --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "${env:homepath}\VirtualBox VMs\$VMName\VHD.vhdx" | Out-Null | ||
| & VBoxManage storageattach $VMName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $ISOFilePath | Out-Null | ||
| & VBoxManage startvm $VMName --type headless | Out-Null | ||
| & VBoxManage modifyvm $VMName --nic1 bridged --bridgeadapter1 $Switch.Name --cableconnected1 on | ||
| } | ||
|
|
||
| New-VM @VM | ||
|
|
||
| Set-VM -Name $VMName -ProcessorCount 2 -AutomaticCheckpointsEnabled $false | ||
| Set-VMProcessor -VMName $VMName -ExposeVirtualizationExtensions $true | ||
| Set-VMDvdDrive -VMName $VMName -Path $ISOFile | ||
| Start-VM -Name $VMName | ||
| } | ||
|
|
||
| function Set-NodeForMinikube { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.