diff options
| author | Jeff Carr <[email protected]> | 2025-03-24 21:54:13 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-24 21:54:13 -0500 |
| commit | e4345c8ad6584f4fc5393c7844bb1967d6564d63 (patch) | |
| tree | b145c2e11edd3650ea0a3ea1954838ae00b8b818 /config.go | |
| parent | 276c5cec2f28ef265a615d31cf27d25e72b29cf8 (diff) | |
moving to a cluster.proto config filev0.2.33
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 44 |
1 files changed, 30 insertions, 14 deletions
@@ -16,7 +16,7 @@ import ( // writes out the cluster information it seperate files // to make it humanly possible to hand edit things as needed -func (c *Cluster) ConfigSave() error { +func (c *OldCluster) ConfigSave() error { // try to backup the current cluster config files if err := backupConfig(); err != nil { return err @@ -64,7 +64,7 @@ func (c *Cluster) ConfigSave() error { return nil } -func (c *Cluster) ConfigLoad() error { +func (c *OldCluster) ConfigLoad() error { if c == nil { return errors.New("It's not safe to run ConfigLoad() on a nil cluster") } @@ -157,6 +157,23 @@ func ConfigWriteJSON(a any, filename string) error { return nil } +func (c *OldCluster) configWriteDroplets() error { + fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.new.text") + cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + defer cfgfile.Close() + if err != nil { + fmt.Println("open config file :", err) + return err + } + loop := c.d.All() // get the list of droplets + for loop.Scan() { + d := loop.Next() + text := prototext.Format(d) + fmt.Fprintln(cfgfile, text) + } + return nil +} + func ConfigWriteTEXT(a any, filename string) error { fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), filename) cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) @@ -174,19 +191,18 @@ func ConfigWriteTEXT(a any, filename string) error { return nil } -func (c *Cluster) configWriteDroplets() error { - fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.new.text") - cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) - defer cfgfile.Close() - if err != nil { - fmt.Println("open config file :", err) - return err +func (c *Clusters) ConfigLoad() error { + if c == nil { + return errors.New("It's not safe to run ConfigLoad() on a nil cluster") } - loop := c.d.All() // get the list of droplets - for loop.Scan() { - d := loop.Next() - text := prototext.Format(d) - fmt.Fprintln(cfgfile, text) + + if data, err := loadFile("cluster.text"); err == nil { + if err = prototext.Unmarshal(data, c); err != nil { + fmt.Println("broken cluster.textconfig file") + return err + } + } else { + return err } return nil } |
