From 4121e66e01f5b314e4fe4999d61550fbbbc07946 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 21 Apr 2025 13:42:09 -0500 Subject: [PATCH] attempting the cluster protobuf --- doAdminGui.go | 42 +++++++++++++++++++++--------------------- doDroplet.go | 11 +++++++---- doList.go | 9 +++++---- structs.go | 17 +++++++---------- windowDroplets.go | 4 ++-- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/doAdminGui.go b/doAdminGui.go index bc024bd..fba8b5e 100644 --- a/doAdminGui.go +++ b/doAdminGui.go @@ -47,12 +47,12 @@ func (admin *adminT) refresh() { log.Info("/DropletsPB Error:", err) } else { fmt.Println("DropletsPB Response len:", len(data)) - admin.droplets = new(virtpb.Droplets) - if err := admin.droplets.Unmarshal(data); err != nil { + admin.cluster.Droplets = new(virtpb.Droplets) + if err := admin.cluster.Droplets.Unmarshal(data); err != nil { fmt.Println("droplets marshal failed", err) return } - fmt.Println("Droplet len=", admin.droplets.Len()) + fmt.Println("Droplet len=", admin.cluster.Droplets.Len()) } // update the hypervisor list @@ -60,12 +60,12 @@ func (admin *adminT) refresh() { log.Info("Error:", err) } else { fmt.Println("HypervisorsPB Response len:", len(data)) - admin.hypervisors = new(virtpb.Hypervisors) - if err := admin.hypervisors.Unmarshal(data); err != nil { + admin.cluster.Hypervisors = new(virtpb.Hypervisors) + if err := admin.cluster.Hypervisors.Unmarshal(data); err != nil { fmt.Println("hypervisors marshal failed", err) return } - fmt.Println("Hypervisors len=", admin.hypervisors.Len()) + fmt.Println("Hypervisors len=", admin.cluster.Hypervisors.Len()) } // update the events list @@ -92,20 +92,20 @@ func doLocalhostAdminGui() *adminT { grid := me.gwin.Group.RawGrid() grid.NewButton("show hypervisors", func() { - if admin.hypervisors == nil { + if admin.cluster.Hypervisors == nil { log.Info("hypervisors not initialized") return } - log.Info("Hypervisors len=", admin.hypervisors.Len()) + log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len()) admin.hwin = newHypervisorsWindow() - admin.hwin.doStdHypervisors(admin.hypervisors) + admin.hwin.doStdHypervisors(admin.cluster.Hypervisors) admin.hwin.win.Custom = func() { log.Info("hiding table window") } }) grid.NewButton("droplets", func() { - if admin.droplets == nil { + if admin.cluster.Droplets == nil { log.Info("droplets not initialized") return } @@ -115,7 +115,7 @@ func doLocalhostAdminGui() *adminT { } var found *virtpb.Droplets found = virtpb.NewDroplets() - all := admin.droplets.All() + all := admin.cluster.Droplets.All() for all.Scan() { vm := all.Next() if vm.Current.State != virtpb.DropletState_ON { @@ -208,20 +208,20 @@ func (admin *adminT) doAdminGui() { grid := win.Group.RawGrid() grid.NewButton("show hypervisors", func() { - if admin.hypervisors == nil { + if admin.cluster.Hypervisors == nil { log.Info("hypervisors not initialized") return } - log.Info("Hypervisors len=", admin.hypervisors.Len()) + log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len()) admin.hwin = newHypervisorsWindow() - admin.hwin.doStdHypervisors(admin.hypervisors) + admin.hwin.doStdHypervisors(admin.cluster.Hypervisors) admin.hwin.win.Custom = func() { log.Info("hiding table window") } }) grid.NewButton("droplets", func() { - if admin.droplets == nil { + if admin.cluster.Droplets == nil { log.Info("droplets not initialized") return } @@ -231,7 +231,7 @@ func (admin *adminT) doAdminGui() { } var found *virtpb.Droplets found = virtpb.NewDroplets() - all := admin.droplets.All() + all := admin.cluster.Droplets.All() for all.Scan() { vm := all.Next() if vm.Current.State != virtpb.DropletState_ON { @@ -303,20 +303,20 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) { grid := group.RawGrid() grid.NewButton("show hypervisors", func() { - if admin.hypervisors == nil { + if admin.cluster.Hypervisors == nil { log.Info("hypervisors not initialized") return } - log.Info("Hypervisors len=", admin.hypervisors.Len()) + log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len()) admin.hwin = newHypervisorsWindow() - admin.hwin.doStdHypervisors(admin.hypervisors) + admin.hwin.doStdHypervisors(admin.cluster.Hypervisors) admin.hwin.win.Custom = func() { log.Info("hiding table window") } }) grid.NewButton("droplets", func() { - if admin.droplets == nil { + if admin.cluster.Droplets == nil { log.Info("droplets not initialized") return } @@ -326,7 +326,7 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) { } var found *virtpb.Droplets found = virtpb.NewDroplets() - all := admin.droplets.All() + all := admin.cluster.Droplets.All() for all.Scan() { vm := all.Next() if vm.Current.State != virtpb.DropletState_ON { diff --git a/doDroplet.go b/doDroplet.go index 8a7cafc..804897e 100644 --- a/doDroplet.go +++ b/doDroplet.go @@ -35,6 +35,9 @@ func doDroplet() (string, error) { for c := range me.clusters.IterAll() { var err error admin := new(adminT) + if admin.cluster == nil { + admin.cluster = new(virtpb.Cluster) + } me.cmap[c] = admin log.Info("found in the config file", c.URL[0]) // a.makeClusterGroup(c) @@ -48,15 +51,15 @@ func doDroplet() (string, error) { log.Info("/DropletsPB Error:", err) continue } else { - admin.droplets = new(virtpb.Droplets) - if err := admin.droplets.Unmarshal(data); err != nil { + admin.cluster.Droplets = new(virtpb.Droplets) + if err := admin.cluster.Droplets.Unmarshal(data); err != nil { log.Printf("DropletsPB Response len:%d\n", len(data)) log.Println("droplets marshal failed", err) continue } } log.Printf("Cluster Name: %s\n", c.Name) - log.Printf("Number of Droplets: %d\n", admin.droplets.Len()) + log.Printf("Number of Droplets: %d\n", admin.cluster.Droplets.Len()) if argv.Droplet.Name == "" { return "", fmt.Errorf("--name droplet name was empty") @@ -64,7 +67,7 @@ func doDroplet() (string, error) { var found *virtpb.Droplets found = virtpb.NewDroplets() - all := admin.droplets.All() + all := admin.cluster.Droplets.All() for all.Scan() { vm := all.Next() if argv.Droplet.Name == vm.Hostname { diff --git a/doList.go b/doList.go index ef2ae5d..7a65650 100644 --- a/doList.go +++ b/doList.go @@ -29,6 +29,7 @@ func doList() { for c := range me.clusters.IterAll() { var err error admin := new(adminT) + admin.cluster = new(virtpb.Cluster) me.cmap[c] = admin log.Info("found in the config file", c.URL[0]) // a.makeClusterGroup(c) @@ -42,19 +43,19 @@ func doList() { log.Info("/DropletsPB Error:", err) continue } else { - admin.droplets = new(virtpb.Droplets) - if err := admin.droplets.Unmarshal(data); err != nil { + admin.cluster.Droplets = new(virtpb.Droplets) + if err := admin.cluster.Droplets.Unmarshal(data); err != nil { log.Printf("DropletsPB Response len:%d\n", len(data)) log.Println("droplets marshal failed", err) continue } } log.Printf("Cluster Name: %s\n", c.Name) - log.Printf("Number of Droplets: %d\n", admin.droplets.Len()) + log.Printf("Number of Droplets: %d\n", admin.cluster.Droplets.Len()) var found *virtpb.Droplets found = virtpb.NewDroplets() - all := admin.droplets.All() + all := admin.cluster.Droplets.All() for all.Scan() { vm := all.Next() if argv.List.On && (vm.Current.State == virtpb.DropletState_OFF) { diff --git a/structs.go b/structs.go index c54e6c2..9a00e35 100644 --- a/structs.go +++ b/structs.go @@ -46,17 +46,14 @@ type virtigoT struct { gwin *gadgets.GenericWindow // main window } +// cluster "admin" mode type adminT struct { - // admin mode - 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 + cluster *virtpb.Cluster // the cluster protobuf + 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 diff --git a/windowDroplets.go b/windowDroplets.go index 2c7aa81..3fc1bab 100644 --- a/windowDroplets.go +++ b/windowDroplets.go @@ -46,7 +46,7 @@ func newDropletsWindow() *stdDropletTableWin { grid.NewButton("Active", func() { var found *virtpb.Droplets found = virtpb.NewDroplets() - all := me.admin.droplets.All() + all := me.admin.cluster.Droplets.All() for all.Scan() { vm := all.Next() if vm.Current.State != virtpb.DropletState_ON { @@ -60,7 +60,7 @@ func newDropletsWindow() *stdDropletTableWin { grid.NewButton("Inactive", func() { var found *virtpb.Droplets found = virtpb.NewDroplets() - all := me.admin.droplets.All() + all := me.admin.cluster.Droplets.All() for all.Scan() { vm := all.Next() if vm.Current.State == virtpb.DropletState_ON {