37 lines
745 B
Go
37 lines
745 B
Go
package virtbuf
|
|
|
|
import (
|
|
sync "sync"
|
|
|
|
durationpb "google.golang.org/protobuf/types/known/durationpb"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
type Cluster struct {
|
|
sync.RWMutex
|
|
|
|
Dirs []string
|
|
d *Droplets
|
|
H *Hypervisors
|
|
e *Events
|
|
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
|
|
}
|