summaryrefslogtreecommitdiff
path: root/helpers.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-22 15:58:28 -0500
committerJeff Carr <[email protected]>2024-10-22 15:58:28 -0500
commit8f1544654b1d5534d9d27437237eca8d8e6dfa96 (patch)
tree4d785d92c2b24083be30e77027053960dfa1a72c /helpers.go
parent4cdb13d89c5b932384de9f8fa542a4cbd852bca7 (diff)
FindHypervisor() and FindDroplet()
Signed-off-by: Jeff Carr <[email protected]>
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
+}