virtigo/doGui.go

177 lines
3.6 KiB
Go
Raw Normal View History

// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// An app to submit patches for the 30 GO GUI repos
import (
"os"
"time"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
2025-02-22 17:45:50 -06:00
"go.wit.com/lib/protobuf/virtpb"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
)
func debug() {
for {
time.Sleep(90 * time.Second)
log.Info("TODO: zookeeper scan here. repo count =")
}
}
func doGui() {
me.myGui = gui.New()
me.myGui.InitEmbed(resources)
me.myGui.Default()
mainWindow := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
mainWindow.Make()
mainWindow.Show()
mainWindow.Custom = func() {
log.Warn("Main window close")
os.Exit(0)
}
drawWindow(mainWindow)
// sits here forever
debug()
}
func drawWindow(win *gadgets.BasicWindow) {
box := win.Box()
vbox := box.NewVerticalBox("BOX2")
group1 := vbox.NewGroup("Zookeeper Settings")
grid := group1.NewGrid("buildOptions", 0, 0)
2025-02-23 01:36:42 -06:00
var hyperWin *GenericWindow
2025-02-23 00:51:28 -06:00
grid.NewButton("hypervisors", func() {
if hyperWin != nil {
hyperWin.Toggle()
return
}
hyperWin = makeHypervisorsWindow(me.cluster.H)
})
2025-02-23 01:36:42 -06:00
var testWin *GenericWindow
2025-02-23 00:51:28 -06:00
grid.NewButton("all defined droplets", func() {
if testWin != nil {
testWin.Toggle()
return
}
d := me.cluster.GetDropletsPB()
testWin = makeDropletsWindow(d)
})
grid.NewButton("Running droplets", func() {
d := me.cluster.GetDropletsPB()
var found *virtpb.Droplets
found = virtpb.NewDroplets()
all := d.All()
for all.Scan() {
vm := all.Next()
if vm.Current.State != virtpb.DropletState_ON {
continue
}
found.Append(vm)
}
makeDropletsWindow(found)
})
/*
2025-02-23 01:36:42 -06:00
var test2 *GenericWindow
grid.NewButton("test2", func() {
if test2 != nil {
test2.Toggle()
return
}
test2 = makeDropletsWindow(me.machines)
})
*/
}
func findVersion(m *zoopb.Machine, pkgname string) string {
zood := m.Packages.FindByName(pkgname)
if zood == nil {
return "n/a"
}
return zood.Version
}
2025-02-23 01:36:42 -06:00
func makeDropletsWindow(pb *virtpb.Droplets) *GenericWindow {
win := NewGenericWindow("Droplets registered with Virtigo", "Buttons of things")
grid := win.Group.RawGrid()
grid.NewButton("Create", func() {
log.Info("todo: open create window here")
2025-02-23 00:51:28 -06:00
})
2025-02-23 01:36:42 -06:00
grid.NewButton("Show All", func() {
log.Info("todo")
})
2025-02-23 01:36:42 -06:00
tbox := win.Bottom.Box()
t := pb.NewTable("test 2")
t.SetParent(tbox)
t.AddHostname()
t.AddMemory()
t.AddCpus()
t.AddStringFunc("State", func(d *virtpb.Droplet) string {
if d.Current.State == virtpb.DropletState_ON {
return "ON"
}
2025-02-23 01:36:42 -06:00
if d.Current.State == virtpb.DropletState_OFF {
return "OFF"
}
return "UNKNOWN"
})
/*
t.AddStringFunc("zood", func(m *zoopb.Machine) string {
return findVersion(m, "zood")
})
t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
return m.Laststamp.AsTime()
})
*/
t.ShowTable()
return win
}
2025-02-23 00:51:28 -06:00
2025-02-23 01:36:42 -06:00
func makeHypervisorsWindow(pb *virtpb.Hypervisors) *GenericWindow {
win := NewGenericWindow("Hypervisors registered with Virtigo", "Buttons of things")
grid := win.Group.RawGrid()
2025-02-23 00:51:28 -06:00
grid.NewButton("List", func() {
log.Info("list...")
})
2025-02-23 01:36:42 -06:00
tbox := win.Bottom.Box() // a vertical box (like a stack of books)
2025-02-23 00:51:28 -06:00
t := pb.NewTable("test 2")
t.SetParent(tbox)
t.AddHostname()
t.AddMemory()
t.AddCpus()
/*
t.AddStringFunc("State", func(d *virtpb.Hypervisor) string {
if d.Current.State == virtpb.HypervisorState_ON {
return "ON"
}
return "UNKNOWN"
})
*/
/*
t.AddStringFunc("zood", func(m *zoopb.Machine) string {
return findVersion(m, "zood")
})
t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
return m.Laststamp.AsTime()
})
*/
t.ShowTable()
return win
}