check for changes and save the config files
This commit is contained in:
parent
c8a50fbb18
commit
4faca63da8
65
doDroplet.go
65
doDroplet.go
|
@ -109,7 +109,72 @@ func doEvent(e *virtpb.Event) *virtpb.Event {
|
|||
if err != nil {
|
||||
result.Error = fmt.Sprintf("%v", err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
if e.Etype == virtpb.EventType_EDIT {
|
||||
log.Println("edit event", e.DropletUuid)
|
||||
result.State = virtpb.Event_DONE
|
||||
if e.Droplet != nil {
|
||||
return updateDroplet(e.Droplet)
|
||||
}
|
||||
log.Println("unknown edit event")
|
||||
result.State = virtpb.Event_FAIL
|
||||
return result
|
||||
}
|
||||
|
||||
log.Println("unknown event", e)
|
||||
result.Etype = e.Etype
|
||||
result.State = virtpb.Event_FAIL
|
||||
return result
|
||||
}
|
||||
|
||||
func updateDroplet(newd *virtpb.Droplet) *virtpb.Event {
|
||||
var changed bool = false
|
||||
result := new(virtpb.Event)
|
||||
|
||||
if newd == nil {
|
||||
result.Error = "updateDroplet() d == nil"
|
||||
result.State = virtpb.Event_FAIL
|
||||
return result
|
||||
}
|
||||
|
||||
d := me.cluster.FindDropletByUuid(newd.Uuid)
|
||||
if d == nil {
|
||||
result.Error = "updateDroplet() could not find uuid"
|
||||
result.State = virtpb.Event_FAIL
|
||||
return result
|
||||
}
|
||||
log.Println("found droplet to update:", newd.Uuid, newd.Hostname, newd.Cpus, newd.Memory)
|
||||
|
||||
if d.Hostname != newd.Hostname && newd.Hostname != "" {
|
||||
d.Hostname = newd.Hostname
|
||||
changed = true
|
||||
}
|
||||
|
||||
if d.Cpus != newd.Cpus && newd.Cpus > 0 {
|
||||
d.Cpus = newd.Cpus
|
||||
changed = true
|
||||
}
|
||||
|
||||
// arbitrary check. don't make vm's with less than 64 MB of RAM
|
||||
// big enough most things will load with some stdout
|
||||
if d.Memory != newd.Memory && newd.Memory > (64*1024*1024) {
|
||||
d.Memory = newd.Memory
|
||||
changed = true
|
||||
}
|
||||
|
||||
if changed {
|
||||
if err := me.cluster.ConfigSave(); err != nil {
|
||||
log.Info("configsave error", err)
|
||||
result.Error = fmt.Sprintf("%v", err)
|
||||
result.State = virtpb.Event_FAIL
|
||||
return result
|
||||
}
|
||||
} else {
|
||||
log.Println("nothing changed in", newd.Uuid, newd.Hostname)
|
||||
}
|
||||
|
||||
result.State = virtpb.Event_DONE
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue