summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-22 15:23:04 -0600
committerJeff Carr <[email protected]>2025-02-22 15:23:04 -0600
commit9f9a52312e6e9538e7ec4c0eefbe46aace352fd3 (patch)
tree7f22f8040ab9b133b83ca08a78902ee9aac89b5c
parent6e111ba862d3f9b9179e9ac71468b6c4f25cbf20 (diff)
first gui for virtigo! easy with proto pb tables
-rw-r--r--Makefile1
-rw-r--r--doGui.go117
-rw-r--r--main.go18
-rw-r--r--structs.go23
-rw-r--r--windowGeneric.go92
5 files changed, 231 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index efad4a2..ff46e4b 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE=
all: build
./virtigo --version
+ ./virtigo --gui gocui
@echo build worked
build: goimports vet
diff --git a/doGui.go b/doGui.go
new file mode 100644
index 0000000..623c53e
--- /dev/null
+++ b/doGui.go
@@ -0,0 +1,117 @@
+// 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"
+ "go.wit.com/lib/protobuf/virtbuf"
+ "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)
+
+ var testWin *genericWindow
+ grid.NewButton("machine list", func() {
+ if testWin != nil {
+ testWin.Toggle()
+ return
+ }
+ d := me.cluster.GetDropletsPB()
+ testWin = makeDropletsWindow(d)
+ })
+
+ /*
+ 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
+}
+
+func makeDropletsWindow(pb *virtbuf.Droplets) *genericWindow {
+ win := initGenericWindow("Droplets registered with Virtigo", "Buttons of things")
+ grid := win.group.RawGrid()
+ grid.NewButton("List", func() {
+ log.Info("list...")
+ })
+ grid.NewButton("more", func() {
+ log.Info("?")
+ })
+ grid.NextRow()
+ grid.NewButton("smore", func() {
+ log.Info("smore")
+ })
+
+ tbox := win.win.Box().Vertical() // a vertical box (like a stack of books)
+ t := pb.NewTable("test 2")
+ t.SetParent(tbox)
+ t.AddHostname()
+ t.AddMemory()
+ t.AddCpus()
+ /*
+ t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
+ return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
+ })
+ 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
+}
diff --git a/main.go b/main.go
index e40c6e8..ce6d446 100644
--- a/main.go
+++ b/main.go
@@ -10,6 +10,7 @@ import (
"time"
"go.wit.com/dev/alexflint/arg"
+ "go.wit.com/gui"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/lib/virtigolib"
"go.wit.com/log"
@@ -21,12 +22,8 @@ var Version string
var resources embed.FS
func main() {
- if os.Getenv("VIRTIGO_HOME") == "" {
- homeDir, _ := os.UserHomeDir()
- fullpath := filepath.Join(homeDir, ".config/virtigo")
- os.Setenv("VIRTIGO_HOME", fullpath)
- }
var pp *arg.Parser
+ gui.InitArg()
pp = arg.MustParse(&argv)
if pp == nil {
@@ -34,9 +31,11 @@ func main() {
os.Exit(0)
}
- // if argv.Daemon {
- // log.DaemonMode(true)
- // }
+ if os.Getenv("VIRTIGO_HOME") == "" {
+ homeDir, _ := os.UserHomeDir()
+ fullpath := filepath.Join(homeDir, ".config/virtigo")
+ os.Setenv("VIRTIGO_HOME", fullpath)
+ }
// set defaults
me.unstable = time.Now() // initialize the grid as unstable
@@ -176,5 +175,6 @@ func main() {
}
// sit here
- startHTTP()
+ go startHTTP()
+ doGui()
}
diff --git a/structs.go b/structs.go
index 606eb6c..f3e53b7 100644
--- a/structs.go
+++ b/structs.go
@@ -3,6 +3,7 @@ package main
import (
"time"
+ "go.wit.com/gui"
pb "go.wit.com/lib/protobuf/virtbuf"
)
@@ -20,19 +21,19 @@ func (b *virtigoT) Enable() {
// this app's variables
type virtigoT struct {
- cluster *pb.Cluster // basic cluster settings
- // newc *pb.Cluster // basic cluster settings
+ cluster *pb.Cluster // basic cluster settings
+ myGui *gui.Node // the gui toolkit handle
e *pb.Events // virtbuf events
hmap map[*pb.Hypervisor]*HyperT // map to the local struct
- names []string
- hypers []*HyperT
- killcount int
- unstable time.Time // the last time the cluster was incorrect
- changed bool
- hyperPollDelay time.Duration // how often to poll the hypervisors
- unstableTimeout time.Duration // how long a droplet can be unstable until it's declared dead
- clusterStableDuration time.Duration // how long the cluster must be stable before new droplets can be started
- missingDropletTimeout time.Duration // how long a droplet can be missing for
+ names []string // ?
+ hypers []*HyperT // notsure
+ killcount int // how many times virtigo-d has had to been killed
+ unstable time.Time // the last time the cluster was incorrect
+ changed bool // have things changed?
+ hyperPollDelay time.Duration // how often to poll the hypervisors
+ unstableTimeout time.Duration // how long a droplet can be unstable until it's declared dead
+ clusterStableDuration time.Duration // how long the cluster must be stable before new droplets can be started
+ missingDropletTimeout time.Duration // how long a droplet can be missing for
}
// the stuff that is needed for a hypervisor
diff --git a/windowGeneric.go b/windowGeneric.go
new file mode 100644
index 0000000..7daae01
--- /dev/null
+++ b/windowGeneric.go
@@ -0,0 +1,92 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/log"
+
+ "go.wit.com/gui"
+)
+
+type genericWindow struct {
+ win *gadgets.BasicWindow // the window widget itself
+ box *gui.Node // the top box of the repolist window
+ group *gui.Node // the default group
+}
+
+func (r *genericWindow) Hidden() bool {
+ if r == nil {
+ return true
+ }
+ if r.win == nil {
+ return true
+ }
+ return r.win.Hidden()
+}
+
+func (r *genericWindow) Toggle() {
+ if r.Hidden() {
+ r.Show()
+ } else {
+ r.Hide()
+ }
+}
+
+func (r *genericWindow) Show() {
+ if r == nil {
+ return
+ }
+ if r.win == nil {
+ return
+ }
+ r.win.Show()
+}
+
+func (r *genericWindow) Hide() {
+ if r == nil {
+ return
+ }
+ if r.win == nil {
+ return
+ }
+ r.win.Hide()
+}
+
+func (r *genericWindow) Disable() {
+ if r == nil {
+ return
+ }
+ if r.box == nil {
+ return
+ }
+ r.box.Disable()
+}
+
+func (r *genericWindow) Enable() {
+ if r == nil {
+ return
+ }
+ if r.box == nil {
+ return
+ }
+ r.box.Enable()
+}
+
+func initGenericWindow(title string, grouptxt string) *genericWindow {
+ gw := new(genericWindow)
+ gw.win = gadgets.RawBasicWindow(title)
+ gw.win.Make()
+
+ gw.box = gw.win.Box().Vertical() // a vertical box (like a stack of books)
+ gw.win.Custom = func() {
+ log.Warn("Found Window close. setting hidden=true")
+ // sets the hidden flag to false so Toggle() works
+ gw.win.Hide()
+ }
+ gw.group = gw.box.NewGroup(grouptxt)
+ gw.Show()
+
+ return gw
+}