diff options
| author | Jeff Carr <[email protected]> | 2024-11-01 08:31:25 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-01 08:31:25 -0500 |
| commit | f36c19f04ff4eb2cf0ad23ff557903f952ca9719 (patch) | |
| tree | 47ff9da47b1c9e7635b2ca126c105241c8d118a3 | |
| parent | 36e69dd84cd0311c12415b6ae430478f43e64c3b (diff) | |
import worked
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | add.go | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -1,6 +1,7 @@ package virtbuf import ( + "errors" "fmt" "time" @@ -8,6 +9,32 @@ import ( "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 // to convert it back to int64? func SetGB(gb int) int64 { @@ -22,15 +49,6 @@ func (x *Hypervisor) SetMemoryGB(gb int) { 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 { loop := c.DropletsAll() // get the list of droplets for loop.Scan() { |
