deprecate hypervisor file. yay!
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
448f4a0649
commit
525362fcc7
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
|
@ -26,6 +25,27 @@ func readConfigFile() {
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize each hypervisor
|
||||||
|
for _, pbh := range me.cluster.Hypervisors {
|
||||||
|
h := findHypervisor(pbh.Hostname)
|
||||||
|
if h != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// this is a new unknown droplet (not in the config file)
|
||||||
|
h = new(HyperT)
|
||||||
|
h.pb = pbh
|
||||||
|
|
||||||
|
h.Delay = 5 * time.Second
|
||||||
|
h.lastpoll = time.Now()
|
||||||
|
h.Scan = func() {
|
||||||
|
h.pollHypervisor()
|
||||||
|
}
|
||||||
|
me.hypers = append(me.hypers, h)
|
||||||
|
log.Log(EVENT, "config new hypervisors", h.pb.Hostname)
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize values for each droplet
|
||||||
for _, pbd := range me.cluster.Droplets {
|
for _, pbd := range me.cluster.Droplets {
|
||||||
d := findDroplet(pbd.Hostname)
|
d := findDroplet(pbd.Hostname)
|
||||||
if d != nil {
|
if d != nil {
|
||||||
|
@ -37,7 +57,6 @@ func readConfigFile() {
|
||||||
me.droplets = append(me.droplets, d)
|
me.droplets = append(me.droplets, d)
|
||||||
log.Log(EVENT, "config new droplet", d.pb.Hostname, d.pb.StartState, d.pb.PreferredHypervisor)
|
log.Log(EVENT, "config new droplet", d.pb.Hostname, d.pb.StartState, d.pb.PreferredHypervisor)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeConfigFile() {
|
func writeConfigFile() {
|
||||||
|
@ -52,50 +71,3 @@ func writeConfigFile() {
|
||||||
json := me.cluster.FormatJSON()
|
json := me.cluster.FormatJSON()
|
||||||
fmt.Fprintln(cfgfile, json)
|
fmt.Fprintln(cfgfile, json)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readHypervisorFile(filename string) {
|
|
||||||
// fmt.Fprintln(w, "GOT TEST?")
|
|
||||||
homeDir, _ := os.UserHomeDir()
|
|
||||||
fullname := filepath.Join(homeDir, ".config/virtigo/", filename)
|
|
||||||
pfile, err := os.ReadFile(fullname)
|
|
||||||
if err != nil {
|
|
||||||
log.Info("No config file :", err)
|
|
||||||
// w.Write(pfile)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
f := string(pfile)
|
|
||||||
for _, line := range strings.Split(f, "\n") {
|
|
||||||
fields := strings.Fields(line)
|
|
||||||
if len(fields) < 1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name := fields[0]
|
|
||||||
h := addHypervisor(name)
|
|
||||||
if len(fields) < 2 || fields[1] != "active" {
|
|
||||||
h.pb.Active = false
|
|
||||||
} else {
|
|
||||||
h.pb.Active = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addHypervisor(name string) *HyperT {
|
|
||||||
var h *HyperT
|
|
||||||
h = findHypervisor(name)
|
|
||||||
if h != nil {
|
|
||||||
log.Info("not sure what to do here. duplicate hypervisor", name, "in config file")
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
log.Log(EVENT, "config new hypervisor", name)
|
|
||||||
h = new(HyperT)
|
|
||||||
h.Delay = 5 * time.Second
|
|
||||||
h.lastpoll = time.Now()
|
|
||||||
h.Scan = func() {
|
|
||||||
h.pollHypervisor()
|
|
||||||
}
|
|
||||||
h.pb = me.cluster.AddHypervisor(name, 16, 256)
|
|
||||||
h.pb.Autoscan = true
|
|
||||||
me.hypers = append(me.hypers, h)
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
4
main.go
4
main.go
|
@ -30,12 +30,13 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
readConfigFile()
|
readConfigFile()
|
||||||
readHypervisorFile("hypervisor")
|
// readHypervisorFile("hypervisor")
|
||||||
writeConfigFile()
|
writeConfigFile()
|
||||||
|
|
||||||
// initialize the grid as unstable
|
// initialize the grid as unstable
|
||||||
me.unstable = time.Now()
|
me.unstable = time.Now()
|
||||||
|
|
||||||
|
/*
|
||||||
log.Info("command line hypervisors:", argv.Hosts)
|
log.Info("command line hypervisors:", argv.Hosts)
|
||||||
for _, name := range argv.Hosts {
|
for _, name := range argv.Hosts {
|
||||||
h := findHypervisor(name)
|
h := findHypervisor(name)
|
||||||
|
@ -46,6 +47,7 @@ func main() {
|
||||||
h = addHypervisor(name)
|
h = addHypervisor(name)
|
||||||
h.pb.Active = true
|
h.pb.Active = true
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if argv.Start != "" {
|
if argv.Start != "" {
|
||||||
d := findDroplet(argv.Start)
|
d := findDroplet(argv.Start)
|
||||||
|
|
1
poll.go
1
poll.go
|
@ -48,7 +48,6 @@ func (h *HyperT) pollHypervisor() {
|
||||||
d.CurrentState = "ON"
|
d.CurrentState = "ON"
|
||||||
d.lastpoll = time.Now()
|
d.lastpoll = time.Now()
|
||||||
|
|
||||||
|
|
||||||
if d.h == nil {
|
if d.h == nil {
|
||||||
// this means the droplet was in the config file
|
// this means the droplet was in the config file
|
||||||
// but this is the first time it's shown up as running
|
// but this is the first time it's shown up as running
|
||||||
|
|
|
@ -32,7 +32,8 @@ func (h *HyperT) NewWatchdog() {
|
||||||
return
|
return
|
||||||
case t := <-h.Dog.C:
|
case t := <-h.Dog.C:
|
||||||
log.Log(POLL, "Watchdog() ticked", h.pb.Hostname, "Current time: ", t)
|
log.Log(POLL, "Watchdog() ticked", h.pb.Hostname, "Current time: ", t)
|
||||||
h.Scan()
|
h.pollHypervisor()
|
||||||
|
// h.Scan()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue