save config file kinda works

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-19 05:44:16 -06:00
parent 0ad4ffd0c6
commit 4e0dc17202
3 changed files with 20 additions and 7 deletions

View File

@ -51,6 +51,9 @@ http-toogle-ZOOD:
http-list-machines:
curl --silent http://localhost:8080/list
http-ConfigSave:
curl --silent http://localhost:8080/save
http-set-zood-target:
curl --silent "http://localhost:8080/target?package=zood&version=v0.0.8"

15
http.go
View File

@ -43,7 +43,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
log.Info("error =", err)
return
}
log.Log(ZOOD, "proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname)
log.Log(INFO, "proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname)
b := me.upgrade[m.Hostname]
switch updateMachine(m) {
case "upgrade":
@ -90,7 +90,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
if zood == nil {
log.Info("machine", m.Hostname, "does not have zood installed")
} else {
log.Info("know about machine", m.Hostname, "zood version", zood.Version, "vs target version", v)
log.Info("zood version", zood.Version, "vs target version", v, "on machine", m.Hostname)
}
}
return
@ -98,7 +98,16 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
// save the config file
if route == "/save" {
// me.machines.SaveConfig()
log.HttpMode(w)
defer log.HttpMode(nil)
data, err := me.machines.Marshal()
if err != nil {
log.Info("proto.Marshal() failed len", len(msg), err)
return
}
log.Info("proto.Marshal() worked len", len(msg))
// me.machines.ConfigSave()
zoopb.ConfigSaveRaw(data)
return
}

View File

@ -39,7 +39,7 @@ func updateMachine(u *zoopb.Machine) string {
u.Packages = new(zoopb.Packages)
}
if zood := m.FindPackageByName("zood"); zood != nil {
log.Log(ZOOD, m.Hostname, "has zood version", zood.Version)
log.Log(INFO, m.Hostname, "has zood version", zood.Version)
}
updatePackages(m, u.Packages)
@ -59,14 +59,15 @@ func updatePackages(m *zoopb.Machine, newp *zoopb.Packages) bool {
if p.Name == "zood" {
if pold := m.FindPackageByName("zood"); pold == nil {
changed = true
log.Log(ZOOD, m.Hostname, "updatePackages() new package", p.Name , "version", p.Version)
log.Log(ZOOD, "updatePackages() new package", p.Name , "version", p.Version, "machine", m.Hostname)
m.Packages.Append(p)
} else {
if p.Version == pold.Version {
log.Log(ZOOD, m.Hostname, "updatePackages() unchanged", p.Version)
log.Log(ZOOD, "updatePackages() unchanged", p.Version, "machine", m.Hostname)
} else {
changed = true
log.Log(ZOOD, m.Hostname, "updatePackages() package", p.Name , "version changed", pold.Version, "to", p.Version)
log.Log(NOW, "updatePackages() package", p.Name , "version changed", pold.Version, "to", p.Version, "machine", m.Hostname)
pold.Version = p.Version
}
}
}