-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.go
78 lines (66 loc) · 2.34 KB
/
utils.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
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
package main
import (
"encoding/json"
"flag"
"fmt"
"hailo/apiserver"
"hailo/conf"
"hailo/hailo"
"os"
"time"
)
// printData prints the complete FDS data for the given endpoint
func printData(authServer string, username string, password string, fdsEndpoint string) {
time.Sleep(time.Millisecond * 100) // Sleeps for a short time, since fmt output sometimes overlaps
// Create config from command line args
config := conf.BuildFdsConfig(authServer, username, password, fdsEndpoint)
fmt.Println(" ---- Server config ----")
pretty, _ := json.MarshalIndent(config, "", "\t")
fmt.Println(string(pretty))
// Get Specifications
specs, _ := hailo.GetSpecs(config)
for _, spec := range specs.Data {
printSpec(config, spec)
for _, subSpec := range spec.DeviceTypeSpecific.ComponentIdList {
printSpec(config, subSpec)
}
}
}
// args holds command line arguments
type args struct {
test bool
userName string
password string
authServer string
fdsEndpoint string
}
// determineArgs gets the
func determineArgs() args {
var programArgs args
flag.BoolVar(&programArgs.test, "t", false, "Test get data from Hailo FDS API without Eliona")
flag.StringVar(&programArgs.userName, "user", "", "Username for Hailo FDS authentication endpoint (used for -t)")
flag.StringVar(&programArgs.password, "password", "", "Password for Hailo FDS authentication endpoint (used for -t)")
flag.StringVar(&programArgs.authServer, "auth", "", "Authentication endpoint for Hailo FDS (used for -t)")
flag.StringVar(&programArgs.fdsEndpoint, "fds", "", "FDS endpoint for for Hailo FDS (used for -t)")
flag.Usage = func() {
fmt.Printf("Usage: \n")
flag.PrintDefaults() // prints default usage
os.Exit(0)
}
flag.Parse()
return programArgs
}
// printSpec gets and prints out the data for the specification
func printSpec(config apiserver.Configuration, spec hailo.Spec) {
fmt.Printf(" ---- Device %s ----\n", spec.DeviceId)
pretty, _ := json.MarshalIndent(spec, "", "\t")
fmt.Println(string(pretty))
status, _ := hailo.GetStatus(config, spec.DeviceId)
fmt.Printf(" ---- Status %s ----\n", spec.DeviceId)
pretty, _ = json.MarshalIndent(status, "", "\t")
fmt.Println(string(pretty))
diag, _ := hailo.GetDiag(config, spec.DeviceId)
fmt.Printf(" ---- Diagnostic %s ----\n", spec.DeviceId)
pretty, _ = json.MarshalIndent(diag, "", "\t")
fmt.Println(string(pretty))
}