diff options
| author | Jeff Carr <[email protected]> | 2024-11-01 00:41:34 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-01 00:41:34 -0500 |
| commit | 706dbbc53328dbfe74f70aee38765551d6a836d0 (patch) | |
| tree | eb8655efdf8d6423546349686c54fc03c806e105 /change.go | |
| parent | b6f5594fe6b92b5b3a76e22ba3823c9ac8e00cd2 (diff) | |
pretty output for humans d.SprintHeader()
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'change.go')
| -rw-r--r-- | change.go | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -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 { |
