From 8f1544654b1d5534d9d27437237eca8d8e6dfa96 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 22 Oct 2024 15:58:28 -0500 Subject: [PATCH] FindHypervisor() and FindDroplet() Signed-off-by: Jeff Carr --- helpers.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 +}