summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile12
-rw-r--r--http.go52
-rw-r--r--main.go2
-rw-r--r--structs.go16
4 files changed, 74 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 190098d..e335433 100644
--- a/Makefile
+++ b/Makefile
@@ -47,3 +47,15 @@ git-clone:
http-toogle-ZOOD:
curl --silent http://localhost:8080/flag?flag=ZOOD
+
+http-list-machines:
+ curl --silent http://localhost:8080/list
+
+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"
diff --git a/http.go b/http.go
index 0460896..444cd3d 100644
--- a/http.go
+++ b/http.go
@@ -22,6 +22,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
hostname := r.URL.Query().Get("hostname")
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 {
@@ -42,9 +44,15 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
log.Log(ZOOD, "proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname)
+ b := me.upgrade[m.Hostname]
switch updateMachine(m) {
case "upgrade":
- fmt.Fprintln(w, "upgrade")
+ if b {
+ fmt.Fprintln(w, "apt update")
+ me.upgrade[m.Hostname] = false
+ } else {
+ fmt.Fprintln(w, "upgrade")
+ }
default:
fmt.Fprintln(w, "notsure")
}
@@ -70,6 +78,48 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ // list out the machines and thier version of zood
+ if route == "/list" {
+ log.HttpMode(w)
+ defer log.HttpMode(nil)
+ loop := me.machines.SortByName()
+ for loop.Scan() {
+ m := loop.Machine()
+ zood := m.FindPackageByName("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("know about machine", m.Hostname, "zood version", zood.Version, "vs target version", v)
+ }
+ }
+ return
+ }
+
+ // save the config file
+ if route == "/save" {
+ // me.machines.SaveConfig()
+ 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)
diff --git a/main.go b/main.go
index 1eb6adc..b47b6eb 100644
--- a/main.go
+++ b/main.go
@@ -48,6 +48,8 @@ func main() {
me.hostname, _ = os.Hostname()
me.pollDelay = 10 * time.Second
me.machines = new(zoopb.Machines)
+ 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()
diff --git a/structs.go b/structs.go
index 20ed0f5..65d5173 100644
--- a/structs.go
+++ b/structs.go
@@ -10,11 +10,13 @@ var me *stuff
// this app's variables
type stuff struct {
- hostname string // my fqdn dns zookeeper hostname
- pollDelay time.Duration // how often to report our status
- dog *time.Ticker // the watchdog timer
- dogchan chan bool // can kill the watchdog
- 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
+ hostname string // my fqdn dns zookeeper hostname
+ pollDelay time.Duration // how often to report our status
+ dog *time.Ticker // the watchdog timer
+ dogchan chan bool // can kill the watchdog
+ 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
+ targets map[string]string // what versions the machines should be running
+ upgrade map[string]bool // use this to trigger builds
}