summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-22 19:19:22 -0500
committerJeff Carr <[email protected]>2024-10-22 19:19:22 -0500
commit448f4a0649d99c3d04096a6488193545751955ec (patch)
tree0e957f241d4a60f940e710abf558f3b3e85091e3
parente2d872f088be24e0a6355f6826625b129a965698 (diff)
dumped droplet file
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--configfiles.go41
-rw-r--r--main.go1
-rw-r--r--poll.go12
3 files changed, 9 insertions, 45 deletions
diff --git a/configfiles.go b/configfiles.go
index cda724d..ef2b3d1 100644
--- a/configfiles.go
+++ b/configfiles.go
@@ -44,6 +44,7 @@ func writeConfigFile() {
homeDir, _ := os.UserHomeDir()
fullname := filepath.Join(homeDir, ".config/virtigo.json")
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
+ defer cfgfile.Close()
if err != nil {
log.Info("open config file :", err)
return
@@ -52,46 +53,6 @@ func writeConfigFile() {
fmt.Fprintln(cfgfile, json)
}
-func readDropletFile(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]
- d := findDroplet(name)
- if d == nil {
- // this is a new unknown droplet (not in the config file)
- d = new(DropletT)
- d.pb = me.cluster.AddDroplet(name, 16, 256)
- if len(fields) > 1 && fields[1] != "ON" {
- d.pb.StartState = "OFF"
- } else {
- d.pb.StartState = "ON"
- }
- if len(fields) >= 3 {
- d.pb.PreferredHypervisor = fields[2]
- }
- me.droplets = append(me.droplets, d)
- log.Log(EVENT, "config new droplet", d.pb.Hostname, d.pb.StartState, d.pb.PreferredHypervisor)
- } else {
- log.Info("not sure what to do here. duplicate droplet", name, "in config file")
- }
-
- }
-}
-
func readHypervisorFile(filename string) {
// fmt.Fprintln(w, "GOT TEST?")
homeDir, _ := os.UserHomeDir()
diff --git a/main.go b/main.go
index d796946..cf0bdbb 100644
--- a/main.go
+++ b/main.go
@@ -30,7 +30,6 @@ func main() {
}
readConfigFile()
- // readDropletFile("droplets")
readHypervisorFile("hypervisor")
writeConfigFile()
diff --git a/poll.go b/poll.go
index 12c07af..24f1dad 100644
--- a/poll.go
+++ b/poll.go
@@ -48,10 +48,6 @@ func (h *HyperT) pollHypervisor() {
d.CurrentState = "ON"
d.lastpoll = time.Now()
- // this means the droplet is still where it was before
- if d.h.pb.Hostname == h.pb.Hostname {
- continue
- }
if d.h == nil {
// this means the droplet was in the config file
@@ -65,6 +61,14 @@ func (h *HyperT) pollHypervisor() {
}
log.Log(EVENT, "new droplet", d.pb.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)")
+ d.h = h
+ continue
+ }
+
+ // this means the droplet is still where it was before
+ if d.h.pb.Hostname != h.pb.Hostname {
+ log.Log(EVENT, "droplet", d.h.pb.Hostname, "moved to", h.pb.Hostname)
+ continue
}
d.h = h
}