From 4e0dc17202883e630a3a57b2a1a4bffff3b268f2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 19 Nov 2024 05:44:16 -0600 Subject: [PATCH] save config file kinda works Signed-off-by: Jeff Carr --- Makefile | 3 +++ http.go | 15 ++++++++++++--- machine.go | 9 +++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index e335433..bf61c6e 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/http.go b/http.go index 444cd3d..3ce0c06 100644 --- a/http.go +++ b/http.go @@ -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 } diff --git a/machine.go b/machine.go index d524a58..ed8a019 100644 --- a/machine.go +++ b/machine.go @@ -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 } } }