summaryrefslogtreecommitdiff
path: root/helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'helpers.go')
-rw-r--r--helpers.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/helpers.go b/helpers.go
index 00ca6cf..8f602ee 100644
--- a/helpers.go
+++ b/helpers.go
@@ -3,6 +3,7 @@ package virtbuf
import (
"fmt"
+ "github.com/google/uuid"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/encoding/prototext"
)
@@ -34,3 +35,37 @@ func (c *Cluster) UnmarshalJSON(data []byte) error {
func (c *Cluster) FormatTEXT() string {
return prototext.Format(c)
}
+
+func (c *Cluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
+ // Generate a new UUID
+ id := uuid.New()
+ h := &Hypervisor{
+ Uuid: id.String(),
+ Hostname: hostname,
+ Cpus: 16,
+ Memory: 256,
+ Comment: "this is a fake hypervisor",
+ }
+ h.Cpus = int64(cpus)
+ h.SetMemoryGB(mem * 32)
+ c.Hypervisors = append(c.Hypervisors, h)
+ return h
+}
+
+func (c *Cluster) FindDroplet(name string) *Droplet {
+ for _, d := range c.Droplets {
+ if d.Hostname == name {
+ return d
+ }
+ }
+ return nil
+}
+
+func (c *Cluster) FindHypervisor(name string) *Hypervisor {
+ for _, h := range c.Hypervisors {
+ if h.Hostname == name {
+ return h
+ }
+ }
+ return nil
+}