From 7b3e24740dd3f9df58a29a42a63de54715e9cba3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 25 Oct 2024 03:11:55 -0500 Subject: [PATCH] works, it's neat, but do I really want this? Signed-off-by: Jeff Carr --- addDroplet.go | 7 ++++--- change.go | 14 ++++++++++++-- main.go | 6 ++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/addDroplet.go b/addDroplet.go index dd625fb..1bff71e 100644 --- a/addDroplet.go +++ b/addDroplet.go @@ -173,38 +173,39 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool { if domcfg.Memory == nil { return true } + var m int64 = 0 // check memory if domcfg.Memory.Unit == "KiB" { - var m int64 m = int64(domcfg.Memory.Value * 1024) if d.pb.Memory != m { d.pb.Memory = m me.changed = true fmt.Printf("Memory changed %s to %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit) } + d.SetMemory(m) return true } if domcfg.Memory.Unit == "MiB" { - var m int64 m = int64(domcfg.Memory.Value * 1024 * 1024) if d.pb.Memory != m { d.pb.Memory = m me.changed = true fmt.Printf("Memory changed %s to %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit) } + d.SetMemory(m) return true } if domcfg.Memory.Unit == "GiB" { - var m int64 m = int64(domcfg.Memory.Value * 1024 * 1024 * 1024) if d.pb.Memory != m { d.pb.Memory = m me.changed = true fmt.Printf("Memory changed %s, %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit) } + d.SetMemory(m) return true } fmt.Println("Unknown Memory Unit", domcfg.Memory.Unit) diff --git a/change.go b/change.go index f4e7d79..95f38d7 100644 --- a/change.go +++ b/change.go @@ -44,17 +44,27 @@ func NewEvent(origval any, newval any) *pb.Event { e.OrigVal = convert(origval) e.NewVal = convert(newval) + + me.events.Events = append(me.events.Events, e) return e } // update the droplet memory func (d *DropletT) SetMemory(b int64) *pb.Event { - log.Info("Set the amount of memory for the droplet", b) + oldm := pb.HumanFormatBytes(d.pb.Memory) + newm := pb.HumanFormatBytes(b) if d.pb.Memory == b { - return nil + log.Info("droplet", d.pb.Hostname, "memory unchanged", oldm, "to", newm) + // return nil } + log.Info("droplet", d.pb.Hostname, "memory change from", oldm, "to", newm) + var e *pb.Event e = NewEvent(d.pb.Memory, b) + e.FieldName = "Droplet.Memory" + + stuff := me.events.FormatJSON() + log.Info("events:", stuff) return e } diff --git a/main.go b/main.go index cb398d2..ade0ccc 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,9 @@ import ( "path/filepath" "time" + "github.com/google/uuid" "go.wit.com/dev/alexflint/arg" + pb "go.wit.com/lib/protobuf/virtbuf" "go.wit.com/log" ) @@ -40,6 +42,10 @@ func main() { me.unstable = time.Now() // initialize the grid as unstable me.delay = 5 * time.Second // how often to poll the hypervisors me.changed = false + me.events = new(pb.Events) + u := uuid.New() + me.events.Uuid = u.String() + me.events.Version = "dirty v1" cfgfile()