expose cluster.Hypervisors

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-31 13:21:10 -05:00
parent e8834578fb
commit 9ad173a845
5 changed files with 9 additions and 13 deletions

4
add.go
View File

@ -48,7 +48,7 @@ func (c *NewCluster) FindDropletByName(name string) *Droplet {
} }
func (c *NewCluster) FindHypervisorByName(name string) *Hypervisor { func (c *NewCluster) FindHypervisorByName(name string) *Hypervisor {
for _, h := range c.h.Hypervisors { for _, h := range c.H.Hypervisors {
if h.Hostname == name { if h.Hostname == name {
return h return h
} }
@ -73,7 +73,7 @@ func (c *NewCluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervis
h.Cpus = 1 h.Cpus = 1
} }
h.SetMemoryGB(mem * 32) h.SetMemoryGB(mem * 32)
c.h.Hypervisors = append(c.h.Hypervisors, h) c.H.Hypervisors = append(c.H.Hypervisors, h)
return h return h
} }

View File

@ -42,11 +42,11 @@ func (c *NewCluster) ConfigSave() error {
return err return err
} }
if err := ConfigWriteJSON(c.h, "hypervisors.json"); err != nil { if err := ConfigWriteJSON(c.H, "hypervisors.json"); err != nil {
fmt.Println("hypervisors.json write failed") fmt.Println("hypervisors.json write failed")
return err return err
} }
if err := ConfigWriteTEXT(c.h, "hypervisors.text"); err != nil { if err := ConfigWriteTEXT(c.H, "hypervisors.text"); err != nil {
fmt.Println("hypervisors.json write failed") fmt.Println("hypervisors.json write failed")
return err return err
} }
@ -77,7 +77,7 @@ func (c *NewCluster) ConfigLoad() error {
} }
if data, err := loadFile("hypervisors.json"); err == nil { if data, err := loadFile("hypervisors.json"); err == nil {
if err = protojson.Unmarshal(data, c.h); err != nil { if err = protojson.Unmarshal(data, c.H); err != nil {
fmt.Println("broken hypervisors.json config file") fmt.Println("broken hypervisors.json config file")
return err return err
} }

View File

@ -13,7 +13,7 @@ func InitCluster() *NewCluster {
var c *NewCluster var c *NewCluster
c = new(NewCluster) c = new(NewCluster)
c.d = new(Droplets) c.d = new(Droplets)
c.h = new(Hypervisors) c.H = new(Hypervisors)
c.e = new(Events) c.e = new(Events)
return c return c
} }

View File

@ -12,7 +12,7 @@ type NewCluster struct {
Dirs []string Dirs []string
d *Droplets d *Droplets
h *Hypervisors H *Hypervisors
e *Events e *Events
Unstable *timestamppb.Timestamp Unstable *timestamppb.Timestamp
UnstableTimeout *durationpb.Duration UnstableTimeout *durationpb.Duration

View File

@ -68,11 +68,7 @@ func CreateSampleEvents(total int) *Events {
} }
func CreateSampleCluster(total int) *NewCluster { func CreateSampleCluster(total int) *NewCluster {
var c *NewCluster c := InitCluster()
c = new(NewCluster)
c.d = new(Droplets)
c.h = new(Hypervisors)
c.e = new(Events)
for i := 0; i < total; i++ { for i := 0; i < total; i++ {
hostname := fmt.Sprintf("bmath%d.wit.com", i) hostname := fmt.Sprintf("bmath%d.wit.com", i)
@ -91,7 +87,7 @@ func CreateSampleCluster(total int) *NewCluster {
h := CreateSampleHypervisor(hostname, i+1) h := CreateSampleHypervisor(hostname, i+1)
h.Comment = fmt.Sprintf("Sample hypervisor %d", i) h.Comment = fmt.Sprintf("Sample hypervisor %d", i)
c.h.Hypervisors = append(c.h.Hypervisors, h) c.H.Hypervisors = append(c.H.Hypervisors, h)
} }
return c return c