-
Notifications
You must be signed in to change notification settings - Fork 462
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
Fix domain running status fails when shutdown expected (#622) #1029
base: main
Are you sure you want to change the base?
Conversation
@luc-phan, Thank you for the PR. I was about to create a PR for this issue and I noticed that you already did. I hope we can collaborate on this together. I looked at your code. It's well written. However if the domain is created with the running at false, then switched to true during update, it will start the domain and immediately issue a shutdown. What I did in my case was to leverage the existing code and implement the same functionality in just 4 lines of code and avoid the issue explained above. diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go
index 5565d8542..c0d86aeeb 100644
--- a/libvirt/resource_libvirt_domain.go
+++ b/libvirt/resource_libvirt_domain.go
@@ -675,7 +675,7 @@ func resourceLibvirtDomainUpdate(ctx context.Context, d *schema.ResourceData, me
return diag.FromErr(err)
}
- if !domainRunningNow {
+ if !domainRunningNow && d.Get("running").(bool) {
err = virConn.DomainCreate(domain)
if err != nil {
return diag.Errorf("error creating libvirt domain: %s", err)
@@ -756,6 +756,9 @@ func resourceLibvirtDomainUpdate(ctx context.Context, d *schema.ResourceData, me
}
}
+ if err := destroyDomainByUserRequest(virConn, d, domain); err != nil {
+ return diag.FromErr(err)
+ }
return nil
}
Let me know what you think. This is a link to the commit I made tiaden@06341a4 |
No. It will not issue a shutdown, but there is some redundant code... The VM is started...
I think it's what you mean. Thank you, I didn't noticed that. I'm going to fix it.
Indeed, your code is better, it leverages the existing code, and the VM is not started twice. I'm going to fix my PR anyway, even though it's rejected, because I'm still learning, and it's a good exercise for me :) |
I added 2 arguments :
|
This PR fixes the issue of the guest not being shutdown when updating
running
tofalse
(#622).The expected state is
shut off
.