diff --git a/Makefile b/Makefile index 74da8df..1e7c471 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ # go install -all: droplet.pb.go hypervisor.pb.go cluster.pb.go events.pb.go experiments.pb.go +all: droplet.pb.go hypervisor.pb.go cluster.pb.go event.pb.go experiments.pb.go make -C example vet: lint @@ -42,11 +42,11 @@ hypervisor.pb.go: hypervisor.proto --go_opt=Mhypervisor.proto=go.wit.com/lib/protobuf/virtbuf \ hypervisor.proto -events.pb.go: events.proto +event.pb.go: event.proto cd ~/go/src && protoc --go_out=. \ --proto_path=go.wit.com/lib/protobuf/virtbuf \ - --go_opt=Mevents.proto=go.wit.com/lib/protobuf/virtbuf \ - events.proto + --go_opt=Mevent.proto=go.wit.com/lib/protobuf/virtbuf \ + event.proto experiments.pb.go: experiments.proto cd ~/go/src && protoc --go_out=. \ @@ -59,6 +59,7 @@ cluster.pb.go: cluster.proto --go_opt=Mdroplet.proto=go.wit.com/lib/protobuf/virtbuf \ --go_opt=Mcluster.proto=go.wit.com/lib/protobuf/virtbuf \ --go_opt=Mhypervisor.proto=go.wit.com/lib/protobuf/virtbuf \ + --go_opt=Mevent.proto=go.wit.com/lib/protobuf/virtbuf \ cluster.proto deps: diff --git a/cluster.proto b/cluster.proto index 8631e43..0d07d5a 100644 --- a/cluster.proto +++ b/cluster.proto @@ -3,10 +3,12 @@ package virtbuf; import "droplet.proto"; import "hypervisor.proto"; +import "event.proto"; message Cluster { int64 id = 1; - repeated Droplet droplets = 2; - repeated Hypervisor hypervisors = 3; - repeated string dirs = 4; + repeated string dirs = 2; + repeated Droplet droplets = 3; + repeated Hypervisor hypervisors = 4; + repeated Event events = 5; } diff --git a/config.go b/config.go index 9bbf524..639844d 100644 --- a/config.go +++ b/config.go @@ -22,6 +22,34 @@ func (e *Events) ConfigSave() error { return ConfigWriteTEXT(e, "events.text") } +func (c *Cluster) ConfigSave() error { + var d *Droplets + d = new(Droplets) + d.Droplets = c.Droplets + if err := ConfigWriteJSON(d, "newdroplets.json"); err != nil { + fmt.Println("droplets.json write failed") + return err + } + + var h *Hypervisors + h = new(Hypervisors) + h.Hypervisors = c.Hypervisors + if err := ConfigWriteJSON(h, "newhypervisors.json"); err != nil { + fmt.Println("hypervisors.json write failed") + return err + } + + var e *Events + e = new(Events) + e.Events = c.Events + if err := ConfigWriteJSON(h, "newEvents.json"); err != nil { + fmt.Println("newEvents.json write failed") + return err + } + + return nil +} + // read in the events log file // reads in from the prototext file // prototext file formats are not garrenteed to be stable. todo: hammer that out @@ -211,10 +239,18 @@ func (d *Droplets) FormatJSON() string { return protojson.Format(d) } +func (d *Droplet) FormatJSON() string { + return protojson.Format(d) +} + func (e *Events) FormatJSON() string { return protojson.Format(e) } +func (h *Hypervisors) FormatJSON() string { + return protojson.Format(h) +} + // apparently this isn't supposed to be used? // https://protobuf.dev/reference/go/faq/#unstable-text // this is a shame because this is much nicer output than JSON Format() diff --git a/events.proto b/event.proto similarity index 100% rename from events.proto rename to event.proto diff --git a/helpers.go b/helpers.go index e9864ae..d55f64a 100644 --- a/helpers.go +++ b/helpers.go @@ -25,33 +25,15 @@ func (x *Hypervisor) GetMemoryPrintable() string { return fmt.Sprintf("%d GB", i) } -/* -func (c *Cluster) MarshalJSON() ([]byte, error) { - return protojson.Marshal(c) +func (all *Droplets) FindDroplet(name string) *Droplet { + for _, d := range all.Droplets { + if d.Hostname == name { + return d + } + } + return nil } -func (c *Cluster) FormatJSON() string { - return protojson.Format(c) -} - -func (c *Cluster) UnmarshalJSON(data []byte) error { - return protojson.Unmarshal(data, c) -} -*/ - -// apparently this isn't supposed to be used? -// https://protobuf.dev/reference/go/faq/#unstable-text -// this is a shame because this is much nicer output than JSON Format() -/* -func (c *Cluster) FormatTEXT() string { - return prototext.Format(c) -} - -func (d *Droplets) FormatTEXT() string { - return prototext.Format(d) -} -*/ - func (c *Cluster) FindDroplet(name string) *Droplet { for _, d := range c.Droplets { if d.Hostname == name {