virtigo/change.go

65 lines
1.3 KiB
Go

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)
}