summaryrefslogtreecommitdiff
path: root/doList.go
blob: 289639f8125080d1f823834d551a0c4667477609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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())
	}
}