func for droplet migration and change state
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bf46163a87
commit
ae69eafee5
62
change.go
62
change.go
|
@ -129,3 +129,65 @@ func (d *Droplet) SetMemory(b int64) *Event {
|
||||||
func (d *Droplet) SetCpus(b int64) {
|
func (d *Droplet) SetCpus(b int64) {
|
||||||
log.Info("Set the number of cpus for the droplet", b)
|
log.Info("Set the number of cpus for the droplet", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// records an event that the droplet changed state (aka turned on, turned off, etc)
|
||||||
|
func (c *Cluster) ChangeDropletState(d *Droplet, newState DropletState) error {
|
||||||
|
if c == nil {
|
||||||
|
return errors.New("cluster is nil")
|
||||||
|
}
|
||||||
|
if d == nil {
|
||||||
|
return errors.New("droplet is nil")
|
||||||
|
}
|
||||||
|
if d.CurrentState == newState {
|
||||||
|
// droplet status didn't change
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var e *Event
|
||||||
|
e = new(Event)
|
||||||
|
|
||||||
|
e.Droplet = d.Hostname
|
||||||
|
e.OrigVal = convertToString(d.CurrentState)
|
||||||
|
e.NewVal = convertToString(newState)
|
||||||
|
e.FieldName = "status"
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
e.Start = timestamppb.New(now)
|
||||||
|
|
||||||
|
c.Events = append(c.Events, e)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// records an event that the droplet migrated to another hypervisor
|
||||||
|
func (c *Cluster) DropletMoved(d *Droplet, newh *Hypervisor) error {
|
||||||
|
if c == nil {
|
||||||
|
return errors.New("cluster is nil")
|
||||||
|
}
|
||||||
|
if d == nil {
|
||||||
|
return errors.New("droplet is nil")
|
||||||
|
}
|
||||||
|
if newh == nil {
|
||||||
|
return errors.New("hypervisor is nil")
|
||||||
|
}
|
||||||
|
if d.CurrentHypervisor == newh.Hostname {
|
||||||
|
// droplet didn't move
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// make a change event
|
||||||
|
var e *Event
|
||||||
|
e = new(Event)
|
||||||
|
|
||||||
|
e.Droplet = d.Hostname
|
||||||
|
e.OrigVal = d.CurrentHypervisor
|
||||||
|
e.NewVal = newh.Hostname
|
||||||
|
e.FieldName = "droplet migrate"
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
e.Start = timestamppb.New(now)
|
||||||
|
|
||||||
|
c.Events = append(c.Events, e)
|
||||||
|
|
||||||
|
// update the droplet record
|
||||||
|
d.CurrentHypervisor = newh.Hostname
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue