first gui for virtigo! easy with proto pb tables
This commit is contained in:
parent
6e111ba862
commit
9f9a52312e
1
Makefile
1
Makefile
|
@ -8,6 +8,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE=
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
./virtigo --version
|
./virtigo --version
|
||||||
|
./virtigo --gui gocui
|
||||||
@echo build worked
|
@echo build worked
|
||||||
|
|
||||||
build: goimports vet
|
build: goimports vet
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
18
main.go
18
main.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
"go.wit.com/gui"
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/lib/virtigolib"
|
"go.wit.com/lib/virtigolib"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -21,12 +22,8 @@ var Version string
|
||||||
var resources embed.FS
|
var resources embed.FS
|
||||||
|
|
||||||
func main() {
|
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
|
var pp *arg.Parser
|
||||||
|
gui.InitArg()
|
||||||
pp = arg.MustParse(&argv)
|
pp = arg.MustParse(&argv)
|
||||||
|
|
||||||
if pp == nil {
|
if pp == nil {
|
||||||
|
@ -34,9 +31,11 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if argv.Daemon {
|
if os.Getenv("VIRTIGO_HOME") == "" {
|
||||||
// log.DaemonMode(true)
|
homeDir, _ := os.UserHomeDir()
|
||||||
// }
|
fullpath := filepath.Join(homeDir, ".config/virtigo")
|
||||||
|
os.Setenv("VIRTIGO_HOME", fullpath)
|
||||||
|
}
|
||||||
|
|
||||||
// set defaults
|
// set defaults
|
||||||
me.unstable = time.Now() // initialize the grid as unstable
|
me.unstable = time.Now() // initialize the grid as unstable
|
||||||
|
@ -176,5 +175,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sit here
|
// sit here
|
||||||
startHTTP()
|
go startHTTP()
|
||||||
|
doGui()
|
||||||
}
|
}
|
||||||
|
|
11
structs.go
11
structs.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/gui"
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,14 +22,14 @@ func (b *virtigoT) Enable() {
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type virtigoT struct {
|
type virtigoT struct {
|
||||||
cluster *pb.Cluster // basic cluster settings
|
cluster *pb.Cluster // basic cluster settings
|
||||||
// newc *pb.Cluster // basic cluster settings
|
myGui *gui.Node // the gui toolkit handle
|
||||||
e *pb.Events // virtbuf events
|
e *pb.Events // virtbuf events
|
||||||
hmap map[*pb.Hypervisor]*HyperT // map to the local struct
|
hmap map[*pb.Hypervisor]*HyperT // map to the local struct
|
||||||
names []string
|
names []string // ?
|
||||||
hypers []*HyperT
|
hypers []*HyperT // notsure
|
||||||
killcount int
|
killcount int // how many times virtigo-d has had to been killed
|
||||||
unstable time.Time // the last time the cluster was incorrect
|
unstable time.Time // the last time the cluster was incorrect
|
||||||
changed bool
|
changed bool // have things changed?
|
||||||
hyperPollDelay time.Duration // how often to poll the hypervisors
|
hyperPollDelay time.Duration // how often to poll the hypervisors
|
||||||
unstableTimeout time.Duration // how long a droplet can be unstable until it's declared dead
|
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
|
clusterStableDuration time.Duration // how long the cluster must be stable before new droplets can be started
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue