ready to package
This commit is contained in:
parent
7dd5d6d2b1
commit
c65d006423
2
apt.go
2
apt.go
|
@ -38,7 +38,7 @@ func addNew(name string, version string) bool {
|
||||||
return me.packages.Append(new1)
|
return me.packages.Append(new1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updatePackages() {
|
func updatePackagesOld() {
|
||||||
// Get the list of installed packages for the detected distro
|
// Get the list of installed packages for the detected distro
|
||||||
newP, err := getPackageList(me.distro)
|
newP, err := getPackageList(me.distro)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
23
http.go
23
http.go
|
@ -36,16 +36,16 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var m *zoopb.Machine
|
var m *zoopb.Machine
|
||||||
m = new(zoopb.Machine)
|
m = new(zoopb.Machine)
|
||||||
if err := m.Unmarshal(msg); err != nil {
|
if err := m.Unmarshal(msg); err != nil {
|
||||||
log.Info("proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
|
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
|
||||||
|
log.Info("error =", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.Packages == nil {
|
log.Info("proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname)
|
||||||
log.Info("Unmarshal worked with msg len", len(msg), "from", m.Hostname)
|
switch updateMachine(m) {
|
||||||
log.Info(m.Hostname, "sent machine")
|
case "upgrade":
|
||||||
} else {
|
fmt.Fprintln(w, "upgrade")
|
||||||
|
default:
|
||||||
log.Info("Unmarshal worked with msg len", len(msg), "from", m.Hostname)
|
fmt.Fprintln(w, "notsure")
|
||||||
log.Info(m.Hostname, "has", m.Packages.Len(), "packages installed")
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -66,13 +66,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Info("Unmarshal worked with msg len", len(msg), "from", hostname)
|
log.Info("Unmarshal worked with msg len", len(msg), "from", hostname)
|
||||||
log.Info(hostname, "has", packs.Len(), "packages installed")
|
log.Info(hostname, "has", packs.Len(), "packages installed")
|
||||||
fmt.Fprintln(w, "upgrade")
|
fmt.Fprintln(w, "upgrade")
|
||||||
|
|
||||||
m := me.machines.FindByName(hostname)
|
|
||||||
if m == nil {
|
|
||||||
log.Info("did not find", hostname)
|
|
||||||
} else {
|
|
||||||
log.Info("found", hostname)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
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 {
|
||||||
|
log.Info("did not find", u.Hostname)
|
||||||
|
me.machines.Append(u)
|
||||||
|
return "new"
|
||||||
|
}
|
||||||
|
log.Info("updating machine", m.Hostname)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
Loading…
Reference in New Issue