Skip to content
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: Network is not started if inactive #1095 #1097

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ne-bknn
Copy link

@ne-bknn ne-bknn commented Sep 11, 2024

Includes network activity status in terraform state, thus allowing terraform to update network resource in case it is inactive (e.g. after hypervisor reboot or virsh net-destroy)

Network activity is checked in Update method, but not in Read, its not recorded in local state. This makes terraform think that network should not be updated (since the state matches recorded one). Then, VM initialization fails, since it depends on an inactive network.

First brought up in #1095.

Includes network activity status in terraform state,
thus allowing terraform to update network resource
in case it is inactive (e.g. after hypervisor reboot
or `virsh net-destroy`)
@ne-bknn
Copy link
Author

ne-bknn commented Sep 12, 2024

Uh, actually referenced here with explanation why this isn't yet fixed: #947

I've just copy-pasted running variable from libvirt_domain schema. My reasoning is that they are semantically equivalent, so if this variable config is correct for libvirt_domain it should be correct for libvirt_network. What's the catch?

Full disclosure: only user-level experience with terraform, no experience with libvirt. My assumptions may be horribly wrong.

@dmacvicar
Copy link
Owner

Thanks for the attempt.

It is more complicated than that. It requires on acting on the status based of what you read to bring the network up if it was up last time and it is now down.

@dmacvicar dmacvicar marked this pull request as draft September 15, 2024 09:43
@ne-bknn
Copy link
Author

ne-bknn commented Sep 15, 2024

I understand that I can be and most probably is wrong, but I do not understand why. Network state is checked in Update and Update brings it up if its not up:

activeInt, err := virConn.NetworkIsActive(network)
if err != nil {
return diag.Errorf("error when getting network %s status during update: %s", network.Name, err)
}
if activeInt != 1 {
log.Printf("[DEBUG] Activating network %s", network.Name)
if err := virConn.NetworkCreate(network); err != nil {
return diag.Errorf("error when activating network %s during update: %s", network.Name, err)
}
}

We just have to signal to terraform that network state is not the expected one. My (manual and naive) tests show that it works - if the network is up, it won't be updated, if it is down, it will be. What case I fail to see?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants