2024-10-31 13:07:24 -05:00
|
|
|
package virtbuf
|
|
|
|
|
|
|
|
import (
|
|
|
|
sync "sync"
|
|
|
|
|
|
|
|
durationpb "google.golang.org/protobuf/types/known/durationpb"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
)
|
|
|
|
|
2024-11-07 05:04:11 -06:00
|
|
|
type Cluster struct {
|
2024-10-31 13:07:24 -05:00
|
|
|
sync.RWMutex
|
|
|
|
|
|
|
|
Dirs []string
|
|
|
|
d *Droplets
|
2024-10-31 13:21:10 -05:00
|
|
|
H *Hypervisors
|
2024-10-31 13:07:24 -05:00
|
|
|
e *Events
|
|
|
|
Unstable *timestamppb.Timestamp
|
|
|
|
UnstableTimeout *durationpb.Duration
|
|
|
|
}
|
2024-11-16 05:22:11 -06:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|