Some checks failed
CD Pipeline / workflow-shape (push) Successful in 1s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 2m17s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
123 lines
5.9 KiB
PowerShell
123 lines
5.9 KiB
PowerShell
param(
|
|
[string]$Alias = "111",
|
|
[string]$ExpectedVmxPath = "D:\Documents\Virtual Machines\192.168.0.111_Ubuntu_64-bit\192.168.0.111_Ubuntu_64-bit.vmx",
|
|
[string[]]$DiscoveryRoot = @(
|
|
"D:\Documents\Virtual Machines",
|
|
"D:\Downloads",
|
|
"D:\VMs",
|
|
"E:\VMs",
|
|
"C:\VMs",
|
|
"C:\Users\Public\Documents\Virtual Machines"
|
|
),
|
|
[int]$MaxResults = 120,
|
|
[switch]$IncludeIdentityMetadata
|
|
)
|
|
|
|
$ErrorActionPreference = "SilentlyContinue"
|
|
$ProgressPreference = "SilentlyContinue"
|
|
|
|
$identityPatterns = "^(displayName|guestOS|ethernet0\.addressType|ethernet0\.generatedAddress|uuid\.bios|uuid\.location|scsi0:0\.fileName|ide1:0\.fileName)\s*="
|
|
|
|
Write-Output "AWOOOI_WINDOWS99_VMX_LOCATE_CHECK=1"
|
|
Write-Output "target_alias=$Alias"
|
|
Write-Output "secret_value_read=false"
|
|
Write-Output "remote_write_performed=false"
|
|
Write-Output "vm_power_change_performed=false"
|
|
Write-Output "windows_service_restart_performed=false"
|
|
Write-Output "windows_registry_apply_performed=false"
|
|
Write-Output "identity_metadata_read=$([int][bool]$IncludeIdentityMetadata)"
|
|
Write-Output "expected_vmx_path=$ExpectedVmxPath"
|
|
Write-Output "expected_vmx_exists=$([int](Test-Path -LiteralPath $ExpectedVmxPath))"
|
|
|
|
$candidateCount = 0
|
|
$aliasHintCount = 0
|
|
$unassignedUbuntuCandidateCount = 0
|
|
$identityTargetHintCount = 0
|
|
$identityUnassignedUbuntuCandidateCount = 0
|
|
|
|
foreach ($root in $DiscoveryRoot) {
|
|
$rootExists = Test-Path -LiteralPath $root
|
|
Write-Output "ROOT path=$root exists=$([int]$rootExists)"
|
|
if (-not $rootExists) {
|
|
continue
|
|
}
|
|
|
|
$files = @(
|
|
Get-ChildItem -LiteralPath $root -Recurse -Filter "*.vmx" -File -ErrorAction SilentlyContinue |
|
|
Select-Object -First $MaxResults
|
|
)
|
|
|
|
foreach ($file in $files) {
|
|
$candidateCount += 1
|
|
$aliasHint = [int]($file.FullName -match [regex]::Escape($Alias))
|
|
$ubuntuHint = [int]($file.FullName -match "Ubuntu|ubuntu")
|
|
if ($aliasHint -eq 1) {
|
|
$aliasHintCount += 1
|
|
}
|
|
if ($aliasHint -eq 0 -and $ubuntuHint -eq 1) {
|
|
$unassignedUbuntuCandidateCount += 1
|
|
}
|
|
Write-Output "VMX_FILE path=$($file.FullName) alias_hint=$aliasHint ubuntu_hint=$ubuntuHint size=$($file.Length)"
|
|
|
|
if ($IncludeIdentityMetadata) {
|
|
$identityLines = @(
|
|
Select-String -LiteralPath $file.FullName -Pattern $identityPatterns -ErrorAction SilentlyContinue |
|
|
Select-Object -First 20
|
|
)
|
|
$displayName = ""
|
|
foreach ($match in $identityLines) {
|
|
$line = $match.Line -replace "`r", ""
|
|
if ($line -match "^displayName\s*=\s*`"(.+)`"") {
|
|
$displayName = $Matches[1]
|
|
}
|
|
Write-Output "VMX_IDENTITY_FIELD path=$($file.FullName) $line"
|
|
}
|
|
$knownNonTargetAlias = [int]($displayName -match "192\.168\.0\.(110|112|120|121|188)")
|
|
$targetAliasIdentityHint = [int]($displayName -match "192\.168\.0\.$Alias")
|
|
$genericUnassignedIdentityHint = [int](
|
|
$ubuntuHint -eq 1 -and
|
|
$knownNonTargetAlias -eq 0 -and
|
|
$targetAliasIdentityHint -eq 0
|
|
)
|
|
if ($targetAliasIdentityHint -eq 1) {
|
|
$identityTargetHintCount += 1
|
|
}
|
|
if ($genericUnassignedIdentityHint -eq 1) {
|
|
$identityUnassignedUbuntuCandidateCount += 1
|
|
}
|
|
Write-Output "VMX_IDENTITY_SUMMARY path=$($file.FullName) display_name=$displayName known_non_target_alias=$knownNonTargetAlias target_alias_identity_hint=$targetAliasIdentityHint generic_unassigned_identity_hint=$genericUnassignedIdentityHint"
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Output "candidate_vmx_count=$candidateCount"
|
|
Write-Output "alias_hint_candidate_count=$aliasHintCount"
|
|
Write-Output "unassigned_ubuntu_candidate_count=$unassignedUbuntuCandidateCount"
|
|
Write-Output "identity_target_hint_count=$identityTargetHintCount"
|
|
Write-Output "identity_unassigned_ubuntu_candidate_count=$identityUnassignedUbuntuCandidateCount"
|
|
if ((Test-Path -LiteralPath $ExpectedVmxPath)) {
|
|
Write-Output "locate_status=expected_vmx_path_present"
|
|
Write-Output "safe_next_step=rerun_windows99_vmware_verify_collector_no_secret"
|
|
} elseif ($aliasHintCount -gt 0) {
|
|
Write-Output "locate_status=alias_hint_candidate_found"
|
|
Write-Output "safe_next_step=build_scoped_relink_dry_run_for_alias_hint_candidate_then_post_verify"
|
|
} elseif ($IncludeIdentityMetadata -and $identityTargetHintCount -gt 0) {
|
|
Write-Output "locate_status=identity_target_hint_candidate_found"
|
|
Write-Output "safe_next_step=build_scoped_relink_dry_run_for_identity_hint_candidate_then_post_verify"
|
|
} elseif ($IncludeIdentityMetadata -and $identityUnassignedUbuntuCandidateCount -eq 1) {
|
|
Write-Output "locate_status=single_identity_unassigned_ubuntu_candidate_requires_confirmation"
|
|
Write-Output "safe_next_step=confirm_single_unassigned_ubuntu_candidate_is_target_alias_before_scoped_relink_dry_run"
|
|
} elseif ($IncludeIdentityMetadata -and $identityUnassignedUbuntuCandidateCount -gt 1) {
|
|
Write-Output "locate_status=multiple_identity_unassigned_ubuntu_candidates_requires_confirmation"
|
|
Write-Output "safe_next_step=confirm_candidate_identity_before_any_relink_or_restore"
|
|
} elseif ($unassignedUbuntuCandidateCount -eq 1) {
|
|
Write-Output "locate_status=single_unassigned_ubuntu_candidate_requires_identity_confirmation"
|
|
Write-Output "safe_next_step=confirm_unassigned_ubuntu_candidate_identity_before_scoped_relink_dry_run"
|
|
} elseif ($unassignedUbuntuCandidateCount -gt 1) {
|
|
Write-Output "locate_status=multiple_unassigned_ubuntu_candidates_requires_identity_confirmation"
|
|
Write-Output "safe_next_step=confirm_candidate_identity_before_any_relink_or_restore"
|
|
} else {
|
|
Write-Output "locate_status=no_candidate_found"
|
|
Write-Output "safe_next_step=restore_vmx_source_from_verified_backup_artifact_then_post_verify_no_vm_power_change"
|
|
}
|