things for create. might be duplicates
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
74da63276e
commit
81cbb6e9d7
17
add.go
17
add.go
|
@ -1,7 +1,6 @@
|
|||
package virtbuf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
@ -9,6 +8,7 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
/*
|
||||
func (c *Cluster) InitDroplet(hostname string) (*Droplet, error) {
|
||||
var d *Droplet
|
||||
d = new(Droplet)
|
||||
|
@ -34,6 +34,7 @@ func (c *Cluster) appendDroplet(d *Droplet) {
|
|||
|
||||
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?
|
||||
|
@ -94,8 +95,18 @@ func (c *Cluster) AddEvent(e *Event) {
|
|||
c.e.Events = append(c.e.Events, e)
|
||||
}
|
||||
|
||||
func (c *Cluster) AddDroplet(d *Droplet) {
|
||||
c.d.Droplets = append(c.d.Droplets, d)
|
||||
// creates a new droplet with default values
|
||||
func NewDefaultDroplet(hostname string) *Droplet {
|
||||
id := uuid.New() // Generate a new UUID
|
||||
d := &Droplet{
|
||||
Uuid: id.String(),
|
||||
Hostname: hostname,
|
||||
Cpus: int64(2),
|
||||
}
|
||||
d.Memory = SetGB(2)
|
||||
d.StartState = DropletState_OFF
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func (c *Cluster) AddDropletSimple(uuid string, hostname string, cpus int, mem int) *Droplet {
|
||||
|
|
17
cluster.go
17
cluster.go
|
@ -17,3 +17,20 @@ type Cluster struct {
|
|||
Unstable *timestamppb.Timestamp
|
||||
UnstableTimeout *durationpb.Duration
|
||||
}
|
||||
|
||||
// adds a new droplet. enforce unique hostnames
|
||||
func (c *Cluster) AddDroplet(newd *Droplet) bool {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
for _, d := range c.d.Droplets {
|
||||
if newd.Hostname == d.Hostname {
|
||||
// boo. that one is already here
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// everything is ok, this hostname is new
|
||||
c.d.Droplets = append(c.d.Droplets, newd)
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue