Compare commits
No commits in common. "master" and "v0.2.13" have entirely different histories.
|
@ -1,3 +1,5 @@
|
|||
go.*
|
||||
|
||||
*.pb.go
|
||||
*.swp
|
||||
|
||||
example/example
|
||||
|
|
8
Makefile
8
Makefile
|
@ -3,7 +3,7 @@
|
|||
# cd ~/go/src/google.golang.org/protobuf/cmd/protoc-gen-go
|
||||
# go install
|
||||
|
||||
all: proto goimports vet
|
||||
all: droplet.pb.go hypervisor.pb.go event.pb.go experiments.pb.go vet
|
||||
|
||||
vet:
|
||||
@GO111MODULE=off go vet
|
||||
|
@ -22,8 +22,6 @@ clean:
|
|||
rm -f *.pb.go
|
||||
-rm -f go.*
|
||||
|
||||
proto:droplet.pb.go hypervisor.pb.go event.pb.go cluster.pb.go
|
||||
|
||||
droplet.pb.go: droplet.proto
|
||||
autogenpb --proto droplet.proto
|
||||
|
||||
|
@ -33,8 +31,8 @@ hypervisor.pb.go: hypervisor.proto
|
|||
event.pb.go: event.proto
|
||||
autogenpb --proto event.proto
|
||||
|
||||
cluster.pb.go: cluster.proto
|
||||
autogenpb --proto cluster.proto
|
||||
experiments.pb.go: experiments.proto
|
||||
autogenpb --proto experiments.proto
|
||||
|
||||
deps:
|
||||
apt install golang-goprotobuf-dev
|
||||
|
|
35
add.go
35
add.go
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
/*
|
||||
func (c *OldCluster) InitDroplet(hostname string) (*Droplet, error) {
|
||||
func (c *Cluster) InitDroplet(hostname string) (*Droplet, error) {
|
||||
var d *Droplet
|
||||
d = new(Droplet)
|
||||
d.Current = new(Current)
|
||||
|
@ -50,7 +50,7 @@ func (x *Hypervisor) SetMemoryGB(gb int) {
|
|||
x.Memory = int64(gb * 1024 * 1024 * 1024)
|
||||
}
|
||||
|
||||
func (c *OldCluster) FindDropletByName(name string) *Droplet {
|
||||
func (c *Cluster) FindDropletByName(name string) *Droplet {
|
||||
loop := c.d.All() // get the list of droplets
|
||||
for loop.Scan() {
|
||||
d := loop.Next()
|
||||
|
@ -61,20 +61,7 @@ func (c *OldCluster) FindDropletByName(name string) *Droplet {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *OldCluster) FindDropletByUuid(id string) *Droplet {
|
||||
/*
|
||||
log.Info("START FIND", id)
|
||||
loop := c.d.All() // get the list of droplets
|
||||
for loop.Scan() {
|
||||
d := loop.Next()
|
||||
log.Info("droplet:", d.Hostname, d.Uuid)
|
||||
}
|
||||
log.Info("END FIND", id)
|
||||
*/
|
||||
return c.d.FindByUuid(id)
|
||||
}
|
||||
|
||||
func (c *OldCluster) FindHypervisorByName(name string) *Hypervisor {
|
||||
func (c *Cluster) FindHypervisorByName(name string) *Hypervisor {
|
||||
for _, h := range c.H.Hypervisors {
|
||||
if h.Hostname == name {
|
||||
return h
|
||||
|
@ -83,7 +70,7 @@ func (c *OldCluster) FindHypervisorByName(name string) *Hypervisor {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *OldCluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
|
||||
func (c *Cluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
|
||||
h := c.FindHypervisorByName(hostname)
|
||||
if h != nil {
|
||||
return h
|
||||
|
@ -104,7 +91,7 @@ func (c *OldCluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervis
|
|||
return h
|
||||
}
|
||||
|
||||
func (c *OldCluster) AddEvent(e *Event) {
|
||||
func (c *Cluster) AddEvent(e *Event) {
|
||||
c.e.Events = append(c.e.Events, e)
|
||||
}
|
||||
|
||||
|
@ -122,7 +109,7 @@ func NewDefaultDroplet(hostname string) *Droplet {
|
|||
return d
|
||||
}
|
||||
|
||||
func (c *OldCluster) AddDropletSimple(uuid string, hostname string, cpus int, mem int) *Droplet {
|
||||
func (c *Cluster) AddDropletSimple(uuid string, hostname string, cpus int, mem int) *Droplet {
|
||||
d := c.FindDropletByName(hostname)
|
||||
if d != nil {
|
||||
return d
|
||||
|
@ -144,7 +131,7 @@ func (c *OldCluster) AddDropletSimple(uuid string, hostname string, cpus int, me
|
|||
}
|
||||
|
||||
// This isn't for the marketing department
|
||||
func (c *OldCluster) AddDropletLocal(name string, hypername string) *Droplet {
|
||||
func (c *Cluster) AddDropletLocal(name string, hypername string) *Droplet {
|
||||
d := &Droplet{
|
||||
Hostname: name,
|
||||
}
|
||||
|
@ -162,7 +149,7 @@ func (c *OldCluster) AddDropletLocal(name string, hypername string) *Droplet {
|
|||
return d
|
||||
}
|
||||
|
||||
func (c *OldCluster) BlankFields() {
|
||||
func (c *Cluster) BlankFields() {
|
||||
loop := c.d.All() // get the list of droplets
|
||||
for loop.Scan() {
|
||||
d := loop.Next()
|
||||
|
@ -174,7 +161,7 @@ func (epb *Events) AppendEvent(e *Event) {
|
|||
epb.Events = append(epb.Events, e)
|
||||
}
|
||||
|
||||
func (c *OldCluster) ClusterStable() (bool, string) {
|
||||
func (c *Cluster) ClusterStable() (bool, string) {
|
||||
last := time.Since(c.Unstable.AsTime())
|
||||
if last > c.UnstableTimeout.AsDuration() {
|
||||
// the cluster has not been stable for 133 seconds
|
||||
|
@ -186,7 +173,7 @@ func (c *OldCluster) ClusterStable() (bool, string) {
|
|||
}
|
||||
|
||||
// check the cluster and droplet to make sure it's ready to start
|
||||
func (c *OldCluster) DropletReady(d *Droplet) (bool, string) {
|
||||
func (c *Cluster) DropletReady(d *Droplet) (bool, string) {
|
||||
if c == nil {
|
||||
return false, "cluster == nil"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
// thank chatgpt for this because why. why write this if you can have it
|
||||
// kick this out in 30 seconds
|
||||
|
|
18
change.go
18
change.go
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
import (
|
||||
// "reflect"
|
||||
|
@ -73,7 +73,7 @@ func (d *Droplet) NewChangeEvent(fname string, origval any, newval any) *Event {
|
|||
var e *Event
|
||||
e = new(Event)
|
||||
|
||||
e.DropletName = d.Hostname
|
||||
e.Droplet = d.Hostname
|
||||
e.OrigVal = convertToString(origval)
|
||||
e.NewVal = convertToString(newval)
|
||||
e.FieldName = fname
|
||||
|
@ -99,12 +99,12 @@ func NewAddEvent(a any, fname string, newval any) *Event {
|
|||
case *Droplet:
|
||||
var d *Droplet
|
||||
d = a.(*Droplet)
|
||||
e.DropletName = d.Hostname
|
||||
e.Droplet = d.Hostname
|
||||
case nil:
|
||||
e.DropletName = "<nil>"
|
||||
e.Droplet = "<nil>"
|
||||
default:
|
||||
log.Info("newAddEvent() unknown type", v)
|
||||
e.DropletName = "on something somewhere"
|
||||
e.Droplet = "on something somewhere"
|
||||
}
|
||||
|
||||
e.NewVal = convertToString(newval)
|
||||
|
@ -163,7 +163,7 @@ func (d *Droplet) SetState(newState DropletState) {
|
|||
}
|
||||
|
||||
// records an event that the droplet changed state (aka turned on, turned off, etc)
|
||||
func (c *OldCluster) ChangeDropletState(d *Droplet, newState DropletState) error {
|
||||
func (c *Cluster) ChangeDropletState(d *Droplet, newState DropletState) error {
|
||||
if c == nil {
|
||||
return errors.New("cluster is nil")
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ func (c *OldCluster) ChangeDropletState(d *Droplet, newState DropletState) error
|
|||
var e *Event
|
||||
e = new(Event)
|
||||
|
||||
e.DropletName = d.Hostname
|
||||
e.Droplet = d.Hostname
|
||||
e.OrigVal = convertToString(d.Current.State)
|
||||
e.NewVal = convertToString(newState)
|
||||
e.FieldName = "status"
|
||||
|
@ -190,7 +190,7 @@ func (c *OldCluster) ChangeDropletState(d *Droplet, newState DropletState) error
|
|||
}
|
||||
|
||||
// records an event that the droplet migrated to another hypervisor
|
||||
func (c *OldCluster) DropletMoved(d *Droplet, newh *Hypervisor) error {
|
||||
func (c *Cluster) DropletMoved(d *Droplet, newh *Hypervisor) error {
|
||||
if c == nil {
|
||||
return errors.New("cluster is nil")
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ func (c *OldCluster) DropletMoved(d *Droplet, newh *Hypervisor) error {
|
|||
var e *Event
|
||||
e = new(Event)
|
||||
|
||||
e.DropletName = d.Hostname
|
||||
e.Droplet = d.Hostname
|
||||
e.OrigVal = d.Current.Hypervisor
|
||||
e.NewVal = newh.Hostname
|
||||
e.FieldName = "droplet migrate"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
import (
|
||||
sync "sync"
|
||||
|
@ -7,7 +7,7 @@ import (
|
|||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
type OldCluster struct {
|
||||
type Cluster struct {
|
||||
sync.RWMutex
|
||||
|
||||
Dirs []string
|
||||
|
@ -18,20 +18,8 @@ type OldCluster struct {
|
|||
UnstableTimeout *durationpb.Duration
|
||||
}
|
||||
|
||||
func (c *OldCluster) GetDropletsPB() *Droplets {
|
||||
return c.d
|
||||
}
|
||||
|
||||
func (c *OldCluster) GetHypervisorsPB() *Hypervisors {
|
||||
return c.H
|
||||
}
|
||||
|
||||
func (c *OldCluster) GetEventsPB() *Events {
|
||||
return c.e
|
||||
}
|
||||
|
||||
// adds a new droplet. enforce unique hostnames
|
||||
func (c *OldCluster) AddDroplet(newd *Droplet) bool {
|
||||
func (c *Cluster) AddDroplet(newd *Droplet) bool {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
syntax = "proto3";
|
||||
package virtpb;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "droplet.proto";
|
||||
import "hypervisor.proto";
|
||||
import "event.proto";
|
||||
|
||||
message Cluster { // `autogenpb:marshal`
|
||||
string uuid = 1; // `autogenpb:unique`
|
||||
string name = 2;
|
||||
repeated string URL = 3;
|
||||
google.protobuf.Timestamp ctime = 4; // when the cluster was created
|
||||
Droplets droplets = 5;
|
||||
Hypervisors hypervisors = 6;
|
||||
Events events = 7;
|
||||
}
|
||||
|
||||
message Clusters { // `autogenpb:marshal`
|
||||
string uuid = 1; // `autogenpb:uuid:57ddd763-75f6-4003-bf0e-8dd0f8a44044`
|
||||
string version = 2; // `autogenpb:version:v0.0.1`
|
||||
repeated Cluster clusters = 3;
|
||||
}
|
98
config.go
98
config.go
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
// functions to import and export the protobuf
|
||||
// data to and from config files
|
||||
|
@ -9,37 +9,14 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"go.wit.com/log"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
func (c *Cluster) ConfigSave() error {
|
||||
name := c.Name
|
||||
if name == "" {
|
||||
name = c.Uuid
|
||||
}
|
||||
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), name+".pb")
|
||||
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
|
||||
}
|
||||
log.Info("ConfigSave()", fullname)
|
||||
data, err := c.Marshal()
|
||||
if err != nil {
|
||||
fmt.Println("cluster Marshal() err:", err)
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(cfgfile, data)
|
||||
return nil
|
||||
}
|
||||
|
||||
// writes out the cluster information it seperate files
|
||||
// to make it humanly possible to hand edit things as needed
|
||||
func (c *OldCluster) ConfigSave() error {
|
||||
func (c *Cluster) ConfigSave() error {
|
||||
// try to backup the current cluster config files
|
||||
if err := backupConfig(); err != nil {
|
||||
return err
|
||||
|
@ -57,12 +34,20 @@ func (c *OldCluster) ConfigSave() error {
|
|||
for _, drop := range dcopy.Droplets {
|
||||
drop.Current = nil
|
||||
}
|
||||
if err := ConfigWriteJSON(dcopy, "droplets.json"); err != nil {
|
||||
fmt.Println("droplets.json write failed")
|
||||
return err
|
||||
}
|
||||
if err := ConfigWriteTEXT(dcopy, "droplets.text"); err != nil {
|
||||
fmt.Println("droplets.json write failed")
|
||||
return err
|
||||
}
|
||||
c.configWriteDroplets()
|
||||
|
||||
if err := ConfigWriteJSON(c.H, "hypervisors.json"); err != nil {
|
||||
fmt.Println("hypervisors.json write failed")
|
||||
return err
|
||||
}
|
||||
if err := ConfigWriteTEXT(c.H, "hypervisors.text"); err != nil {
|
||||
fmt.Println("hypervisors.json write failed")
|
||||
return err
|
||||
|
@ -79,27 +64,27 @@ func (c *OldCluster) ConfigSave() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *OldCluster) ConfigLoad() error {
|
||||
func (c *Cluster) ConfigLoad() error {
|
||||
if c == nil {
|
||||
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
|
||||
}
|
||||
|
||||
if data, err := loadFile("droplets.text"); err == nil {
|
||||
if err = prototext.Unmarshal(data, c.d); err != nil {
|
||||
fmt.Println("broken droplets.text config file")
|
||||
if data, err := loadFile("droplets.json"); err == nil {
|
||||
if err = protojson.Unmarshal(data, c.d); err != nil {
|
||||
fmt.Println("broken droplets.json config file")
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
||||
if data, err := loadFile("hypervisors.text"); err == nil {
|
||||
if err = prototext.Unmarshal(data, c.H); err != nil {
|
||||
fmt.Println("broken hypervisors.text config file")
|
||||
if data, err := loadFile("hypervisors.json"); err == nil {
|
||||
if err = protojson.Unmarshal(data, c.H); err != nil {
|
||||
fmt.Println("broken hypervisors.json config file")
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
log.Warn("ERROR HERE IN Hypervisors")
|
||||
fmt.Println("ERROR HERE IN Hypervisors")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -108,11 +93,8 @@ func (c *OldCluster) ConfigLoad() error {
|
|||
// does it not stay allocated after this function ends?
|
||||
c.e = new(Events)
|
||||
}
|
||||
|
||||
if err := c.e.loadEvents(); err != nil {
|
||||
// ignore events.pb since these should be sent elsewhere
|
||||
log.Warn("Events failed to load, ignoring:", err)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -160,7 +142,7 @@ func loadFile(filename string) ([]byte, error) {
|
|||
|
||||
func ConfigWriteJSON(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)
|
||||
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
|
||||
defer cfgfile.Close()
|
||||
if err != nil {
|
||||
fmt.Println("open config file :", err)
|
||||
|
@ -175,26 +157,9 @@ 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)
|
||||
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
|
||||
defer cfgfile.Close()
|
||||
if err != nil {
|
||||
fmt.Println("open config file :", err)
|
||||
|
@ -209,18 +174,19 @@ func ConfigWriteTEXT(a any, filename string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Clusters) ConfigLoad() error {
|
||||
if c == nil {
|
||||
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
|
||||
}
|
||||
|
||||
if data, err := loadFile("cluster.text"); err == nil {
|
||||
if err = prototext.Unmarshal(data, c); err != nil {
|
||||
fmt.Println("broken cluster.textconfig file")
|
||||
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, 0666)
|
||||
defer cfgfile.Close()
|
||||
if err != nil {
|
||||
fmt.Println("open config file :", err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
// thank chatgpt for this because why. why write this if you can have it
|
||||
// kick this out in 30 seconds
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
syntax = "proto3";
|
||||
package virtpb;
|
||||
package virtbuf;
|
||||
|
||||
import "google/protobuf/duration.proto"; // Import the well-known type for Timestamp
|
||||
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||
|
||||
// global settings for autogenpb `autogenpb:mutex`
|
||||
|
||||
message Droplets { // `autogenpb:marshal` `autogenpb:gui`
|
||||
string uuid = 1; // `autogenpb:uuid:d5d492e2-38d4-476b-86f3-f5abf01f9d6d`
|
||||
string version = 2; // `autogenpb:version:v0.0.1`
|
||||
message Droplets { // `autogenpb:marshal`
|
||||
string uuid = 1; // I guess why not just have this on each file
|
||||
string version = 2; // maybe can be used for protobuf schema change violations
|
||||
repeated Droplet droplets = 3;
|
||||
}
|
||||
|
||||
|
@ -18,22 +18,22 @@ message Droplet { // `autogenpb:
|
|||
int64 cpus = 3; // what's the point of int64 vs int32
|
||||
int64 memory = 4; // in bytes
|
||||
Current current = 5; // what the state and values of the droplet is
|
||||
DropletState startState = 6; // what the state of the droplet is SUPPOSED TO BE ('on' or 'off')
|
||||
string qemuMachine = 7; // the qemu machine type to use "pc-q35-9.0"
|
||||
int64 spicePort = 8; // preferred port to use for spice
|
||||
DropletState start_state = 6; // what the state of the droplet is SUPPOSED TO BE ('on' or 'off')
|
||||
string qemu_machine = 7; // the qemu machine type to use "pc-q35-9.0"
|
||||
int64 spice_port = 8; // preferred port to use for spice
|
||||
|
||||
string preferredHypervisor = 9; // the hypervisor to prefer to run the droplet on
|
||||
string forceHypervisor = 10; // use this hypervisor and this hypervisor only
|
||||
string preferredArch = 11; // the cpu arch to use "x86_64" (should really get this from the disk?)
|
||||
string preferred_hypervisor = 9; // the hypervisor to prefer to run the droplet on
|
||||
string force_hypervisor = 10; // use this hypervisor and this hypervisor only
|
||||
string preferred_arch = 11; // the cpu arch to use "x86_64" (should really get this from the disk?)
|
||||
repeated Network networks = 12; // really just mac addresses. should be unique across cluster
|
||||
repeated Disk disks = 13; // disks to attach
|
||||
|
||||
string localOnly = 14; // this is only defined locally on the hypervisor
|
||||
string customXml = 15; // if needed,
|
||||
string local_only = 14; // this is only defined locally on the hypervisor
|
||||
string custom_xml = 15; // if needed,
|
||||
Archive archive = 16; // what the state of the droplet is SUPPOSED TO BE ('on' or 'off')
|
||||
|
||||
google.protobuf.Timestamp unstable = 39; // the last time we heard anything from this droplet
|
||||
google.protobuf.Duration unstableTimeout = 40; // the last time we heard anything from this droplet
|
||||
google.protobuf.Duration unstable_timeout = 40; // the last time we heard anything from this droplet
|
||||
}
|
||||
|
||||
// volatile data. the current settings and values of things.
|
||||
|
@ -42,12 +42,12 @@ message Droplet { // `autogenpb:
|
|||
message Current {
|
||||
DropletState state = 1; // used to track the current state before taking any action
|
||||
string hypervisor = 2; // the current hypervisor the droplet is running on
|
||||
int64 startAttempts = 3; // how many times a start has been attempted
|
||||
string fullXml = 4; // the full libvirt xml to import
|
||||
google.protobuf.Timestamp lastPoll = 5; // the last time we heard anything from this droplet
|
||||
string imageUrl = 6; // url to the image
|
||||
google.protobuf.Timestamp offSince = 7; // when the droplet was turned off
|
||||
google.protobuf.Timestamp onSince = 8; // when the droplet was turned on
|
||||
int64 start_attempts = 3; // how many times a start has been attempted
|
||||
string full_xml = 4; // the full libvirt xml to import
|
||||
google.protobuf.Timestamp last_poll = 5; // the last time we heard anything from this droplet
|
||||
string image_url = 6; // url to the image
|
||||
google.protobuf.Timestamp off_since = 7; // when the droplet was turned off
|
||||
google.protobuf.Timestamp on_since = 8; // when the droplet was turned on
|
||||
}
|
||||
|
||||
message Archive {
|
||||
|
@ -55,6 +55,7 @@ message Archive {
|
|||
google.protobuf.Timestamp when = 2; // when it was archived
|
||||
}
|
||||
|
||||
// virtual machine state
|
||||
enum DropletState {
|
||||
ON = 0;
|
||||
OFF = 1;
|
||||
|
@ -78,5 +79,5 @@ message Disk {
|
|||
string filename = 1;
|
||||
string filepath = 2;
|
||||
int64 size = 3;
|
||||
string qemuArch = 4; // what arch. example: "x86_64" or "riscv64"
|
||||
string qemu_arch = 4; // what arch. example: "x86_64" or "riscv64"
|
||||
}
|
||||
|
|
39
event.proto
39
event.proto
|
@ -1,16 +1,15 @@
|
|||
syntax = "proto3";
|
||||
package virtpb;
|
||||
package virtbuf;
|
||||
|
||||
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||
import "google/protobuf/any.proto"; // Import the well-known type for Timestamp
|
||||
import "droplet.proto";
|
||||
|
||||
// global settings for autogenpb `autogenpb:no-sort` `autogenpb:mutex`
|
||||
|
||||
message Events { // `autogenpb:marshal` `autogenpb:gui`
|
||||
string uuid = 1; // `autogenpb:uuid:1e3a50c7-5916-4423-b33c-f0b977a7e446`
|
||||
string version = 2; // `autogenpb:version:v0.0.1`
|
||||
int64 eventSize = 3; // max events to store in a single
|
||||
message Events { // `autogenpb:marshal`
|
||||
string uuid = 1; // I guess why not just have this on each file
|
||||
string version = 2; // maybe can be used for protobuf schema change violations
|
||||
int64 event_size = 3; // max events to store in a single
|
||||
repeated Event events = 4; // all the events
|
||||
}
|
||||
|
||||
|
@ -19,29 +18,22 @@ message Events { // `autogenpb:marsh
|
|||
// at least for now in the early days. but maybe forever.
|
||||
// homelab clouds normally don't have many events.
|
||||
// we are talking less than 1 a minute. even 1 an hour is often a lot
|
||||
message Event { // `autogenpb:marshal`
|
||||
enum status {
|
||||
DONE = 0;
|
||||
FAIL = 1;
|
||||
RUNNING = 2;
|
||||
}
|
||||
message Event {
|
||||
int32 id = 1; // `autogenpb:unique` // should be unique across the cluster
|
||||
EventType etype = 2;
|
||||
string dropletName = 3; // name of the droplet
|
||||
string dropletUuid = 4; // uuid of the droplet
|
||||
string droplet = 3; // name of the droplet
|
||||
string droplet_uuid = 4; // uuid of the droplet
|
||||
string hypervisor = 5; // name of the hypervisor
|
||||
string hypervisorUuid = 6; // uuid of the hypervisor
|
||||
string hypervisor_uuid = 6; // uuid of the hypervisor
|
||||
google.protobuf.Timestamp start = 7; // start time
|
||||
google.protobuf.Timestamp end = 8; // end time
|
||||
string fieldName = 9; // the field name that changed
|
||||
string origVal = 10; // original value
|
||||
string newVal = 11; // new value
|
||||
google.protobuf.Any origAny = 12; // anypb format. probably overkill
|
||||
google.protobuf.Any newAny = 13; // anypb format
|
||||
string error = 14; // what went wrong
|
||||
status state = 15; // state of the event
|
||||
Droplet droplet = 16; // droplet
|
||||
string field_name = 9; // the field name that changed
|
||||
string orig_val = 10; // original value
|
||||
string new_val = 11; // new value
|
||||
google.protobuf.Any orig_any = 12; // anypb format. probably overkill
|
||||
google.protobuf.Any new_any = 13; // anypb format
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
ADD = 0;
|
||||
DELETE = 1;
|
||||
|
@ -56,5 +48,4 @@ enum EventType {
|
|||
FAIL = 10; // everything failed
|
||||
CRASH = 11; // droplet hard crashed
|
||||
CHANGE = 12; // droplet or hypervisor config change
|
||||
EDIT = 13; // edit droplet settings
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
syntax = "proto3";
|
||||
package virtbuf;
|
||||
|
||||
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||
import "google/protobuf/any.proto"; // Import the well-known type for Timestamp
|
||||
|
||||
// global settings for autogenpb `autogenpb:no-sort` `autogenpb:no-marshal`
|
||||
|
||||
message WhatsThis {
|
||||
// is it possible to have custom formatting in JSON and TEXT marshal/unmarshal ?
|
||||
WhatInfo humantest = 1;
|
||||
|
||||
google.protobuf.Timestamp end = 2; // end time
|
||||
google.protobuf.Any orig_val = 3; // original value
|
||||
google.protobuf.Any new_val = 4; // new value
|
||||
}
|
||||
|
||||
// this is for exerimenting
|
||||
message WhatInfo {
|
||||
int64 capacity = 1; // Stores the storage capacity in bytes.
|
||||
}
|
10
helpers.go
10
helpers.go
|
@ -1,17 +1,17 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
// functions to import and export the protobuf
|
||||
// data to and from config files
|
||||
|
||||
func InitCluster() *OldCluster {
|
||||
var c *OldCluster
|
||||
c = new(OldCluster)
|
||||
func InitCluster() *Cluster {
|
||||
var c *Cluster
|
||||
c = new(Cluster)
|
||||
c.d = new(Droplets)
|
||||
c.H = new(Hypervisors)
|
||||
c.e = new(Events)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *OldCluster) DropletsAll() *DropletScanner {
|
||||
func (c *Cluster) DropletsAll() *DropletIterator {
|
||||
return c.d.All()
|
||||
}
|
||||
|
|
4
human.go
4
human.go
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
// mostly just functions related to making STDOUT
|
||||
// more readable by us humans
|
||||
|
@ -185,7 +185,7 @@ func (d *Droplet) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, e
|
|||
return t, nil
|
||||
}
|
||||
|
||||
func (c *OldCluster) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||
func (c *Cluster) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||
hostname := r.URL.Query().Get("hostname")
|
||||
d := c.FindDropletByName(hostname)
|
||||
if d == nil {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
syntax = "proto3";
|
||||
package virtpb;
|
||||
package virtbuf;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
// global settings for autogenpb `autogenpb:mutex`
|
||||
|
||||
message Hypervisors { // `autogenpb:marshal` `autogenpb:gui`
|
||||
string uuid = 1; // `autogenpb:uuid:6e3aa8b9-cf98-40f6-af58-3c6ad1edf4d4`
|
||||
string version = 2; // `autogenpb:version:v0.0.1`
|
||||
message Hypervisors { // `autogenpb:marshal`
|
||||
string uuid = 1; // I guess why not just have this on each file
|
||||
string version = 2; // maybe can be used for protobuf schema change violations
|
||||
repeated Hypervisor hypervisors = 3;
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,9 @@ message Hypervisor {
|
|||
string comment = 6;
|
||||
bool autoscan = 7; // to scan or not to scan by virtigo
|
||||
HypervisorArch arch = 8;
|
||||
int64 killcount = 9; // in bytes
|
||||
google.protobuf.Timestamp lastPoll = 10; // the last time we heard anything
|
||||
}
|
||||
|
||||
// think about this more
|
||||
enum HypervisorArch {
|
||||
RISCV64 = 0;
|
||||
X86_64 = 1;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -39,6 +39,22 @@ func CreateSampleHypervisor(hostname string, mem int) *Hypervisor {
|
|||
return h
|
||||
}
|
||||
|
||||
func CreateExperiment(total int) *WhatsThis {
|
||||
var e *WhatsThis
|
||||
e = new(WhatsThis)
|
||||
|
||||
// info := StorageInfo{Capacity: 64}
|
||||
// e.Humantest = &info
|
||||
if e.Humantest == nil {
|
||||
var newInfo WhatInfo
|
||||
newInfo = WhatInfo{Capacity: 64}
|
||||
e.Humantest = &newInfo
|
||||
} else {
|
||||
e.Humantest.Capacity = SetGB(total * 32)
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func CreateSampleEvents(total int) *Events {
|
||||
var e *Events
|
||||
e = new(Events)
|
||||
|
@ -51,7 +67,7 @@ func CreateSampleEvents(total int) *Events {
|
|||
return e
|
||||
}
|
||||
|
||||
func CreateSampleCluster(total int) *OldCluster {
|
||||
func CreateSampleCluster(total int) *Cluster {
|
||||
c := InitCluster()
|
||||
|
||||
for i := 0; i < total; i++ {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package virtpb
|
||||
package virtbuf
|
||||
|
||||
/*
|
||||
// MarshalJSON custom marshals the WhatInfo struct to JSON
|
||||
|
|
Loading…
Reference in New Issue