-
Notifications
You must be signed in to change notification settings - Fork 19
/
listLocations.go
52 lines (48 loc) · 1.18 KB
/
listLocations.go
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
package hypervisors
import (
"bufio"
"fmt"
"net/http"
"github.com/Symantec/Dominator/fleetmanager/topology"
)
func (m *Manager) listLocations(dirname string) ([]string, error) {
topo, err := m.getTopology()
if err != nil {
return nil, err
}
directory, err := topo.FindDirectory(dirname)
if err != nil {
return nil, err
}
var locations []string
directory.Walk(func(directory *topology.Directory) error {
for _, machine := range directory.Machines {
hypervisor, err := m.getLockedHypervisor(machine.Hostname, false)
if err != nil {
continue
}
if hypervisor.probeStatus == probeStatusConnected &&
(hypervisor.healthStatus == "" ||
hypervisor.healthStatus == "healthy") {
locations = append(locations, directory.GetPath())
hypervisor.mutex.RUnlock()
return nil
}
hypervisor.mutex.RUnlock()
}
return nil
})
return locations, nil
}
func (m *Manager) listLocationsHandler(w http.ResponseWriter,
req *http.Request) {
writer := bufio.NewWriter(w)
defer writer.Flush()
if locations, err := m.listLocations(""); err != nil {
fmt.Fprintln(writer, err)
} else {
for _, location := range locations {
fmt.Fprintln(writer, location)
}
}
}