diff --git a/doAdminGui.go b/doAdminGui.go index 257e83f..bc024bd 100644 --- a/doAdminGui.go +++ b/doAdminGui.go @@ -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) { diff --git a/main.go b/main.go index a8ac00a..f02df52 100644 --- a/main.go +++ b/main.go @@ -70,8 +70,7 @@ func main() { badExit(err) } - me.admin = new(adminT) - me.admin.doAdminGui() + doAdminGui() okExit("admin close") } diff --git a/structs.go b/structs.go index 84349b4..c54e6c2 100644 --- a/structs.go +++ b/structs.go @@ -48,14 +48,15 @@ type virtigoT struct { type adminT struct { // admin mode - droplets *virtpb.Droplets // your droplets - hypervisors *virtpb.Hypervisors // yep - events *virtpb.Events // yep - uptime *gui.Node // the uptime message - dwin *stdDropletTableWin // the droplet window - hwin *stdHypervisorTableWin // the hypervisor window - ewin *stdEventTableWin // the events window - url *url.URL // URL for the cloud + cluster *virtpb.Cluster // the cluster protobuf + droplets *virtpb.Droplets // your droplets + hypervisors *virtpb.Hypervisors // yep + // events *virtpb.Events // yep + uptime *gui.Node // the uptime message + dwin *stdDropletTableWin // the droplet window + hwin *stdHypervisorTableWin // the hypervisor window + ewin *stdEventTableWin // the events window + url *url.URL // URL for the cloud } // the stuff that is needed for a hypervisor