working on making events

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-24 21:39:07 -05:00
parent fea819956f
commit 1effa9c745
3 changed files with 65 additions and 2 deletions

View File

@ -10,7 +10,7 @@ all:
./virtigo --help
xml-add:
./virtigo --add-xml /tmp/xml/*.xml
./virtigo --libvirt *.xml
start-all-droplets:
curl --silent http://localhost:8080/start?start=git.wit.org

View File

@ -16,7 +16,6 @@ type args struct {
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
Daemon bool `arg:"--daemon" help:"run in daemon mode"`
}
// Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`

64
change.go Normal file
View File

@ -0,0 +1,64 @@
package main
import (
// "reflect"
"errors"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/wrapperspb"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log"
)
func convert(x any) *anypb.Any {
switch v := x.(type) {
case int64:
var a *anypb.Any
a, _ = anypb.New(wrapperspb.Int64(x.(int64)))
return a
case string:
var a *anypb.Any
a, _ = anypb.New(wrapperspb.String(x.(string)))
return a
case int:
var a *anypb.Any
a, _ = anypb.New(wrapperspb.Int64(x.(int64)))
return a
case bool:
var a *anypb.Any
a, _ = anypb.New(wrapperspb.Bool(x.(bool)))
return a
default:
log.Error(errors.New("Set() unknown type"), "v =", v, "x =", x)
return nil
}
return nil
}
// Wrapping the int into a protobuf message
func NewEvent(origval any, newval any) *pb.Event {
var e *pb.Event
e = new(pb.Event)
e.OrigVal = convert(origval)
e.NewVal = convert(newval)
return e
}
// update the droplet memory
func (d *DropletT) SetMemory(b int64) *pb.Event {
log.Info("Set the amount of memory for the droplet", b)
if d.pb.Memory == b {
return nil
}
var e *pb.Event
e = NewEvent(d.pb.Memory, b)
return e
}
// update the droplet memory
func (d *DropletT) SetCpus(b int64) {
log.Info("Set the number of cpus for the droplet", b)
}