virtigo/doList.go

73 lines
1.8 KiB
Go

// 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 (
"net/http"
"net/url"
"time"
"go.wit.com/lib/protobuf/virtpb"
"go.wit.com/log"
)
func doList() {
msg := []byte(`{"message": "Hello"}`)
// 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.cmap = make(map[*virtpb.Cluster]*adminT)
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)
admin.url, err = url.Parse(c.URL[0])
if err != nil {
badExit(err)
}
// update the droplet list
if data, err := postData(admin.url.String()+"/DropletsPB", msg); err != nil {
log.Info("/DropletsPB Error:", err)
continue
} else {
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.cluster.Droplets.Len())
var found *virtpb.Droplets
found = virtpb.NewDroplets()
all := admin.cluster.Droplets.All()
for all.Scan() {
vm := all.Next()
if vm.Current == nil {
continue
}
if argv.List.On && (vm.Current.State == virtpb.DropletState_OFF) {
continue
}
found.Append(vm)
log.Info(vm.SprintHeader())
}
log.Println("On Droplet count=", found.Len())
}
}