deprecate old experiment
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
7a0925041e
commit
954e555ac7
39
config.go
39
config.go
|
@ -12,68 +12,81 @@ import (
|
||||||
"google.golang.org/protobuf/encoding/prototext"
|
"google.golang.org/protobuf/encoding/prototext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WriteConfig(d *Droplets, h *Hypervisors, e *Events) {
|
func WriteConfig(d *Droplets, h *Hypervisors, e *Events) bool {
|
||||||
d.WriteConfigJSON()
|
if !d.WriteConfigJSON() {
|
||||||
d.WriteConfigTEXT()
|
return false
|
||||||
|
}
|
||||||
|
if !d.WriteConfigTEXT() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
e.WriteConfigJSON()
|
if e.WriteConfigJSON() {
|
||||||
e.WriteConfigTEXT()
|
return false
|
||||||
|
}
|
||||||
|
if e.WriteConfigTEXT() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// export as json
|
// export as json
|
||||||
func (e *Events) WriteConfigJSON() {
|
func (e *Events) WriteConfigJSON() bool {
|
||||||
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "events.json")
|
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "events.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()
|
defer cfgfile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("open config file :", err)
|
fmt.Println("open config file :", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
text := e.FormatJSON()
|
text := e.FormatJSON()
|
||||||
fmt.Fprintln(cfgfile, text)
|
fmt.Fprintln(cfgfile, text)
|
||||||
fmt.Println("Write:", fullname, "OK")
|
fmt.Println("Write:", fullname, "OK")
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// export as prototext
|
// export as prototext
|
||||||
func (e *Events) WriteConfigTEXT() {
|
func (e *Events) WriteConfigTEXT() bool {
|
||||||
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "events.text")
|
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "events.text")
|
||||||
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()
|
defer cfgfile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("open config file :", err)
|
fmt.Println("open config file :", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
text := e.FormatTEXT()
|
text := e.FormatTEXT()
|
||||||
fmt.Fprintln(cfgfile, text)
|
fmt.Fprintln(cfgfile, text)
|
||||||
fmt.Println("Write:", fullname, "OK")
|
fmt.Println("Write:", fullname, "OK")
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// export as json
|
// export as json
|
||||||
func (d *Droplets) WriteConfigJSON() {
|
func (d *Droplets) WriteConfigJSON() bool {
|
||||||
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.json")
|
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.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()
|
defer cfgfile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("open config file :", err)
|
fmt.Println("open config file :", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
text := d.FormatJSON()
|
text := d.FormatJSON()
|
||||||
fmt.Fprintln(cfgfile, text)
|
fmt.Fprintln(cfgfile, text)
|
||||||
fmt.Println("Write:", fullname, "OK")
|
fmt.Println("Write:", fullname, "OK")
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// export as prototext
|
// export as prototext
|
||||||
func (d *Droplets) WriteConfigTEXT() {
|
func (d *Droplets) WriteConfigTEXT() bool {
|
||||||
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.text")
|
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.text")
|
||||||
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()
|
defer cfgfile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("open config file :", err)
|
fmt.Println("open config file :", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
text := d.FormatTEXT()
|
text := d.FormatTEXT()
|
||||||
fmt.Fprintln(cfgfile, text)
|
fmt.Fprintln(cfgfile, text)
|
||||||
fmt.Println("Write:", fullname, "OK")
|
fmt.Println("Write:", fullname, "OK")
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// human readable JSON
|
// human readable JSON
|
||||||
|
|
|
@ -29,7 +29,7 @@ message Droplet {
|
||||||
string image_url = 15; // url to the image
|
string image_url = 15; // url to the image
|
||||||
|
|
||||||
// is it possible to have custom formatting in JSON and TEXT marshal/unmarshal ?
|
// is it possible to have custom formatting in JSON and TEXT marshal/unmarshal ?
|
||||||
JunkInfo humantest = 16;
|
// JunkInfo humantest = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DropletState {
|
enum DropletState {
|
||||||
|
|
Loading…
Reference in New Issue