summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--add.go17
-rw-r--r--cluster.go17
2 files changed, 31 insertions, 3 deletions
diff --git a/add.go b/add.go
index f0eab89..d77077b 100644
--- a/add.go
+++ b/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 {
diff --git a/cluster.go b/cluster.go
index 97da63a..a2c2391 100644
--- a/cluster.go
+++ b/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
+}