parent
cc0ca1dd7c
commit
08757bc315
6
add.go
6
add.go
|
@ -27,7 +27,7 @@ func (x *Hypervisor) GetMemoryPrintable() string {
|
||||||
return fmt.Sprintf("%d GB", i)
|
return fmt.Sprintf("%d GB", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (all *Droplets) FindDroplet(name string) *Droplet {
|
func (all *Droplets) oldFindDroplet(name string) *Droplet {
|
||||||
for _, d := range all.Droplets {
|
for _, d := range all.Droplets {
|
||||||
if d.Hostname == name {
|
if d.Hostname == name {
|
||||||
return d
|
return d
|
||||||
|
@ -45,7 +45,7 @@ func (c *Cluster) FindDropletByName(name string) *Droplet {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) FindHypervisor(name string) *Hypervisor {
|
func (c *Cluster) FindHypervisorByName(name string) *Hypervisor {
|
||||||
for _, h := range c.Hypervisors {
|
for _, h := range c.Hypervisors {
|
||||||
if h.Hostname == name {
|
if h.Hostname == name {
|
||||||
return h
|
return h
|
||||||
|
@ -55,7 +55,7 @@ func (c *Cluster) FindHypervisor(name string) *Hypervisor {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
|
func (c *Cluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
|
||||||
h := c.FindHypervisor(hostname)
|
h := c.FindHypervisorByName(hostname)
|
||||||
if h != nil {
|
if h != nil {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
14
config.go
14
config.go
|
@ -8,7 +8,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
"google.golang.org/protobuf/encoding/prototext"
|
"google.golang.org/protobuf/encoding/prototext"
|
||||||
|
@ -19,7 +18,7 @@ import (
|
||||||
// to make it humanly possible to hand edit things as needed
|
// to make it humanly possible to hand edit things as needed
|
||||||
func (c *Cluster) ConfigSave() error {
|
func (c *Cluster) ConfigSave() error {
|
||||||
// try to backup the current cluster config files
|
// try to backup the current cluster config files
|
||||||
if err := backupConfigFiles(); err != nil {
|
if err := backupConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,17 +82,6 @@ func (c *Cluster) ConfigSave() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func backupConfigFiles() error {
|
|
||||||
// make a new dir to backup the files
|
|
||||||
now := time.Now()
|
|
||||||
// timestamp := now.Format("2022.07.18.190545") // 50yr shout out to K&R
|
|
||||||
timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
|
|
||||||
srcDir := filepath.Join(os.Getenv("VIRTIGO_HOME"))
|
|
||||||
destDir := filepath.Join(os.Getenv("VIRTIGO_HOME"), timestamp)
|
|
||||||
|
|
||||||
return backupFiles(srcDir, destDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Cluster) ConfigLoad() error {
|
func (c *Cluster) ConfigLoad() error {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
|
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
|
||||||
|
|
|
@ -10,8 +10,20 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func backupConfig() error {
|
||||||
|
// make a new dir to backup the files
|
||||||
|
now := time.Now()
|
||||||
|
// timestamp := now.Format("2022.07.18.190545") // 50yr shout out to K&R
|
||||||
|
timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
|
||||||
|
srcDir := filepath.Join(os.Getenv("VIRTIGO_HOME"))
|
||||||
|
destDir := filepath.Join(os.Getenv("VIRTIGO_HOME"), timestamp)
|
||||||
|
|
||||||
|
return backupFiles(srcDir, destDir)
|
||||||
|
}
|
||||||
|
|
||||||
func backupFiles(srcDir string, destDir string) error {
|
func backupFiles(srcDir string, destDir string) error {
|
||||||
// Create the destination directory
|
// Create the destination directory
|
||||||
err := os.MkdirAll(destDir, os.ModePerm)
|
err := os.MkdirAll(destDir, os.ModePerm)
|
Loading…
Reference in New Issue