Ajout de l'annulation de l'opération etcd

This commit is contained in:
Mickael BOURNEUF 2025-02-12 21:31:01 +01:00
parent 26b1a3eed2
commit 3f66afc286
2 changed files with 16 additions and 4 deletions

View File

@ -30,12 +30,12 @@ func Lifecyle(c *libvirt.Connect, d *libvirt.Domain, e *libvirt.DomainEventLifec
}
defer etcd.Close()
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
switch e.Event {
case libvirt.DOMAIN_EVENT_DEFINED:
event = "defined"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
etcd.Put(ctx, "/cluster/"+config.ClusterID+"/host/"+config.NodeID+"/qemu/"+domainID, "")
cancel()
switch libvirt.DomainEventDefinedDetailType(e.Detail) {
case libvirt.DOMAIN_EVENT_DEFINED_ADDED:
@ -52,7 +52,9 @@ func Lifecyle(c *libvirt.Connect, d *libvirt.Domain, e *libvirt.DomainEventLifec
case libvirt.DOMAIN_EVENT_UNDEFINED:
event = "undefined"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
etcd.Delete(ctx, "/cluster/"+config.ClusterID+"/host/"+config.NodeID+"/qemu/"+domainID)
cancel()
switch libvirt.DomainEventUndefinedDetailType(e.Detail) {
case libvirt.DOMAIN_EVENT_UNDEFINED_REMOVED:
@ -65,7 +67,9 @@ func Lifecyle(c *libvirt.Connect, d *libvirt.Domain, e *libvirt.DomainEventLifec
case libvirt.DOMAIN_EVENT_STARTED:
event = "started"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
etcd.Put(ctx, "/cluster/"+config.ClusterID+"/domain/"+domainID+"/state", "2")
cancel()
switch libvirt.DomainEventStartedDetailType(e.Detail) {
case libvirt.DOMAIN_EVENT_STARTED_BOOTED:
@ -84,7 +88,9 @@ func Lifecyle(c *libvirt.Connect, d *libvirt.Domain, e *libvirt.DomainEventLifec
case libvirt.DOMAIN_EVENT_SUSPENDED:
event = "suspended"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
etcd.Put(ctx, "/cluster/"+config.ClusterID+"/domain/"+domainID+"/state", "3")
cancel()
switch libvirt.DomainEventSuspendedDetailType(e.Detail) {
case libvirt.DOMAIN_EVENT_SUSPENDED_PAUSED:
@ -111,7 +117,9 @@ func Lifecyle(c *libvirt.Connect, d *libvirt.Domain, e *libvirt.DomainEventLifec
case libvirt.DOMAIN_EVENT_RESUMED:
event = "resumed"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
etcd.Put(ctx, "/cluster/"+config.ClusterID+"/domain/"+domainID+"/state", "4")
cancel()
switch libvirt.DomainEventResumedDetailType(e.Detail) {
case libvirt.DOMAIN_EVENT_RESUMED_UNPAUSED:
@ -130,7 +138,9 @@ func Lifecyle(c *libvirt.Connect, d *libvirt.Domain, e *libvirt.DomainEventLifec
case libvirt.DOMAIN_EVENT_STOPPED:
event = "stopped"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
etcd.Put(ctx, "/cluster/"+config.ClusterID+"/domain/"+domainID+"/state", "5")
cancel()
switch libvirt.DomainEventStoppedDetailType(e.Detail) {
case libvirt.DOMAIN_EVENT_STOPPED_SHUTDOWN:
@ -153,7 +163,9 @@ func Lifecyle(c *libvirt.Connect, d *libvirt.Domain, e *libvirt.DomainEventLifec
case libvirt.DOMAIN_EVENT_SHUTDOWN:
event = "shutdown"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
etcd.Put(ctx, "/cluster/"+config.ClusterID+"/domain/"+domainID+"/state", "6")
cancel()
switch libvirt.DomainEventShutdownDetailType(e.Detail) {
case libvirt.DOMAIN_EVENT_SHUTDOWN_FINISHED:

4
go.mod
View File

@ -5,7 +5,7 @@ go 1.22.9
require (
github.com/denisbrodbeck/machineid v1.0.1
github.com/prometheus/client_golang v1.20.5
go.etcd.io/etcd/api/v3 v3.5.18
github.com/rabbitmq/amqp091-go v1.10.0
go.etcd.io/etcd/client/v3 v3.5.18
gopkg.in/ini.v1 v1.67.0
libvirt.org/go/libvirt v1.11001.0
@ -23,7 +23,7 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rabbitmq/amqp091-go v1.10.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.18 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.18 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect