import worked

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-01 08:31:25 -05:00
parent 36e69dd84c
commit f36c19f04f
1 changed files with 27 additions and 9 deletions

36
add.go
View File

@ -1,6 +1,7 @@
package virtbuf package virtbuf
import ( import (
"errors"
"fmt" "fmt"
"time" "time"
@ -8,6 +9,32 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func (c *NewCluster) InitDroplet(hostname string) (*Droplet, error) {
var d *Droplet
d = new(Droplet)
d.Current = new(Current)
d = c.FindDropletByName(hostname)
if d != nil {
return d, errors.New("duplicate hostname: " + hostname)
}
d.Hostname = hostname
// d.Uuid = uuid.New() // not appropriate here
// set some defaults
d.StartState = DropletState_OFF
d.Current.State = DropletState_UNKNOWN
c.appendDroplet(d)
return d, nil
}
func (c *NewCluster) appendDroplet(d *Droplet) {
c.Lock()
defer c.Unlock()
c.d.Droplets = append(c.d.Droplets, d)
}
// can the json protobuf output use a string and have a type handler // can the json protobuf output use a string and have a type handler
// to convert it back to int64? // to convert it back to int64?
func SetGB(gb int) int64 { func SetGB(gb int) int64 {
@ -22,15 +49,6 @@ func (x *Hypervisor) SetMemoryGB(gb int) {
x.Memory = int64(gb * 1024 * 1024 * 1024) x.Memory = int64(gb * 1024 * 1024 * 1024)
} }
func (all *Droplets) oldFindDroplet(name string) *Droplet {
for _, d := range all.Droplets {
if d.Hostname == name {
return d
}
}
return nil
}
func (c *NewCluster) FindDropletByName(name string) *Droplet { func (c *NewCluster) FindDropletByName(name string) *Droplet {
loop := c.DropletsAll() // get the list of droplets loop := c.DropletsAll() // get the list of droplets
for loop.Scan() { for loop.Scan() {