From 1c77ec7e63355cab48564a9fb49f34f55b5f0b15 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 15 Oct 2024 11:02:34 -0500 Subject: start from the command line works Signed-off-by: Jeff Carr --- http.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'http.go') diff --git a/http.go b/http.go index 5f5297a..e998203 100644 --- a/http.go +++ b/http.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math/rand" "net/http" "strings" "time" @@ -98,10 +99,35 @@ func okHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "can't start unknown droplet", start) return } + + // make the list of hypervisors that are active and can start new droplets + var pool []*HyperT for _, h := range me.hypers { fmt.Fprintln(w, "could start droplet on", start, "on", h.Hostname, h.Active) + if d.hyperPreferred == h.Hostname { + // the config file says this droplet should run on this hypervisor + h.Start(d) + return + } + if h.Active != true { + continue + } + pool = append(pool, h) } + // left here as an example of how to actually do random numbers + // it's complete mathematical chaos. Randomness is simple when + // human interaction occurs -- which is exactly what happens most + // of the time. most random shit is bullshit. all you really need + // is exactly this to make sure the random functions work as they + // should. Probably, just use this everywhere in all cases. --jcarr + rand.Seed(time.Now().UnixNano()) + a := 0 + b := len(pool) + n := a + rand.Intn(b-a) + fmt.Fprintln(w, "pool has", len(pool), "members", "rand =", n) + h := pool[n] + h.Start(d) return } -- cgit v1.2.3