fix(recovery): apply windows 99 vmware autostart truth
Some checks failed
CD Pipeline / workflow-shape (push) Has been cancelled
CD Pipeline / cancel-stale-cd (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
Some checks failed
CD Pipeline / workflow-shape (push) Has been cancelled
CD Pipeline / cancel-stale-cd (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
This commit is contained in:
@@ -18,11 +18,16 @@ def test_reboot_p0_contract_covers_all_required_hosts_and_vmware_autostart() ->
|
||||
assert host in host_probe
|
||||
assert "AWOOOI-Start-VMware-VMs" in windows99
|
||||
assert "NoAutoRebootWithLoggedOnUsers" in windows99
|
||||
assert "Host110Vmx" in windows99
|
||||
assert "Host111Vmx" in windows99
|
||||
assert "Host188Vmx" in windows99
|
||||
assert "Host120Vmx" in windows99
|
||||
assert "Host121Vmx" in windows99
|
||||
assert "Host112Vmx" in windows99
|
||||
assert "D:\\Documents\\Virtual Machines" in windows99
|
||||
assert "D:\\Downloads" in windows99
|
||||
assert "HOST111_VMWARE_TARGET=not_required_by_default_missing_no_vmx_found_on_99" in windows99
|
||||
assert "VM_ALREADY_RUNNING" in windows99
|
||||
|
||||
|
||||
def test_reboot_p0_contract_has_maintenance_and_telegram_alerts() -> None:
|
||||
|
||||
@@ -2,12 +2,21 @@ param(
|
||||
[ValidateSet("Verify", "DryRun", "Apply")]
|
||||
[string]$Mode = "Verify",
|
||||
[string]$VmrunPath = "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe",
|
||||
[string]$Host110Vmx = "",
|
||||
[string]$Host111Vmx = "",
|
||||
[string]$Host188Vmx = "",
|
||||
[string]$Host120Vmx = "",
|
||||
[string]$Host121Vmx = "",
|
||||
[string]$Host112Vmx = "",
|
||||
[string[]]$DiscoveryRoot = @("D:\VMs", "E:\VMs", "C:\VMs", "C:\Users\Public\Documents\Virtual Machines")
|
||||
[string[]]$RequiredVmAliases = @("110", "188", "120", "121", "112"),
|
||||
[string[]]$DiscoveryRoot = @(
|
||||
"D:\Documents\Virtual Machines",
|
||||
"D:\Downloads",
|
||||
"D:\VMs",
|
||||
"E:\VMs",
|
||||
"C:\VMs",
|
||||
"C:\Users\Public\Documents\Virtual Machines"
|
||||
)
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -15,14 +24,22 @@ $ErrorActionPreference = "Stop"
|
||||
$TaskName = "AWOOOI-Start-VMware-VMs"
|
||||
$ProgramDataDir = "C:\ProgramData\AWOOOI"
|
||||
$StartScript = Join-Path $ProgramDataDir "Start-AWOOOI-VMs.ps1"
|
||||
$VmOrder = @("111", "188", "120", "121", "112")
|
||||
$VmOrder = $RequiredVmAliases
|
||||
$SuppliedVmx = @{
|
||||
"110" = $Host110Vmx
|
||||
"111" = $Host111Vmx
|
||||
"188" = $Host188Vmx
|
||||
"120" = $Host120Vmx
|
||||
"121" = $Host121Vmx
|
||||
"112" = $Host112Vmx
|
||||
}
|
||||
$KnownVmxCandidates = @{
|
||||
"110" = @("D:\Documents\Virtual Machines\Ubuntu 64-bit (3)\Ubuntu 64-bit (3).vmx")
|
||||
"188" = @("D:\Documents\Virtual Machines\Ollama_Ubuntu_64-bit\Ollama_Ubuntu_64-bit.vmx")
|
||||
"120" = @("D:\Documents\Virtual Machines\192.168.0.120_Ubuntu_64-bit\192.168.0.120_Ubuntu_64-bit.vmx")
|
||||
"121" = @("D:\Documents\Virtual Machines\192.168.0.121_Ubuntu_64-bit\192.168.0.121_Ubuntu_64-bit.vmx")
|
||||
"112" = @("D:\Downloads\kali-linux-2025.4-vmware-amd64\kali-linux-2025.4-vmware-amd64.vmwarevm\kali-linux-2025.4-vmware-amd64.vmx")
|
||||
}
|
||||
|
||||
function Resolve-VmxPath {
|
||||
param([string]$HostAlias)
|
||||
@@ -32,12 +49,28 @@ function Resolve-VmxPath {
|
||||
return (Resolve-Path -LiteralPath $supplied).Path
|
||||
}
|
||||
|
||||
foreach ($candidate in @($KnownVmxCandidates[$HostAlias])) {
|
||||
if ($candidate -and (Test-Path -LiteralPath $candidate)) {
|
||||
return (Resolve-Path -LiteralPath $candidate).Path
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($root in $DiscoveryRoot) {
|
||||
if (-not (Test-Path -LiteralPath $root)) {
|
||||
continue
|
||||
}
|
||||
$match = Get-ChildItem -LiteralPath $root -Recurse -Filter "*.vmx" -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.FullName -match "(^|[\\_\-\s])$HostAlias([\\_\-\s]|$)" } |
|
||||
Where-Object {
|
||||
$displayName = ""
|
||||
try {
|
||||
$displayName = (Select-String -LiteralPath $_.FullName -Pattern "^displayName\s*=\s*" -ErrorAction SilentlyContinue |
|
||||
Select-Object -First 1).Line
|
||||
} catch {
|
||||
$displayName = ""
|
||||
}
|
||||
$_.FullName -match "(^|[\\_\-\s])$HostAlias([\\_\-\s]|$)" -or
|
||||
$displayName -match "(^|[\\_\-\s])$HostAlias([\\_\-\s]|$)"
|
||||
} |
|
||||
Select-Object -First 1
|
||||
if ($match) {
|
||||
return $match.FullName
|
||||
@@ -70,14 +103,18 @@ $($vmRows -join ",`n")
|
||||
|
||||
Start-Service -Name "VMAuthdService" -ErrorAction SilentlyContinue
|
||||
Start-Service -Name "VMnetDHCP" -ErrorAction SilentlyContinue
|
||||
Start-Service -Name "VMware NAT Service" -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 30
|
||||
`$running = (& `$VmrunPath list 2>`$null) -join [Environment]::NewLine
|
||||
|
||||
foreach (`$vm in `$VMs) {
|
||||
if (-not (Test-Path -LiteralPath `$vm.Path)) {
|
||||
Write-Output "VMX_MISSING alias=`$(`$vm.Alias) path=`$(`$vm.Path)"
|
||||
continue
|
||||
}
|
||||
if (`$running -like "*`$(`$vm.Path)*") {
|
||||
Write-Output "VM_ALREADY_RUNNING alias=`$(`$vm.Alias) path=`$(`$vm.Path)"
|
||||
continue
|
||||
}
|
||||
& `$VmrunPath -T ws start `$vm.Path nogui
|
||||
Write-Output "VM_START_REQUESTED alias=`$(`$vm.Alias) path=`$(`$vm.Path) exit=`$LASTEXITCODE"
|
||||
Start-Sleep -Seconds 20
|
||||
@@ -126,6 +163,11 @@ $vmrunPresent = Test-Path -LiteralPath $VmrunPath
|
||||
Write-Output "AWOOOI_WINDOWS99_VMWARE_AUTOSTART=1"
|
||||
Write-Output "MODE=$Mode"
|
||||
Write-Output "VMRUN_PRESENT=$([int]$vmrunPresent)"
|
||||
if ($SuppliedVmx["111"] -or $VmOrder -contains "111") {
|
||||
Write-Output "HOST111_VMWARE_TARGET=explicit_or_required"
|
||||
} else {
|
||||
Write-Output "HOST111_VMWARE_TARGET=not_required_by_default_missing_no_vmx_found_on_99"
|
||||
}
|
||||
foreach ($alias in $VmOrder) {
|
||||
Write-Output "VMX alias=$alias path=$($vmMap[$alias]) present=$([int][bool]$vmMap[$alias])"
|
||||
}
|
||||
@@ -155,7 +197,6 @@ if ($Mode -eq "DryRun") {
|
||||
Write-StartupScript -VmMap $vmMap
|
||||
Set-Service -Name "VMAuthdService" -StartupType Automatic -ErrorAction SilentlyContinue
|
||||
Set-Service -Name "VMnetDHCP" -StartupType Automatic -ErrorAction SilentlyContinue
|
||||
Set-Service -Name "VMware NAT Service" -StartupType Automatic -ErrorAction SilentlyContinue
|
||||
Apply-ScheduledTask
|
||||
Apply-WindowsUpdatePolicy
|
||||
|
||||
|
||||
Reference in New Issue
Block a user