common update code
This commit is contained in:
parent
64d44e2272
commit
d29e55b0d5
36
http.go
36
http.go
|
@ -41,42 +41,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
/*
|
||||
if route == "/status" {
|
||||
var packs *zoopb.Packages
|
||||
packs = new(zoopb.Packages)
|
||||
if err := packs.Unmarshal(msg); err != nil {
|
||||
log.Info("/status proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("/status Unmarshal worked with msg len", len(msg), "from", hostname)
|
||||
log.Info("/status hostname", hostname, "has", packs.Len(), "packages installed")
|
||||
fmt.Fprintln(w, "upgrade")
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
// list out the machines and thier version of zood
|
||||
/*
|
||||
if route == "/list" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
loop := me.machines.SortByHostname()
|
||||
for loop.Scan() {
|
||||
m := loop.Next()
|
||||
zood := m.Packages.FindByName("zood")
|
||||
v := me.targets["zood"] // this is the target version
|
||||
if zood == nil {
|
||||
log.Info("machine", m.Hostname, "does not have zood installed")
|
||||
} else {
|
||||
log.Info(fmt.Sprintf("zood version %s vs target version %s on machine %s", zood.Version, v, m.Hostname))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
if route == "/uptime" {
|
||||
if me.zood == nil {
|
||||
fmt.Fprintf(w, "BAD zood == nil\n")
|
||||
|
|
38
machine.go
38
machine.go
|
@ -60,6 +60,7 @@ func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data
|
|||
} else {
|
||||
fmt.Fprintln(w, m.UpgradeCmd)
|
||||
}
|
||||
m.UpgradeCmd = ""
|
||||
m.Upgrade = false
|
||||
} else {
|
||||
fmt.Fprintln(w, "good")
|
||||
|
@ -112,7 +113,9 @@ func updateMachine(u *zoopb.Machine) string {
|
|||
}
|
||||
m.Laststamp = timestamppb.New(time.Now())
|
||||
|
||||
updatePackages(m, u.Packages)
|
||||
if updatePackages(m, u.Packages) {
|
||||
// trigger save pb
|
||||
}
|
||||
return "upgrade"
|
||||
}
|
||||
|
||||
|
@ -127,20 +130,31 @@ func updatePackages(m *zoopb.Machine, newp *zoopb.Packages) bool {
|
|||
for loop.Scan() {
|
||||
p := loop.Next()
|
||||
if p.Name == "zood" {
|
||||
if pold := m.Packages.FindByName("zood"); pold == nil {
|
||||
if updatePackageVersion(m, p) {
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if p.Name == "virtigod" {
|
||||
if updatePackageVersion(m, p) {
|
||||
changed = true
|
||||
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, "updatePackages() unchanged", p.Version, "machine", m.Hostname)
|
||||
} else {
|
||||
changed = true
|
||||
log.Log(NOW, "updatePackages() package", p.Name, "version changed", pold.Version, "to", p.Version, "machine", m.Hostname)
|
||||
pold.Version = p.Version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
func updatePackageVersion(m *zoopb.Machine, pnew *zoopb.Package) bool {
|
||||
pold := m.Packages.FindByName(pnew.Name)
|
||||
if pold == nil {
|
||||
log.Log(NOW, "updatePackages() new package", pnew.Name, "version", pnew.Version, "machine", m.Hostname)
|
||||
m.Packages.Append(pnew)
|
||||
return true
|
||||
}
|
||||
if pold.Version == pnew.Version {
|
||||
log.Log(ZOOD, "updatePackages() unchanged", pold.Version, "machine", m.Hostname)
|
||||
return false
|
||||
}
|
||||
log.Log(NOW, "updatePackages() package", pnew.Name, "version changed", pold.Version, "to", pnew.Version, "machine", m.Hostname)
|
||||
pold.Version = pnew.Version
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue