diff options
| author | Jeff Carr <[email protected]> | 2024-10-22 19:19:22 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-22 19:19:22 -0500 |
| commit | 448f4a0649d99c3d04096a6488193545751955ec (patch) | |
| tree | 0e957f241d4a60f940e710abf558f3b3e85091e3 | |
| parent | e2d872f088be24e0a6355f6826625b129a965698 (diff) | |
dumped droplet file
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | configfiles.go | 41 | ||||
| -rw-r--r-- | main.go | 1 | ||||
| -rw-r--r-- | poll.go | 12 |
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() @@ -30,7 +30,6 @@ func main() { } readConfigFile() - // readDropletFile("droplets") readHypervisorFile("hypervisor") writeConfigFile() @@ -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 } |
