Skip to content

Fix vm shutdown #34

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

Merged
merged 2 commits into from
Apr 10, 2025
Merged

Fix vm shutdown #34

merged 2 commits into from
Apr 10, 2025

Conversation

justinc1
Copy link
Collaborator

Shutdown VM before DELETE. Timeout can be set with environ HC_VM_SHUTDOWN_TIMEOUT.

We always use cause=INTERNAL.
Compute json payload inside ModifyVMPowerState.

Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
@justinc1 justinc1 self-assigned this Apr 10, 2025
Copy link
Collaborator

@anazobec anazobec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @justinc1 👍.

Just small changes for the linters' sake.

Comment on lines 457 to 471
var waitSleep time.Duration = 5
var waitTime time.Duration = 0
for {
// wait on VM to stop
currentState, err := utils.GetVMPowerState(vmUUID, *restClient)
if err != nil {
return err
}
if currentState == "SHUTOFF" {
return nil
}
if waitTime > maxWaitTime {
break
}
time.Sleep(waitSleep * time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this linter error: Multiplication of durations: 'waitSleep * time.Second' (durationcheck). Apparently this is a common occurrence in Golang.

According to research, time.Duration is just another way of saying int64. So a way to fix this could be the following:

Suggested change
var waitSleep time.Duration = 5
var waitTime time.Duration = 0
for {
// wait on VM to stop
currentState, err := utils.GetVMPowerState(vmUUID, *restClient)
if err != nil {
return err
}
if currentState == "SHUTOFF" {
return nil
}
if waitTime > maxWaitTime {
break
}
time.Sleep(waitSleep * time.Second)
var waitSleep time.Duration = 5 * time.Second // from ns to s
var waitTime time.Duration = 0
for {
// wait on VM to stop
currentState, err := utils.GetVMPowerState(vmUUID, *restClient)
if err != nil {
return err
}
if currentState == "SHUTOFF" {
return nil
}
if waitTime > maxWaitTime {
break
}
time.Sleep(waitSleep)

Copy link
Collaborator

@anazobec anazobec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this PR. @justinc1, you may merge when ready.

Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
@justinc1 justinc1 merged commit 0a1dd34 into main Apr 10, 2025
7 checks passed
@justinc1 justinc1 deleted the fix-vm-shutdown branch April 10, 2025 13:48
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants