forked from nileshsimaria/jtimon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_vendor.go
65 lines (56 loc) · 1.36 KB
/
multi_vendor.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
package main
import (
"fmt"
"google.golang.org/grpc"
)
var vendors = []*vendor{newGNMI(), newJuniperJUNOS(), newCiscoIOSXR()}
type vendor struct {
name string
loginCheckRequired bool
sendLoginCheck func(*JCtx, *grpc.ClientConn) error
dialExt func(*JCtx) grpc.DialOption
subscribe func(*grpc.ClientConn, *JCtx) SubErrorCode
}
func getVendor(jctx *JCtx, tryGnmi bool) (*vendor, error) {
name := jctx.config.Vendor.Name
if tryGnmi {
name = "gnmi"
}
// juniper-junos is default
if name == "" {
name = "juniper-junos"
}
for _, vendor := range vendors {
if name == vendor.name {
return vendor, nil
}
}
return nil, fmt.Errorf("support for vendor [%s] has not implemented yet", name)
}
func newJuniperJUNOS() *vendor {
return &vendor{
name: "juniper-junos",
loginCheckRequired: true,
sendLoginCheck: loginCheckJunos,
dialExt: nil,
subscribe: subscribeJunos,
}
}
func newCiscoIOSXR() *vendor {
return &vendor{
name: "cisco-iosxr",
loginCheckRequired: false,
sendLoginCheck: nil,
dialExt: dialExtensionXR,
subscribe: subscribeXR,
}
}
func newGNMI() *vendor {
return &vendor{
name: "gnmi",
loginCheckRequired: false,
sendLoginCheck: nil,
dialExt: nil,
subscribe: subscribegNMI,
}
}