summaryrefslogtreecommitdiff
path: root/change.go
blob: f4e7d796123ee9a7902d197bcb5d4cda44672f22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)
}