attempting the cluster protobuf

This commit is contained in:
Jeff Carr 2025-04-21 13:42:09 -05:00
parent a4dd085a47
commit 4121e66e01
5 changed files with 42 additions and 41 deletions

View File

@ -47,12 +47,12 @@ func (admin *adminT) refresh() {
log.Info("/DropletsPB Error:", err) log.Info("/DropletsPB Error:", err)
} else { } else {
fmt.Println("DropletsPB Response len:", len(data)) fmt.Println("DropletsPB Response len:", len(data))
admin.droplets = new(virtpb.Droplets) admin.cluster.Droplets = new(virtpb.Droplets)
if err := admin.droplets.Unmarshal(data); err != nil { if err := admin.cluster.Droplets.Unmarshal(data); err != nil {
fmt.Println("droplets marshal failed", err) fmt.Println("droplets marshal failed", err)
return return
} }
fmt.Println("Droplet len=", admin.droplets.Len()) fmt.Println("Droplet len=", admin.cluster.Droplets.Len())
} }
// update the hypervisor list // update the hypervisor list
@ -60,12 +60,12 @@ func (admin *adminT) refresh() {
log.Info("Error:", err) log.Info("Error:", err)
} else { } else {
fmt.Println("HypervisorsPB Response len:", len(data)) fmt.Println("HypervisorsPB Response len:", len(data))
admin.hypervisors = new(virtpb.Hypervisors) admin.cluster.Hypervisors = new(virtpb.Hypervisors)
if err := admin.hypervisors.Unmarshal(data); err != nil { if err := admin.cluster.Hypervisors.Unmarshal(data); err != nil {
fmt.Println("hypervisors marshal failed", err) fmt.Println("hypervisors marshal failed", err)
return return
} }
fmt.Println("Hypervisors len=", admin.hypervisors.Len()) fmt.Println("Hypervisors len=", admin.cluster.Hypervisors.Len())
} }
// update the events list // update the events list
@ -92,20 +92,20 @@ func doLocalhostAdminGui() *adminT {
grid := me.gwin.Group.RawGrid() grid := me.gwin.Group.RawGrid()
grid.NewButton("show hypervisors", func() { grid.NewButton("show hypervisors", func() {
if admin.hypervisors == nil { if admin.cluster.Hypervisors == nil {
log.Info("hypervisors not initialized") log.Info("hypervisors not initialized")
return return
} }
log.Info("Hypervisors len=", admin.hypervisors.Len()) log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len())
admin.hwin = newHypervisorsWindow() admin.hwin = newHypervisorsWindow()
admin.hwin.doStdHypervisors(admin.hypervisors) admin.hwin.doStdHypervisors(admin.cluster.Hypervisors)
admin.hwin.win.Custom = func() { admin.hwin.win.Custom = func() {
log.Info("hiding table window") log.Info("hiding table window")
} }
}) })
grid.NewButton("droplets", func() { grid.NewButton("droplets", func() {
if admin.droplets == nil { if admin.cluster.Droplets == nil {
log.Info("droplets not initialized") log.Info("droplets not initialized")
return return
} }
@ -115,7 +115,7 @@ func doLocalhostAdminGui() *adminT {
} }
var found *virtpb.Droplets var found *virtpb.Droplets
found = virtpb.NewDroplets() found = virtpb.NewDroplets()
all := admin.droplets.All() all := admin.cluster.Droplets.All()
for all.Scan() { for all.Scan() {
vm := all.Next() vm := all.Next()
if vm.Current.State != virtpb.DropletState_ON { if vm.Current.State != virtpb.DropletState_ON {
@ -208,20 +208,20 @@ func (admin *adminT) doAdminGui() {
grid := win.Group.RawGrid() grid := win.Group.RawGrid()
grid.NewButton("show hypervisors", func() { grid.NewButton("show hypervisors", func() {
if admin.hypervisors == nil { if admin.cluster.Hypervisors == nil {
log.Info("hypervisors not initialized") log.Info("hypervisors not initialized")
return return
} }
log.Info("Hypervisors len=", admin.hypervisors.Len()) log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len())
admin.hwin = newHypervisorsWindow() admin.hwin = newHypervisorsWindow()
admin.hwin.doStdHypervisors(admin.hypervisors) admin.hwin.doStdHypervisors(admin.cluster.Hypervisors)
admin.hwin.win.Custom = func() { admin.hwin.win.Custom = func() {
log.Info("hiding table window") log.Info("hiding table window")
} }
}) })
grid.NewButton("droplets", func() { grid.NewButton("droplets", func() {
if admin.droplets == nil { if admin.cluster.Droplets == nil {
log.Info("droplets not initialized") log.Info("droplets not initialized")
return return
} }
@ -231,7 +231,7 @@ func (admin *adminT) doAdminGui() {
} }
var found *virtpb.Droplets var found *virtpb.Droplets
found = virtpb.NewDroplets() found = virtpb.NewDroplets()
all := admin.droplets.All() all := admin.cluster.Droplets.All()
for all.Scan() { for all.Scan() {
vm := all.Next() vm := all.Next()
if vm.Current.State != virtpb.DropletState_ON { if vm.Current.State != virtpb.DropletState_ON {
@ -303,20 +303,20 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) {
grid := group.RawGrid() grid := group.RawGrid()
grid.NewButton("show hypervisors", func() { grid.NewButton("show hypervisors", func() {
if admin.hypervisors == nil { if admin.cluster.Hypervisors == nil {
log.Info("hypervisors not initialized") log.Info("hypervisors not initialized")
return return
} }
log.Info("Hypervisors len=", admin.hypervisors.Len()) log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len())
admin.hwin = newHypervisorsWindow() admin.hwin = newHypervisorsWindow()
admin.hwin.doStdHypervisors(admin.hypervisors) admin.hwin.doStdHypervisors(admin.cluster.Hypervisors)
admin.hwin.win.Custom = func() { admin.hwin.win.Custom = func() {
log.Info("hiding table window") log.Info("hiding table window")
} }
}) })
grid.NewButton("droplets", func() { grid.NewButton("droplets", func() {
if admin.droplets == nil { if admin.cluster.Droplets == nil {
log.Info("droplets not initialized") log.Info("droplets not initialized")
return return
} }
@ -326,7 +326,7 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) {
} }
var found *virtpb.Droplets var found *virtpb.Droplets
found = virtpb.NewDroplets() found = virtpb.NewDroplets()
all := admin.droplets.All() all := admin.cluster.Droplets.All()
for all.Scan() { for all.Scan() {
vm := all.Next() vm := all.Next()
if vm.Current.State != virtpb.DropletState_ON { if vm.Current.State != virtpb.DropletState_ON {

View File

@ -35,6 +35,9 @@ func doDroplet() (string, error) {
for c := range me.clusters.IterAll() { for c := range me.clusters.IterAll() {
var err error var err error
admin := new(adminT) admin := new(adminT)
if admin.cluster == nil {
admin.cluster = new(virtpb.Cluster)
}
me.cmap[c] = admin me.cmap[c] = admin
log.Info("found in the config file", c.URL[0]) log.Info("found in the config file", c.URL[0])
// a.makeClusterGroup(c) // a.makeClusterGroup(c)
@ -48,15 +51,15 @@ func doDroplet() (string, error) {
log.Info("/DropletsPB Error:", err) log.Info("/DropletsPB Error:", err)
continue continue
} else { } else {
admin.droplets = new(virtpb.Droplets) admin.cluster.Droplets = new(virtpb.Droplets)
if err := admin.droplets.Unmarshal(data); err != nil { if err := admin.cluster.Droplets.Unmarshal(data); err != nil {
log.Printf("DropletsPB Response len:%d\n", len(data)) log.Printf("DropletsPB Response len:%d\n", len(data))
log.Println("droplets marshal failed", err) log.Println("droplets marshal failed", err)
continue continue
} }
} }
log.Printf("Cluster Name: %s\n", c.Name) 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 == "" { if argv.Droplet.Name == "" {
return "", fmt.Errorf("--name droplet name was empty") return "", fmt.Errorf("--name droplet name was empty")
@ -64,7 +67,7 @@ func doDroplet() (string, error) {
var found *virtpb.Droplets var found *virtpb.Droplets
found = virtpb.NewDroplets() found = virtpb.NewDroplets()
all := admin.droplets.All() all := admin.cluster.Droplets.All()
for all.Scan() { for all.Scan() {
vm := all.Next() vm := all.Next()
if argv.Droplet.Name == vm.Hostname { if argv.Droplet.Name == vm.Hostname {

View File

@ -29,6 +29,7 @@ func doList() {
for c := range me.clusters.IterAll() { for c := range me.clusters.IterAll() {
var err error var err error
admin := new(adminT) admin := new(adminT)
admin.cluster = new(virtpb.Cluster)
me.cmap[c] = admin me.cmap[c] = admin
log.Info("found in the config file", c.URL[0]) log.Info("found in the config file", c.URL[0])
// a.makeClusterGroup(c) // a.makeClusterGroup(c)
@ -42,19 +43,19 @@ func doList() {
log.Info("/DropletsPB Error:", err) log.Info("/DropletsPB Error:", err)
continue continue
} else { } else {
admin.droplets = new(virtpb.Droplets) admin.cluster.Droplets = new(virtpb.Droplets)
if err := admin.droplets.Unmarshal(data); err != nil { if err := admin.cluster.Droplets.Unmarshal(data); err != nil {
log.Printf("DropletsPB Response len:%d\n", len(data)) log.Printf("DropletsPB Response len:%d\n", len(data))
log.Println("droplets marshal failed", err) log.Println("droplets marshal failed", err)
continue continue
} }
} }
log.Printf("Cluster Name: %s\n", c.Name) 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 var found *virtpb.Droplets
found = virtpb.NewDroplets() found = virtpb.NewDroplets()
all := admin.droplets.All() all := admin.cluster.Droplets.All()
for all.Scan() { for all.Scan() {
vm := all.Next() vm := all.Next()
if argv.List.On && (vm.Current.State == virtpb.DropletState_OFF) { if argv.List.On && (vm.Current.State == virtpb.DropletState_OFF) {

View File

@ -46,12 +46,9 @@ type virtigoT struct {
gwin *gadgets.GenericWindow // main window gwin *gadgets.GenericWindow // main window
} }
// cluster "admin" mode
type adminT struct { type adminT struct {
// admin mode
cluster *virtpb.Cluster // the cluster protobuf 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 uptime *gui.Node // the uptime message
dwin *stdDropletTableWin // the droplet window dwin *stdDropletTableWin // the droplet window
hwin *stdHypervisorTableWin // the hypervisor window hwin *stdHypervisorTableWin // the hypervisor window

View File

@ -46,7 +46,7 @@ func newDropletsWindow() *stdDropletTableWin {
grid.NewButton("Active", func() { grid.NewButton("Active", func() {
var found *virtpb.Droplets var found *virtpb.Droplets
found = virtpb.NewDroplets() found = virtpb.NewDroplets()
all := me.admin.droplets.All() all := me.admin.cluster.Droplets.All()
for all.Scan() { for all.Scan() {
vm := all.Next() vm := all.Next()
if vm.Current.State != virtpb.DropletState_ON { if vm.Current.State != virtpb.DropletState_ON {
@ -60,7 +60,7 @@ func newDropletsWindow() *stdDropletTableWin {
grid.NewButton("Inactive", func() { grid.NewButton("Inactive", func() {
var found *virtpb.Droplets var found *virtpb.Droplets
found = virtpb.NewDroplets() found = virtpb.NewDroplets()
all := me.admin.droplets.All() all := me.admin.cluster.Droplets.All()
for all.Scan() { for all.Scan() {
vm := all.Next() vm := all.Next()
if vm.Current.State == virtpb.DropletState_ON { if vm.Current.State == virtpb.DropletState_ON {