-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (65 loc) · 1.5 KB
/
main.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
package main
import (
"context"
"flag"
"fmt"
"time"
agent "github.com/karimra/srl-ndk-demo"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/metadata"
)
const (
retryInterval = 2 * time.Second
agentName = "grpc-tunnel"
gnmiServerUnixSocket = "unix:///opt/srlinux/var/run/sr_gnmi_server"
)
var version = "dev"
var debug *bool
func main() {
debug = flag.Bool("d", false, "turn on debug")
versionFlag := flag.Bool("v", false, "print version")
flag.Parse()
if *versionFlag {
fmt.Println(version)
return
}
if *debug {
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx = metadata.AppendToOutgoingContext(ctx, "agent_name", agentName)
CRAGENT:
app, err := agent.New(ctx, agentName)
if err != nil {
log.Errorf("failed to create agent %q: %v", agentName, err)
log.Infof("retrying in %s", retryInterval)
time.Sleep(retryInterval)
goto CRAGENT
}
a := newApp(ctx, WithAgent(app))
//
go func() {
for {
select {
case <-ctx.Done():
return
default:
log.Info("getting system info...")
sysInfo, err := a.getSystemInfo(ctx)
if err != nil {
log.Errorf("failed to get system info %q: %v", agentName, err)
log.Infof("retrying in %s", retryInterval)
time.Sleep(retryInterval)
continue
}
log.Infof("system info: %+v", sysInfo)
a.config.sysInfo = *sysInfo
return
}
}
}()
log.Info("starting config handler...")
a.start(ctx)
}