-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
57 lines (48 loc) · 1.37 KB
/
driver.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
package gnmi
import (
"context"
"github.com/freeconf/restconf/device"
pb_gnmi "github.com/openconfig/gnmi/proto/gnmi"
)
/*
driver bridges between gnmi and FreeCONF. mapping GNMI commands to node operations
*/
type driver struct {
device device.Device
subs *subService
pb_gnmi.UnimplementedGNMIServer
}
func newDriver(d device.Device) *driver {
return &driver{
device: d,
subs: &subService{},
}
}
func (d *driver) Capabilities(ctx context.Context, req *pb_gnmi.CapabilityRequest) (*pb_gnmi.CapabilityResponse, error) {
resp := &pb_gnmi.CapabilityResponse{
SupportedModels: nil,
SupportedEncodings: []pb_gnmi.Encoding{
pb_gnmi.Encoding_JSON,
pb_gnmi.Encoding_JSON_IETF,
},
GNMIVersion: Version,
}
for moduleName, module := range d.device.Modules() {
md := &pb_gnmi.ModelData{
Name: moduleName,
Organization: module.Organization(),
Version: module.Revision().Ident(),
}
resp.SupportedModels = append(resp.SupportedModels, md)
}
return resp, nil
}
func (d *driver) Set(ctx context.Context, req *pb_gnmi.SetRequest) (*pb_gnmi.SetResponse, error) {
return set(d.device, ctx, req)
}
func (d *driver) Get(ctx context.Context, req *pb_gnmi.GetRequest) (*pb_gnmi.GetResponse, error) {
return get(d.device, ctx, req)
}
func (d *driver) Subscribe(server pb_gnmi.GNMI_SubscribeServer) error {
return d.subs.subscribe(d.device, server)
}