diff --git a/cmd/qemu/events/lifecycle.go b/cmd/qemu/events/lifecycle.go index 8148e60..45f4753 100644 --- a/cmd/qemu/events/lifecycle.go +++ b/cmd/qemu/events/lifecycle.go @@ -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: diff --git a/go.mod b/go.mod index 781b476..975da8e 100644 --- a/go.mod +++ b/go.mod @@ -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