move everything into cluster protobuf

This commit is contained in:
Jeff Carr 2025-04-21 13:30:34 -05:00
parent d3f809b25d
commit a4dd085a47
3 changed files with 69 additions and 22 deletions

View File

@ -73,12 +73,12 @@ func (admin *adminT) refresh() {
log.Info("Error:", err)
} else {
fmt.Println("EventsPB Response len:", len(data))
admin.events = new(virtpb.Events)
if err := admin.events.Unmarshal(data); err != nil {
admin.cluster.Events = new(virtpb.Events)
if err := admin.cluster.Events.Unmarshal(data); err != nil {
fmt.Println("events marshal failed", err)
return
}
fmt.Println("Events len=", admin.events.Len())
fmt.Println("Events len=", admin.cluster.Events.Len())
}
}
@ -127,13 +127,13 @@ func doLocalhostAdminGui() *adminT {
})
grid.NewButton("events", func() {
if admin.events == nil {
if admin.cluster.Events == nil {
log.Info("events are not initialized")
return
}
log.Info("Events len=", admin.events.Len())
log.Info("Events len=", admin.cluster.Events.Len())
admin.ewin = newEventsWindow()
admin.ewin.doStdEvents(admin.events)
admin.ewin.doStdEvents(admin.cluster.Events)
admin.ewin.win.Custom = func() {
log.Info("hiding table window")
}
@ -148,6 +148,41 @@ func doLocalhostAdminGui() *adminT {
return admin
}
func doAdminGui() {
me.myGui = gui.New()
me.myGui.InitEmbed(resources)
me.myGui.Default()
// Initialize a persistent client with a custom Transport
client = &http.Client{
Transport: &http.Transport{
DisableKeepAlives: false, // Ensure Keep-Alive is enabled
},
Timeout: 10 * time.Second, // Set a reasonable timeout
}
me.gwin = gadgets.NewGenericWindow("Virtigo: (run your cluster)", "")
me.gwin.Custom = func() {
log.Warn("Main window close")
os.Exit(0)
}
me.cmap = make(map[*virtpb.Cluster]*adminT)
for c := range me.clusters.IterAll() {
a := new(adminT)
me.cmap[c] = a
log.Info("found in the config file", c.URL[0])
a.makeClusterGroup(c)
}
// sit here forever refreshing the GUI
for {
// admin.refresh()
log.Info("todo: refresh() protobufs here")
time.Sleep(90 * time.Second)
}
}
func (admin *adminT) doAdminGui() {
me.myGui = gui.New()
me.myGui.InitEmbed(resources)
@ -208,13 +243,13 @@ func (admin *adminT) doAdminGui() {
})
grid.NewButton("events", func() {
if admin.events == nil {
if admin.cluster.Events == nil {
log.Info("events are not initialized")
return
}
log.Info("Events len=", admin.events.Len())
log.Info("Events len=", admin.cluster.Events.Len())
admin.ewin = newEventsWindow()
admin.ewin.doStdEvents(admin.events)
admin.ewin.doStdEvents(admin.cluster.Events)
admin.ewin.win.Custom = func() {
log.Info("hiding table window")
}
@ -253,6 +288,10 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) {
badExit(err)
}
if admin.cluster == nil {
admin.cluster = new(virtpb.Cluster)
}
name := c.GetName()
if name == "" {
name = admin.url.Hostname()
@ -299,17 +338,25 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) {
})
grid.NewButton("events", func() {
if admin.events == nil {
if admin.cluster.Events == nil {
log.Info("events are not initialized")
return
}
log.Info("Events len=", admin.events.Len())
log.Info("Events len=", admin.cluster.Events.Len())
admin.ewin = newEventsWindow()
admin.ewin.doStdEvents(admin.events)
admin.ewin.doStdEvents(admin.cluster.Events)
admin.ewin.win.Custom = func() {
log.Info("hiding table window")
}
})
grid.NewButton("refresh", func() {
admin.refresh()
})
grid.NewButton("save cluster.pb", func() {
admin.refresh()
})
}
func postData(url string, data []byte) ([]byte, error) {

View File

@ -70,8 +70,7 @@ func main() {
badExit(err)
}
me.admin = new(adminT)
me.admin.doAdminGui()
doAdminGui()
okExit("admin close")
}

View File

@ -48,9 +48,10 @@ type virtigoT struct {
type adminT struct {
// admin mode
cluster *virtpb.Cluster // the cluster protobuf
droplets *virtpb.Droplets // your droplets
hypervisors *virtpb.Hypervisors // yep
events *virtpb.Events // yep
// events *virtpb.Events // yep
uptime *gui.Node // the uptime message
dwin *stdDropletTableWin // the droplet window
hwin *stdHypervisorTableWin // the hypervisor window