summaryrefslogtreecommitdiff
path: root/doList.go
blob: ee2eeea6b53b7434d076def268d0554a2e360250 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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 (
	"fmt"
	"net/http"
	"net/url"
	"time"

	"go.wit.com/lib/protobuf/virtpb"
	"go.wit.com/log"
)

// refresh the windows & tables the user has open
func doListDroplets() {
	/*
		// update the droplet list
		if data, err := postData(admin.url.String()+"/DropletsPB", msg); err != nil {
			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 {
				fmt.Println("droplets marshal failed", err)
				return
			}
			fmt.Println("Droplet len=", admin.droplets.Len())
		}

		// update the hypervisor list
		if data, err := postData(admin.url.String()+"/HypervisorsPB", msg); err != nil {
			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 {
				fmt.Println("hypervisors marshal failed", err)
				return
			}
			fmt.Println("Hypervisors len=", admin.hypervisors.Len())
		}

		// update the events list
		if data, err := postData(admin.url.String()+"/EventsPB", msg); err != nil {
			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 {
				fmt.Println("events marshal failed", err)
				return
			}
			fmt.Println("Events len=", admin.events.Len())
		}
	*/
}

// var client *http.Client

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)
		me.cmap[c] = admin
		log.Info("found in the config file", c.URL)
		// a.makeClusterGroup(c)
		admin.url, err = url.Parse(c.URL)
		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)
		} else {
			fmt.Println("DropletsPB Response len:", len(data))
			admin.droplets = new(virtpb.Droplets)
			if err := admin.droplets.Unmarshal(data); err != nil {
				fmt.Println("droplets marshal failed", err)
				return
			}
			fmt.Println("Droplet len=", admin.droplets.Len())
		}

	}

	// sit here forever refreshing the GUI
}