summaryrefslogtreecommitdiff
path: root/helpers.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-22 16:33:36 -0500
committerJeff Carr <[email protected]>2024-10-22 16:33:36 -0500
commitf2040886198b8f4a25ce1a9f65585097b299f9fa (patch)
treeab7bd4f70c521c97ba766c96a31af5284baf76f1 /helpers.go
parent8f1544654b1d5534d9d27437237eca8d8e6dfa96 (diff)
attempt at human readable message in JSON output
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'helpers.go')
-rw-r--r--helpers.go71
1 files changed, 55 insertions, 16 deletions
diff --git a/helpers.go b/helpers.go
index 8f602ee..4ffd13c 100644
--- a/helpers.go
+++ b/helpers.go
@@ -8,6 +8,16 @@ import (
"google.golang.org/protobuf/encoding/prototext"
)
+// can the json protobuf output use a string and have a type handler
+// to convert it back to int64?
+func SetGB(gb int) int64 {
+ return int64(gb * 1024 * 1024 * 1024)
+}
+
+func SetMB(mb int) int64 {
+ return int64(mb * 1024 * 1024)
+}
+
func (x *Hypervisor) SetMemoryGB(gb int) {
x.Memory = int64(gb * 1024 * 1024 * 1024)
}
@@ -36,22 +46,6 @@ 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 {
@@ -69,3 +63,48 @@ func (c *Cluster) FindHypervisor(name string) *Hypervisor {
}
return nil
}
+
+func (c *Cluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
+ h := c.FindHypervisor(hostname)
+ if h != nil {
+ return h
+ }
+ // Generate a new UUID
+ id := uuid.New()
+ h = &Hypervisor{
+ Uuid: id.String(),
+ Hostname: hostname,
+ Cpus: int64(cpus),
+ Comment: "this is a fake hypervisor",
+ }
+ if cpus < 0 {
+ h.Cpus = 1
+ }
+ h.SetMemoryGB(mem * 32)
+ c.Hypervisors = append(c.Hypervisors, h)
+ return h
+}
+
+func (c *Cluster) AddDroplet(hostname string, cpus int, mem int) *Droplet {
+ d := c.FindDroplet(hostname)
+ if d != nil {
+ return d
+ }
+
+ // Generate a new UUID
+ id := uuid.New()
+ d = &Droplet{
+ Uuid: id.String(),
+ Hostname: hostname,
+ Cpus: int64(cpus),
+ }
+
+ if cpus < 0 {
+ d.Cpus = 1
+ }
+ d.Memory = SetGB(mem * 32)
+ d.Testsi.Capacity = SetGB(mem * 32)
+ // d.Testsi = StorageInfo{Capacity: 64}
+ c.Droplets = append(c.Droplets, d)
+ return d
+}