summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-06 05:24:09 -0600
committerJeff Carr <[email protected]>2024-11-06 05:24:09 -0600
commit3c9d1d6f1d78bbf1ba86097bd29133d96dde6698 (patch)
tree6a775ff41abf377a3589d579e56c56e7e2e84e42
parent0da809ae42582f573ada0a73e22c3fb1dceca6de (diff)
still runs
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--create.go89
-rw-r--r--main.go13
2 files changed, 13 insertions, 89 deletions
diff --git a/create.go b/create.go
deleted file mode 100644
index d6d2a67..0000000
--- a/create.go
+++ /dev/null
@@ -1,89 +0,0 @@
-package main
-
-import (
- "errors"
- "fmt"
- "math/rand"
- "time"
-
- pb "go.wit.com/lib/protobuf/virtbuf"
-)
-
-// for now, because sometimes this should write to stdout and
-// sometimes to http socket, it returns a string
-func startDroplet(d *pb.Droplet) (string, error) {
- var result string
- name := d.Hostname
- // validate the droplet
- if err := ValidateDroplet(d); err != nil {
- result = "ValidateDroplet() failed droplet " + d.Hostname
- return result, err
- }
-
- // is the droplet already on?
- if d.Current.State == pb.DropletState_ON {
- result = "EVENT start droplet " + d.Hostname + " is already ON"
- return result, errors.New(result)
- }
-
- // how long has the cluster been stable?
- // wait until it is stable. use this to throttle droplet starts
- dur := time.Since(me.unstable)
- result = fmt.Sprintln("should start droplet", name, "here. grid stable for:", pb.FormatDuration(dur))
- if dur < me.unstableTimeout {
- tmp := pb.FormatDuration(me.unstableTimeout)
- result += "grid is still too unstable (unstable timeout = " + tmp + ")"
- return result, errors.New("grid is still unstable")
- }
-
- // make the list of hypervisors that are active and can start new droplets
- var pool []*HyperT
- for _, h := range me.hypers {
- // this droplet is set to use this and only this hypervisor
- if d.ForceHypervisor == h.pb.Hostname {
- ok, b := h.start(d)
- if ok {
- return result + b, nil
- }
- return result + b, errors.New("start " + name + " on hypervisor " + h.pb.Hostname)
- }
-
- // skip hypervisors marked inactive
- if h.pb.Active != true {
- result += fmt.Sprintln("hypervisor is inactive:", name, "for", h.pb.Hostname, h.pb.Active)
- continue
- }
-
- // the config file says this droplet should run on this hypervisor
- // attempt to start the droplet here. use this even if the hypervisor is inactive?
- if d.PreferredHypervisor == h.pb.Hostname {
- ok, b := h.start(d)
- if ok {
- return result + b, nil
- }
- return result + b, errors.New("start " + name + " on hypervisor " + h.pb.Hostname)
- }
-
- result += fmt.Sprintln("hypervisor ready:", name, "for", h.pb.Hostname, h.pb.Active)
- 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)
- result += fmt.Sprintln("pool has", len(pool), "members", "rand =", n)
- h := pool[n]
-
- ok, output := h.start(d)
- if ok {
- return result + output, nil
- }
- return result + output, errors.New("start " + name + " on hypervisor " + h.pb.Hostname)
-}
diff --git a/main.go b/main.go
index 7e36374..55173f2 100644
--- a/main.go
+++ b/main.go
@@ -56,6 +56,10 @@ func main() {
me.cluster = pb.InitCluster()
if err := me.cluster.ConfigLoad(); err != nil {
log.Info("config load error", err)
+ log.Info("")
+ log.Info("You have never run this before")
+ log.Info("init example cloud here")
+ log.Sleep(2)
os.Exit(-1)
}
@@ -162,6 +166,15 @@ func main() {
go h.NewWatchdog()
}
+ var cloud *virtigolib.CloudManager
+ cloud = virtigolib.NewCloud()
+ found, _ := cloud.FindDropletByName("www.wit.com")
+ if found == nil {
+ log.Info("d == nil")
+ } else {
+ log.Info("d == ", found)
+ }
+
// sit here
startHTTP()
}