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

integrate support for libvirt events #177

Closed
lukas016 opened this issue Feb 13, 2024 · 0 comments · Fixed by #190
Closed

integrate support for libvirt events #177

lukas016 opened this issue Feb 13, 2024 · 0 comments · Fixed by #190
Assignees
Labels
enhancement New feature or request prio-low

Comments

@lukas016
Copy link
Contributor

lukas016 commented Feb 13, 2024

Summary

Libvirt service supports register event handler, so we can listen to events from libvirt directly in libvirt-provider and we don't need active pulling of information from libvirt.

          I would suggest to subscribe to the `LifeCycleEvents` of the libvirt Domain and enqueue Machines if something changes in the domain.

Here is some sample code how this might look like:

// Subscribe to lifecycle events using the provided context
eventChan, err := l.LifecycleEvents(ctx)
if err != nil {
	fmt.Println("Failed to subscribe to lifecycle events:", err)
	return
}

fmt.Println("Subscribed to lifecycle events. Listening for events...")

// Listen for lifecycle events in a separate goroutine
go func() {
	for event := range eventChan {
		fmt.Printf("Received lifecycle event: %+v\n", event)
                // enqueue Machines here and switch over the events
	}
	fmt.Println("Lifecycle event channel closed.")
}()

// Wait for context to be cancelled (e.g., by receiving a signal)
<-ctx.Done()
fmt.Println("Context cancelled. Shutting down...")

This can be also used to consolidate other go routines which we are starting during the initialization of the provider.

Originally posted by @afritzler in #144 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request prio-low
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant