2024-11-15 21:51:25 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/lib/protobuf/zoopb"
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// someone sent machine 'u' is it new?
|
|
|
|
// if not, update the record of it
|
|
|
|
func updateMachine(u *zoopb.Machine) string {
|
|
|
|
if u == nil {
|
|
|
|
return "nil"
|
|
|
|
}
|
|
|
|
m := me.machines.FindByName(u.Hostname)
|
|
|
|
if m == nil {
|
2024-11-17 23:23:02 -06:00
|
|
|
log.Info("adding new machine", u.Hostname)
|
2024-11-15 21:51:25 -06:00
|
|
|
me.machines.Append(u)
|
|
|
|
return "new"
|
|
|
|
}
|
2024-11-17 23:23:02 -06:00
|
|
|
// log.Info("updating machine", m.Hostname)
|
2024-11-15 21:51:25 -06:00
|
|
|
|
|
|
|
// did the # of cpus change?
|
|
|
|
if m.Cpus != u.Cpus {
|
|
|
|
m.Cpus = u.Cpus
|
|
|
|
log.Info("cpus changed to", m.Cpus)
|
|
|
|
}
|
|
|
|
|
|
|
|
// did the memory change?
|
|
|
|
if m.Memory != u.Memory {
|
|
|
|
m.Memory = u.Memory
|
|
|
|
log.Info("memory changed to", m.Memory)
|
|
|
|
}
|
|
|
|
|
|
|
|
// init these if nil
|
|
|
|
if m.Packages == nil {
|
|
|
|
m.Packages = new(zoopb.Packages)
|
|
|
|
}
|
|
|
|
if u.Packages == nil {
|
|
|
|
u.Packages = new(zoopb.Packages)
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePackages(m.Packages, u.Packages)
|
|
|
|
return "upgrade"
|
|
|
|
}
|
|
|
|
|
|
|
|
// looks to see if any packages:
|
|
|
|
// changed versions
|
|
|
|
// were newly installed
|
|
|
|
// were uninstalled
|
|
|
|
func updatePackages(p *zoopb.Packages, u *zoopb.Packages) bool {
|
|
|
|
var changed bool = false
|
|
|
|
|
|
|
|
return changed
|
|
|
|
}
|