dumped droplet file
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
e2d872f088
commit
448f4a0649
|
@ -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()
|
||||
|
|
1
main.go
1
main.go
|
@ -30,7 +30,6 @@ func main() {
|
|||
}
|
||||
|
||||
readConfigFile()
|
||||
// readDropletFile("droplets")
|
||||
readHypervisorFile("hypervisor")
|
||||
writeConfigFile()
|
||||
|
||||
|
|
12
poll.go
12
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue