works, it's neat, but do I really want this?
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
1effa9c745
commit
7b3e24740d
|
@ -173,38 +173,39 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
||||||
if domcfg.Memory == nil {
|
if domcfg.Memory == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
var m int64 = 0
|
||||||
|
|
||||||
// check memory
|
// check memory
|
||||||
if domcfg.Memory.Unit == "KiB" {
|
if domcfg.Memory.Unit == "KiB" {
|
||||||
var m int64
|
|
||||||
m = int64(domcfg.Memory.Value * 1024)
|
m = int64(domcfg.Memory.Value * 1024)
|
||||||
if d.pb.Memory != m {
|
if d.pb.Memory != m {
|
||||||
d.pb.Memory = m
|
d.pb.Memory = m
|
||||||
me.changed = true
|
me.changed = true
|
||||||
fmt.Printf("Memory changed %s to %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit)
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if domcfg.Memory.Unit == "MiB" {
|
if domcfg.Memory.Unit == "MiB" {
|
||||||
var m int64
|
|
||||||
m = int64(domcfg.Memory.Value * 1024 * 1024)
|
m = int64(domcfg.Memory.Value * 1024 * 1024)
|
||||||
if d.pb.Memory != m {
|
if d.pb.Memory != m {
|
||||||
d.pb.Memory = m
|
d.pb.Memory = m
|
||||||
me.changed = true
|
me.changed = true
|
||||||
fmt.Printf("Memory changed %s to %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit)
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if domcfg.Memory.Unit == "GiB" {
|
if domcfg.Memory.Unit == "GiB" {
|
||||||
var m int64
|
|
||||||
m = int64(domcfg.Memory.Value * 1024 * 1024 * 1024)
|
m = int64(domcfg.Memory.Value * 1024 * 1024 * 1024)
|
||||||
if d.pb.Memory != m {
|
if d.pb.Memory != m {
|
||||||
d.pb.Memory = m
|
d.pb.Memory = m
|
||||||
me.changed = true
|
me.changed = true
|
||||||
fmt.Printf("Memory changed %s, %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit)
|
fmt.Printf("Memory changed %s, %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit)
|
||||||
}
|
}
|
||||||
|
d.SetMemory(m)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
fmt.Println("Unknown Memory Unit", domcfg.Memory.Unit)
|
fmt.Println("Unknown Memory Unit", domcfg.Memory.Unit)
|
||||||
|
|
14
change.go
14
change.go
|
@ -44,17 +44,27 @@ func NewEvent(origval any, newval any) *pb.Event {
|
||||||
|
|
||||||
e.OrigVal = convert(origval)
|
e.OrigVal = convert(origval)
|
||||||
e.NewVal = convert(newval)
|
e.NewVal = convert(newval)
|
||||||
|
|
||||||
|
me.events.Events = append(me.events.Events, e)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the droplet memory
|
// update the droplet memory
|
||||||
func (d *DropletT) SetMemory(b int64) *pb.Event {
|
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 {
|
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
|
var e *pb.Event
|
||||||
e = NewEvent(d.pb.Memory, b)
|
e = NewEvent(d.pb.Memory, b)
|
||||||
|
e.FieldName = "Droplet.Memory"
|
||||||
|
|
||||||
|
stuff := me.events.FormatJSON()
|
||||||
|
log.Info("events:", stuff)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
main.go
6
main.go
|
@ -9,7 +9,9 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,6 +42,10 @@ func main() {
|
||||||
me.unstable = time.Now() // initialize the grid as unstable
|
me.unstable = time.Now() // initialize the grid as unstable
|
||||||
me.delay = 5 * time.Second // how often to poll the hypervisors
|
me.delay = 5 * time.Second // how often to poll the hypervisors
|
||||||
me.changed = false
|
me.changed = false
|
||||||
|
me.events = new(pb.Events)
|
||||||
|
u := uuid.New()
|
||||||
|
me.events.Uuid = u.String()
|
||||||
|
me.events.Version = "dirty v1"
|
||||||
|
|
||||||
cfgfile()
|
cfgfile()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue