From ca0d4f423a7892f582eced971a31caab1add9c02 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 22 Oct 2024 04:26:29 -0500 Subject: [PATCH] experiements Signed-off-by: Jeff Carr --- configfile/main.go | 2 +- helpers.go | 9 ++++++++- sampleData.go | 8 ++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/configfile/main.go b/configfile/main.go index ff3e4c0..eba2dd8 100644 --- a/configfile/main.go +++ b/configfile/main.go @@ -34,7 +34,7 @@ func main() { // show the hypervisors to STDOUT for _, h := range aCluster.Hypervisors { - log.Println("\thypervisor =", h.Hostname, h.Memory) + log.Println("\thypervisor =", h.Hostname, h.GetMemoryPrintable()) } } diff --git a/helpers.go b/helpers.go index 81b5fb2..4148a23 100644 --- a/helpers.go +++ b/helpers.go @@ -1,5 +1,12 @@ package virtbuf -func (x *Hypervisor) SetMemory(gb int) { +import "fmt" + +func (x *Hypervisor) SetMemoryGB(gb int) { x.Memory = int64(gb * 1024 * 1024 * 1024) } + +func (x *Hypervisor) GetMemoryPrintable() string { + i := x.Memory / (1024 * 1024 * 1024) + return fmt.Sprintf("%d GB", i) +} diff --git a/sampleData.go b/sampleData.go index 806e1f9..03af6ab 100644 --- a/sampleData.go +++ b/sampleData.go @@ -31,11 +31,11 @@ func CreateSampleHypervisor(hostname string, mem int) *Hypervisor { h := &Hypervisor{ Uuid: id.String(), Hostname: hostname, - Cpus: 16, - Memory: 256, + Cpus: 16, + Memory: 256, Comment: "this is a fake hypervisor", } - h.SetMemory(mem * 32) + h.SetMemoryGB(mem * 32) return h } @@ -54,7 +54,7 @@ func CreateSampleCluster(total int) *Cluster { for i := 0; i < 3; i++ { hostname := fmt.Sprintf("farm%d", i) - h := CreateSampleHypervisor(hostname, i + 1) + h := CreateSampleHypervisor(hostname, i+1) h.Comment = fmt.Sprintf("Sample hypervisor %d", i) c.Hypervisors = append(c.Hypervisors, h)