Compare commits
No commits in common. "master" and "v0.0.45" have entirely different histories.
22
Makefile
22
Makefile
|
@ -7,7 +7,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
|||
# REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi)
|
||||
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
|
||||
|
||||
all: goimports gocui-debugging
|
||||
all: goimports gocui
|
||||
# ./zookeeper
|
||||
|
||||
vet:
|
||||
|
@ -18,10 +18,7 @@ nogui:
|
|||
./zookeeper --gui nocui
|
||||
|
||||
gocui: build
|
||||
./zookeeper --gui gocui
|
||||
|
||||
gocui-debugging: build
|
||||
./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so >/tmp/forge.log 2>&1
|
||||
./zookeeper --gui gocui >/tmp/forge.log 2>&1
|
||||
|
||||
build: goimports vet
|
||||
GO111MODULE=off go build -v -x \
|
||||
|
@ -51,7 +48,7 @@ redomod:
|
|||
clean:
|
||||
rm -f go.*
|
||||
rm -f zookeeper
|
||||
go-mod-clean purge
|
||||
go-mod-clean --purge
|
||||
|
||||
# git clone the sources and all the golang dependancies into ~/go/src
|
||||
# if you don't have go-clone, you can get it from http://go.wit.com/
|
||||
|
@ -64,5 +61,14 @@ http-toogle-ZOOD:
|
|||
http-list-machines:
|
||||
curl --silent http://localhost:8080/list
|
||||
|
||||
http-uptime:
|
||||
curl --silent http://localhost:8080/uptime
|
||||
http-ConfigSave:
|
||||
curl --silent http://localhost:8080/save
|
||||
|
||||
http-set-zood-target:
|
||||
curl --silent "http://localhost:8080/target?package=zood&version=v0.0.8"
|
||||
|
||||
http-upgrade-hpdev2.grid.wit.com:
|
||||
curl --silent "http://localhost:8080/upgrade?hostname=hpdev2.grid.wit.com"
|
||||
|
||||
http-upgrade-mirrors.wit.com:
|
||||
curl --silent "http://localhost:8080/upgrade?hostname=mirrors.wit.com"
|
||||
|
|
30
doGui.go
30
doGui.go
|
@ -11,28 +11,17 @@ import (
|
|||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// refresh the windows & tables the user has open
|
||||
func refresh() {
|
||||
time.Sleep(90 * time.Second)
|
||||
if argv.Verbose {
|
||||
log.Info("zookeeper scan here")
|
||||
}
|
||||
if me.zood != nil {
|
||||
// me.zood.doMachinesUpgradeTable(me.machines)
|
||||
all := me.machines.All()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
if me.hostname == m.Hostname {
|
||||
// this is me! This is the version of zood that should be installed everywhere
|
||||
v := m.FindVersion("zood")
|
||||
me.zood.version = v
|
||||
me.zood.versionL.SetText(v)
|
||||
}
|
||||
}
|
||||
me.zood.refresh()
|
||||
doMachinesUpgradeTable()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +51,7 @@ func doGui() {
|
|||
me.zood.Toggle()
|
||||
return
|
||||
}
|
||||
me.zood = makeZoodWin()
|
||||
makeZoodWin()
|
||||
})
|
||||
|
||||
grid.NewButton("Cluster Events", func() {
|
||||
|
@ -72,18 +61,5 @@ func doGui() {
|
|||
// sit here forever refreshing the GUI
|
||||
for {
|
||||
refresh()
|
||||
time.Sleep(90 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func saveMachineState() {
|
||||
cur := zoopb.NewMachines()
|
||||
|
||||
all := me.machines.SortByHostname()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
log.Info("have machine:", m.Hostname)
|
||||
cur.Append(m)
|
||||
}
|
||||
cur.ConfigSave()
|
||||
}
|
||||
|
|
22
exit.go
22
exit.go
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func okExit(thing string) {
|
||||
if thing != "" {
|
||||
log.Info("zookeeper exit:", thing, "ok")
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func badExit(err error) {
|
||||
log.Info("zookeeper failed: ", err)
|
||||
os.Exit(-1)
|
||||
}
|
99
http.go
99
http.go
|
@ -8,8 +8,8 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
|
@ -24,7 +24,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
route := cleanURL(r.URL.Path)
|
||||
|
||||
hostname := r.URL.Query().Get("hostname")
|
||||
// flag := r.URL.Query().Get("flag")
|
||||
flag := r.URL.Query().Get("flag")
|
||||
packname := r.URL.Query().Get("package")
|
||||
version := r.URL.Query().Get("version")
|
||||
|
||||
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
||||
if err != nil {
|
||||
|
@ -41,28 +43,84 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if route == "/uptime" {
|
||||
if me.zood == nil {
|
||||
fmt.Fprintf(w, "BAD zood == nil\n")
|
||||
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
|
||||
}
|
||||
var count int
|
||||
var bad int
|
||||
for m := range me.machines.IterAll() {
|
||||
count += 1
|
||||
if m.FindVersion("zood") != me.zood.version {
|
||||
if m.SinceLastUpdate() > 10*time.Minute {
|
||||
// skip machines that have not been updated in the last 10 minutes
|
||||
log.Info("ignoring old machine", m.Hostname)
|
||||
continue
|
||||
|
||||
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
|
||||
}
|
||||
bad += 1
|
||||
}
|
||||
}
|
||||
if bad == 0 {
|
||||
fmt.Fprintf(w, "GOOD machine count=(%d) all machines are version %s\n", count, me.zood.version)
|
||||
|
||||
// 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 {
|
||||
fmt.Fprintf(w, "BAD machine count=(%d) upgrade=(%d) to %s\n", count, bad, me.zood.version)
|
||||
log.Info(fmt.Sprintf("zood version %s vs target version %s on machine %s", zood.Version, v, m.Hostname))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// save the config file
|
||||
if route == "/save" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
if err := me.machines2.ConfigSave(); err == nil {
|
||||
log.Log(NOW, "ConfigSave() ok")
|
||||
} else {
|
||||
log.Log(NOW, "ConfigSave() failed", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// flag a package to attempt to upgrade
|
||||
if route == "/upgrade" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
me.upgrade[hostname] = true
|
||||
log.Log(NOW, "setting package ", packname, " to upgrade")
|
||||
return
|
||||
}
|
||||
|
||||
// set the target version for a package
|
||||
if route == "/target" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
// me.targets[packname] = version
|
||||
log.Log(NOW, "setting package/version to ", packname, " ", version)
|
||||
return
|
||||
}
|
||||
|
||||
// toggle logging flags
|
||||
if route == "/flag" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
log.Info("going to toggle flag:", flag)
|
||||
switch flag {
|
||||
case "ZOOD":
|
||||
if ZOOD.Enabled() {
|
||||
log.Log(NOW, "toogle ZOOD false")
|
||||
ZOOD.SetBool(false)
|
||||
} else {
|
||||
log.Log(NOW, "toogle ZOOD true")
|
||||
ZOOD.SetBool(true)
|
||||
}
|
||||
default:
|
||||
log.Info("unknown looging flag:", flag)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -80,6 +138,5 @@ func startHTTP() {
|
|||
err := http.ListenAndServe(p, nil)
|
||||
if err != nil {
|
||||
log.Println("Error starting server:", err)
|
||||
badExit(err)
|
||||
}
|
||||
}
|
||||
|
|
54
machine.go
54
machine.go
|
@ -43,6 +43,7 @@ func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data
|
|||
am := new(zoopb.Machine)
|
||||
am.Hostname = newm.Hostname
|
||||
am.Memory = newm.Memory
|
||||
me.machines2.Append(am)
|
||||
me.machines.Append(newm)
|
||||
log.Info("new machine", am.Hostname, am.Memory)
|
||||
return
|
||||
|
@ -55,15 +56,10 @@ func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data
|
|||
}
|
||||
if m.Upgrade {
|
||||
log.Info(m.Hostname, "was told to upgrade zood")
|
||||
if m.UpgradeCmd == "" {
|
||||
fmt.Fprintln(w, "apt update")
|
||||
} else {
|
||||
fmt.Fprintln(w, m.UpgradeCmd)
|
||||
}
|
||||
m.UpgradeCmd = ""
|
||||
m.Upgrade = false
|
||||
} else {
|
||||
fmt.Fprintln(w, "good")
|
||||
fmt.Fprintln(w, "upgrade")
|
||||
}
|
||||
// log.Info("update machine protobuf", hostname)
|
||||
updateMachine(newm)
|
||||
|
@ -79,12 +75,8 @@ func updateMachine(u *zoopb.Machine) string {
|
|||
if m == nil {
|
||||
log.Info("adding new machine", u.Hostname)
|
||||
me.machines.Append(u)
|
||||
if me.zood == nil {
|
||||
// do nothing. window has not been opened
|
||||
} else {
|
||||
me.zood.doMachinesUpgradeTable(me.machines)
|
||||
}
|
||||
saveMachineState()
|
||||
log.Info("save machines pb file here...")
|
||||
me.machines2.ConfigSave()
|
||||
return "new"
|
||||
}
|
||||
// log.Info("updating machine", m.Hostname)
|
||||
|
@ -113,9 +105,7 @@ func updateMachine(u *zoopb.Machine) string {
|
|||
}
|
||||
m.Laststamp = timestamppb.New(time.Now())
|
||||
|
||||
if updatePackages(m, u.Packages) {
|
||||
// trigger save pb
|
||||
}
|
||||
updatePackages(m, u.Packages)
|
||||
return "upgrade"
|
||||
}
|
||||
|
||||
|
@ -130,36 +120,20 @@ func updatePackages(m *zoopb.Machine, newp *zoopb.Packages) bool {
|
|||
for loop.Scan() {
|
||||
p := loop.Next()
|
||||
if p.Name == "zood" {
|
||||
if updatePackageVersion(m, p) {
|
||||
if pold := m.Packages.FindByName("zood"); pold == nil {
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if p.Name == "virtigod" {
|
||||
if updatePackageVersion(m, p) {
|
||||
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
|
||||
}
|
||||
}
|
||||
if p.Name == "forge" {
|
||||
if updatePackageVersion(m, p) {
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
10
main.go
10
main.go
|
@ -37,13 +37,19 @@ func main() {
|
|||
|
||||
me = new(zookeep)
|
||||
me.hostname, _ = os.Hostname()
|
||||
me.pollDelay = time.Hour
|
||||
me.pollDelay = 10 * time.Second
|
||||
me.machines = zoopb.NewMachines()
|
||||
me.machines2 = zoopb.NewMachines()
|
||||
if err := me.machines.ConfigLoad(); err != nil {
|
||||
log.Warn("load config failed", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
// me.upgrade = make(map[string]bool) // used to trigger upgrade attempts
|
||||
if err := me.machines2.ConfigLoad(); err != nil {
|
||||
log.Warn("load config failed", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
// me.targets = make(map[string]string) // keep track of what versions the machines should be running
|
||||
me.upgrade = make(map[string]bool) // used to trigger upgrade attempts
|
||||
|
||||
go NewWatchdog()
|
||||
|
||||
|
|
20
structs.go
20
structs.go
|
@ -4,6 +4,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.wit.com/gui"
|
||||
|
@ -22,6 +23,7 @@ type zookeep struct {
|
|||
distro string // debian,redhat,gentoo,macos,wincrap
|
||||
packages *zoopb.Packages // installed packages and versions
|
||||
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
|
||||
machines2 *zoopb.Machines // every machine that has reported itself to the zookeeper
|
||||
targets map[string]string // what versions the machines should be running
|
||||
upgrade map[string]bool // use this to trigger builds
|
||||
myGui *gui.Node // the gui toolkit handle
|
||||
|
@ -30,3 +32,21 @@ type zookeep struct {
|
|||
machinesTB *zoopb.MachinesTable // the machines gui table buffer
|
||||
zood *stdTableWin // the zood version window
|
||||
}
|
||||
|
||||
type stdTableWin struct {
|
||||
sync.Mutex
|
||||
win *gadgets.GenericWindow // the machines gui window
|
||||
box *gui.Node // the machines gui parent box widget
|
||||
TB *zoopb.MachinesTable // the machines gui table buffer
|
||||
update bool // if the window should be updated
|
||||
}
|
||||
|
||||
func (w *stdTableWin) Toggle() {
|
||||
if w == nil {
|
||||
return
|
||||
}
|
||||
if w.win == nil {
|
||||
return
|
||||
}
|
||||
w.win.Toggle()
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func NewWatchdog() {
|
|||
// log.Info("know about machine", m.Hostname, "zood version", zood.Version)
|
||||
}
|
||||
}
|
||||
log.Info("hour watchdog:", counter, "machines. Current time:", t)
|
||||
log.Info("zookeeper has", counter, "machines. Current time:", t)
|
||||
|
||||
// h.pollHypervisor()
|
||||
// h.Scan()
|
||||
|
|
211
windowZood.go
211
windowZood.go
|
@ -5,7 +5,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.wit.com/gui"
|
||||
|
@ -14,137 +13,42 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
type stdTableWin struct {
|
||||
sync.Mutex
|
||||
win *gadgets.GenericWindow // the machines gui window
|
||||
box *gui.Node // the machines gui parent box widget
|
||||
TB *zoopb.MachinesTable // the machines gui table buffer
|
||||
version string // the current zood version
|
||||
versionL *gui.Node // label widget to display the current zood version
|
||||
outOfDate *gui.Node // checkbox to only show out of date droplets
|
||||
showAll *gui.Node // show everything in the zoo
|
||||
update bool // if the window should be updated
|
||||
}
|
||||
|
||||
func (w *stdTableWin) Toggle() {
|
||||
if w == nil {
|
||||
return
|
||||
}
|
||||
if w.win == nil {
|
||||
return
|
||||
}
|
||||
w.win.Toggle()
|
||||
}
|
||||
|
||||
func makeZoodWin() *stdTableWin {
|
||||
stdw := new(stdTableWin)
|
||||
stdw.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here")
|
||||
stdw.win.Custom = func() {
|
||||
func makeZoodWin() {
|
||||
me.zood = new(stdTableWin)
|
||||
me.zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here")
|
||||
me.zood.win.Custom = func() {
|
||||
log.Info("test delete window here")
|
||||
}
|
||||
|
||||
grid := stdw.win.Group.RawGrid()
|
||||
grid := me.zood.win.Group.RawGrid()
|
||||
grid.NewButton("save machines.pb", func() {
|
||||
saveMachineState()
|
||||
})
|
||||
|
||||
grid.NewButton("show active", func() {
|
||||
stdw.doMachinesUpgradeTable(me.machines)
|
||||
})
|
||||
|
||||
grid.NewButton("refresh", func() {
|
||||
stdw.refresh()
|
||||
})
|
||||
|
||||
stdw.versionL = grid.NewLabel("scan")
|
||||
stdw.outOfDate = grid.NewCheckbox("out of date")
|
||||
stdw.showAll = grid.NewCheckbox("all")
|
||||
grid.NewButton("show out of date", func() {
|
||||
found := zoopb.NewMachines()
|
||||
all := me.machines.All()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
if m.FindVersion("zood") != me.zood.version {
|
||||
found.Append(m)
|
||||
}
|
||||
}
|
||||
stdw.doMachinesUpgradeTable(found)
|
||||
grid.NewCheckbox("hide active")
|
||||
grid.NewButton("update", func() {
|
||||
doMachinesUpgradeTable()
|
||||
})
|
||||
|
||||
// make a box at the bottom of the window for the protobuf table
|
||||
stdw.box = stdw.win.Bottom.Box().SetProgName("TBOX")
|
||||
stdw.doMachinesUpgradeTable(me.machines)
|
||||
|
||||
return stdw
|
||||
me.zood.box = me.zood.win.Bottom.Box().SetProgName("TBOX")
|
||||
doMachinesUpgradeTable()
|
||||
}
|
||||
|
||||
func (stdw *stdTableWin) refresh() {
|
||||
if stdw.outOfDate.Checked() {
|
||||
log.Info("refresh() showing out of date zoo")
|
||||
found := zoopb.NewMachines()
|
||||
all := me.machines.All()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
if !stdw.showAll.Checked() {
|
||||
// skip non-active zoo members
|
||||
mtime := m.Laststamp.AsTime()
|
||||
if time.Since(mtime) > 10*time.Hour {
|
||||
continue
|
||||
func doMachinesUpgradeTable() {
|
||||
me.zood.Lock()
|
||||
defer me.zood.Unlock()
|
||||
if me.zood.TB != nil {
|
||||
me.zood.TB.Delete()
|
||||
me.zood.TB = nil
|
||||
}
|
||||
}
|
||||
if m.FindVersion("zood") != me.zood.version {
|
||||
found.Append(m)
|
||||
}
|
||||
}
|
||||
stdw.doMachinesUpgradeTable(found)
|
||||
return
|
||||
}
|
||||
if stdw.showAll.Checked() {
|
||||
log.Info("refresh() showing everything in zoo")
|
||||
stdw.doMachinesUpgradeTable(me.machines)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("refresh() only show active zoo")
|
||||
found := zoopb.NewMachines()
|
||||
all := me.machines.All()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
mtime := m.Laststamp.AsTime()
|
||||
// now := time.Now()
|
||||
if time.Since(mtime) > 10*time.Hour {
|
||||
continue
|
||||
}
|
||||
found.Append(m)
|
||||
}
|
||||
stdw.doMachinesUpgradeTable(found)
|
||||
}
|
||||
|
||||
func (zood *stdTableWin) doMachinesUpgradeTable(pb *zoopb.Machines) {
|
||||
zood.Lock()
|
||||
defer zood.Unlock()
|
||||
if zood.TB != nil {
|
||||
zood.TB.Delete()
|
||||
zood.TB = nil
|
||||
}
|
||||
|
||||
/*
|
||||
found := zoopb.NewMachines()
|
||||
all := pb.SortByHostname()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
found.Append(m)
|
||||
}
|
||||
*/
|
||||
|
||||
// display the protobuf
|
||||
zood.TB = AddMachinesPB(zood.box, pb)
|
||||
me.zood.TB = AddMachinesPB(me.zood.box, me.machines)
|
||||
f := func(m *zoopb.Machine) {
|
||||
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
|
||||
m.Upgrade = true
|
||||
}
|
||||
zood.TB.Custom(f)
|
||||
log.Info("table has uuid", zood.TB.GetUuid())
|
||||
me.zood.TB.Custom(f)
|
||||
log.Info("table has uuid", me.zood.TB.GetUuid())
|
||||
}
|
||||
|
||||
func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
|
||||
|
@ -152,69 +56,22 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
|
|||
t.NewUuid()
|
||||
t.SetParent(tbox)
|
||||
|
||||
upbut := t.AddButtonFunc("upgrade", func(m *zoopb.Machine) string {
|
||||
if me.zood != nil {
|
||||
mver := m.FindVersion("zood")
|
||||
if mver == me.zood.version {
|
||||
return ""
|
||||
} else {
|
||||
// log.Info("machine mismatch", m.Hostname, mver, me.zood.version)
|
||||
}
|
||||
}
|
||||
// log.Info("machine =", m.Hostname)
|
||||
f := func(m *zoopb.Machine) string {
|
||||
log.Info("machine =", m.Hostname)
|
||||
return "now"
|
||||
})
|
||||
upbut.Custom = func(m *zoopb.Machine) {
|
||||
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
|
||||
m.Upgrade = true
|
||||
}
|
||||
t.AddButtonFunc("upgrade", f)
|
||||
|
||||
t.AddHostname()
|
||||
t.AddMemory()
|
||||
t.AddCpus()
|
||||
t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
|
||||
if m.Memory/(1024*1024) > 10000 {
|
||||
return fmt.Sprintf("%4d G", m.Memory/(1024*1024*1024))
|
||||
}
|
||||
return fmt.Sprintf("%4d M", m.Memory/(1024*1024))
|
||||
return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
|
||||
})
|
||||
|
||||
t.AddStringFunc("zood", func(m *zoopb.Machine) string {
|
||||
return m.FindVersion("zood")
|
||||
return findVersion(m, "zood")
|
||||
})
|
||||
virtbut := t.AddButtonFunc("virtigod", func(m *zoopb.Machine) string {
|
||||
ver := m.FindVersion("virtigod")
|
||||
if ver == "n/a" {
|
||||
return ""
|
||||
}
|
||||
return ver
|
||||
})
|
||||
virtbut.Custom = func(m *zoopb.Machine) {
|
||||
log.Info("Triggering machine", m.Hostname, "to upgrade virtigod")
|
||||
m.Upgrade = true
|
||||
m.UpgradeCmd = "apt install virtigod"
|
||||
}
|
||||
|
||||
forgebut := t.AddButtonFunc("forge", func(m *zoopb.Machine) string {
|
||||
ver := m.FindVersion("forge")
|
||||
if ver == "n/a" {
|
||||
return ""
|
||||
}
|
||||
return ver
|
||||
})
|
||||
forgebut.Custom = func(m *zoopb.Machine) {
|
||||
log.Info("Triggering machine", m.Hostname, "to upgrade forge")
|
||||
m.Upgrade = true
|
||||
m.UpgradeCmd = "apt install forge"
|
||||
}
|
||||
|
||||
delf := func(m *zoopb.Machine) string {
|
||||
return "delete"
|
||||
}
|
||||
delbut := t.AddButtonFunc("delete", delf)
|
||||
delbut.Custom = func(m *zoopb.Machine) {
|
||||
log.Info("Need to delete the protobuf record here", m.Hostname)
|
||||
}
|
||||
|
||||
/*
|
||||
// show if the machine needs to be upgraded
|
||||
|
@ -233,3 +90,23 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
|
|||
t.ShowTable()
|
||||
return t
|
||||
}
|
||||
|
||||
func findVersion(m *zoopb.Machine, pkgname string) string {
|
||||
zood := m.Packages.FindByName(pkgname)
|
||||
if zood == nil {
|
||||
return "n/a"
|
||||
}
|
||||
return zood.Version
|
||||
}
|
||||
|
||||
func saveMachineState() {
|
||||
cur := zoopb.NewMachines()
|
||||
|
||||
all := me.machines.SortByHostname()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
log.Info("have machine:", m.Hostname)
|
||||
cur.Append(m)
|
||||
}
|
||||
cur.ConfigSave()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue