Skip to content

Commit

Permalink
Updating activation logic for verify function to call activation dire…
Browse files Browse the repository at this point in the history
…ctly (#261)
  • Loading branch information
bkatyl authored Dec 9, 2024
1 parent 77ac439 commit 75b2f94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
18 changes: 7 additions & 11 deletions sysprep/activate_instance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ function Verify-PAYGLicense {
$licenseID = (Invoke-RestMethod -Headers @{'Metadata-Flavor' = 'Google'} -Uri "http://169.254.169.254/computeMetadata/v1/instance/licenses/$licenseIndex/id").ToString()
if ($paygLicenses.Contains($licenseID)) {
Write-Output "PAYG license $licenseID found."
return $true
Activate-Instance
return
}
}
Write-Output 'No PAYG license found.'
return $false
Write-Output 'PAYG license not found, skipping GCE activation'
return
}
catch {
Write-Output "Failed to identify if a PAYG license is attached. Error: $_"
return $false
return
}
return $false
return
}

function Activate-Instance {
Expand Down Expand Up @@ -358,10 +359,5 @@ if (Test-Path "$env:ProgramFiles\Google\Compute Engine\sysprep\byol_image") {
Write-Output 'Image imported into GCE via BYOL workflow, skipping GCE activation'
}
else {
if (Verify-PAYGLicense -eq $true){
Activate-Instance
}
else {
Write-Output 'PAYG license not found, skipping GCE activation'
}
Verify-PAYGLicense
}
1 change: 1 addition & 0 deletions sysprep/sysprep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ try {

# Delete the tag file so we don't think it already succeeded.
if (Test-Path $script:sysprep_tag) {
Write-Log "Removing $script:sysprep_tag"
Remove-Item $script:sysprep_tag
}

Expand Down

0 comments on commit 75b2f94

Please sign in to comment.