summaryrefslogtreecommitdiff
path: root/configfiles.go
diff options
context:
space:
mode:
Diffstat (limited to 'configfiles.go')
-rw-r--r--configfiles.go70
1 files changed, 21 insertions, 49 deletions
diff --git a/configfiles.go b/configfiles.go
index ef2b3d1..c633a6d 100644
--- a/configfiles.go
+++ b/configfiles.go
@@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
- "strings"
"time"
pb "go.wit.com/lib/protobuf/virtbuf"
@@ -26,6 +25,27 @@ func readConfigFile() {
os.Exit(-1)
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 {
d := findDroplet(pbd.Hostname)
if d != nil {
@@ -37,7 +57,6 @@ func readConfigFile() {
me.droplets = append(me.droplets, d)
log.Log(EVENT, "config new droplet", d.pb.Hostname, d.pb.StartState, d.pb.PreferredHypervisor)
}
-
}
func writeConfigFile() {
@@ -52,50 +71,3 @@ func writeConfigFile() {
json := me.cluster.FormatJSON()
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
-}