summaryrefslogtreecommitdiff
path: root/change.go
diff options
context:
space:
mode:
Diffstat (limited to 'change.go')
-rw-r--r--change.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/change.go b/change.go
index dc77b0c..04c5b20 100644
--- a/change.go
+++ b/change.go
@@ -49,6 +49,14 @@ func convertToString(x any) string {
return fmt.Sprintf("%d", x.(int))
case uint:
return fmt.Sprintf("%d", x.(uint))
+ case *DropletState:
+ var s *DropletState
+ s = x.(*DropletState)
+ return s.String()
+ case DropletState:
+ var s DropletState
+ s = x.(DropletState)
+ return s.String()
case bool:
if x.(bool) {
return "true"
@@ -128,6 +136,34 @@ func (d *Droplet) SetCpus(b int64) {
log.Info("Set the number of cpus for the droplet", b)
}
+// update the droplet memory
+func (d *Droplet) SetState(newState DropletState) {
+ if d.Current == nil {
+ d.Current = new(Current)
+ }
+ if d.Current.State == newState {
+ // nothing has changed
+ return
+ }
+ switch newState {
+ case DropletState_ON:
+ d.Current.OnSince = timestamppb.New(time.Now())
+ d.Current.OffSince = nil
+ case DropletState_OFF:
+ d.Current.OffSince = timestamppb.New(time.Now())
+ d.Current.OnSince = nil
+ default:
+ // zero on OnSince to indicate something hickup'd?
+ // not sure if this should be done here. probably trust qemu dom0 instead
+ // but I can't do that right now so for now this will work
+ d.Current.OnSince = timestamppb.New(time.Now())
+ d.Current.OffSince = timestamppb.New(time.Now())
+ }
+ d.Current.State = newState
+ d.NewChangeEvent("STATE", d.Current.State, newState)
+ log.Info("Droplet", d.Hostname, "changed state from", d.Current.State, "to", newState)
+}
+
// records an event that the droplet changed state (aka turned on, turned off, etc)
func (c *NewCluster) ChangeDropletState(d *Droplet, newState DropletState) error {
if c == nil {