dumped droplet file

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-22 19:19:22 -05:00
parent e2d872f088
commit 448f4a0649
3 changed files with 9 additions and 45 deletions

View File

@ -44,6 +44,7 @@ func writeConfigFile() {
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
fullname := filepath.Join(homeDir, ".config/virtigo.json") fullname := filepath.Join(homeDir, ".config/virtigo.json")
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666) cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()
if err != nil { if err != nil {
log.Info("open config file :", err) log.Info("open config file :", err)
return return
@ -52,46 +53,6 @@ func writeConfigFile() {
fmt.Fprintln(cfgfile, json) 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) { func readHypervisorFile(filename string) {
// fmt.Fprintln(w, "GOT TEST?") // fmt.Fprintln(w, "GOT TEST?")
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()

View File

@ -30,7 +30,6 @@ func main() {
} }
readConfigFile() readConfigFile()
// readDropletFile("droplets")
readHypervisorFile("hypervisor") readHypervisorFile("hypervisor")
writeConfigFile() writeConfigFile()

12
poll.go
View File

@ -48,10 +48,6 @@ func (h *HyperT) pollHypervisor() {
d.CurrentState = "ON" d.CurrentState = "ON"
d.lastpoll = time.Now() 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 { if d.h == nil {
// this means the droplet was in the config file // 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)") 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 d.h = h
} }