@@ -8,10 +8,13 @@ import (
8
8
9
9
bgpconvertors "github.com/criteo/data-aggregation-api/internal/convertor/bgp"
10
10
rpconvertors "github.com/criteo/data-aggregation-api/internal/convertor/routingpolicy"
11
+ snmpconvertors "github.com/criteo/data-aggregation-api/internal/convertor/snmp"
11
12
"github.com/criteo/data-aggregation-api/internal/ingestor/repository"
12
13
"github.com/criteo/data-aggregation-api/internal/model/cmdb/bgp"
13
14
"github.com/criteo/data-aggregation-api/internal/model/cmdb/routingpolicy"
15
+ "github.com/criteo/data-aggregation-api/internal/model/cmdb/snmp"
14
16
"github.com/criteo/data-aggregation-api/internal/model/dcim"
17
+ "github.com/criteo/data-aggregation-api/internal/model/ietf"
15
18
"github.com/criteo/data-aggregation-api/internal/model/openconfig"
16
19
"github.com/openconfig/ygot/ygot"
17
20
"github.com/rs/zerolog/log"
@@ -22,15 +25,18 @@ const AFKEnabledTag = "afk-enabled"
22
25
var defaultInstance = "default"
23
26
24
27
type GeneratedConfig struct {
25
- Openconfig * openconfig.Device
26
- JSON string
28
+ IETF * ietf.Device
29
+ JSONIETF string
30
+ Openconfig * openconfig.Device
31
+ JSONOpenConfig string
27
32
}
28
33
29
34
type Device struct {
30
35
mutex * sync.Mutex
31
36
Dcim * dcim.NetworkDevice
32
37
Config * GeneratedConfig
33
38
BGPGlobalConfig * bgp.BGPGlobal
39
+ SNMP * snmp.SNMP
34
40
Sessions []* bgp.Session
35
41
PeerGroups []* bgp.PeerGroup
36
42
PrefixLists []* routingpolicy.PrefixList
@@ -92,12 +98,16 @@ func NewDevice(dcimInfo *dcim.NetworkDevice, devicesData *repository.AssetsPerDe
92
98
return nil , fmt .Errorf ("no route-policies found for %s" , dcimInfo .Hostname )
93
99
}
94
100
101
+ device .SNMP , ok = devicesData .SNMP [dcimInfo .Hostname ]
102
+ if ! ok {
103
+ log .Warn ().Msgf ("no snmp found for %s" , dcimInfo .Hostname )
104
+ }
95
105
return device , nil
96
106
}
97
107
98
- // GenerateOpenconfig generate the OpenConfig data for the current device.
108
+ // Generateconfigs generate the Config (openconfig & ietf) data for the current device.
99
109
// The CMDB data must have been precomputed before running this method.
100
- func (d * Device ) GenerateOpenconfig () error {
110
+ func (d * Device ) Generateconfigs () error {
101
111
d .mutex .Lock ()
102
112
defer d .mutex .Unlock ()
103
113
@@ -139,23 +149,60 @@ func (d *Device) GenerateOpenconfig() error {
139
149
Indent : " " ,
140
150
},
141
151
)
152
+
142
153
if err != nil {
143
154
return fmt .Errorf ("failed to transform an openconfig device specification (%s) into JSON using ygot: %w" , d .Dcim .Hostname , err )
144
155
}
145
156
146
157
d .Config = & GeneratedConfig {
147
- Openconfig : & config ,
148
- JSON : devJSON ,
158
+ Openconfig : & config ,
159
+ JSONOpenConfig : devJSON ,
160
+ IETF : nil ,
161
+ JSONIETF : "{}" ,
149
162
}
150
163
164
+ if d .SNMP == nil {
165
+ log .Warn ().Msgf ("%s don't have a Snmp configuration, skip IetfConfig" , d .Dcim .Hostname )
166
+ } else {
167
+ IetfSystem := snmpconvertors .SNMPtoIETFfSystem (d .SNMP )
168
+ IetfSnmp := snmpconvertors .SNMPtoIETFsnmp (d .SNMP )
169
+
170
+ d .Config .IETF = & ietf.Device {
171
+ System : & IetfSystem ,
172
+ Snmp : & IetfSnmp ,
173
+ }
174
+
175
+ d .Config .JSONIETF , err = ygot .EmitJSON (
176
+ d .Config .IETF ,
177
+ & ygot.EmitJSONConfig {
178
+ Format : ygot .RFC7951 ,
179
+ SkipValidation : false ,
180
+ Indent : " " ,
181
+ },
182
+ )
183
+ if err != nil {
184
+ return fmt .Errorf ("failed to transform an ietf device specification (%s) into JSON using ygot: %w" , d .Dcim .Hostname , err )
185
+ }
186
+ }
151
187
return nil
152
188
}
153
189
154
- // GetCompactJSON returns OpenConfig result in not indented JSON format.
190
+ // GetCompactOpenconfigJSON returns OpenConfig result in not indented JSON format.
155
191
// Generated JSON is already indented by Ygot - currently there is no option to not indent the JSON.
156
- func (d * Device ) GetCompactJSON () ([]byte , error ) {
192
+ func (d * Device ) GetCompactOpenconfigJSON () ([]byte , error ) {
193
+ out := bytes .NewBuffer (nil )
194
+ err := json .Compact (out , []byte (d .Config .JSONOpenConfig ))
195
+ if err != nil {
196
+ return nil , err
197
+ }
198
+ return out .Bytes (), nil
199
+ }
200
+
201
+ // GetCompactIETFJSON returns IETF result in not indented JSON format.
202
+ // GetCompactIETFJSON JSON is already indented by Ygot - currently there is no option to not indent the JSON.
203
+ func (d * Device ) GetCompactIETFJSON () ([]byte , error ) {
157
204
out := bytes .NewBuffer (nil )
158
- err := json .Compact (out , []byte (d .Config .JSON ))
205
+ err := json .Compact (out , []byte (d .Config .JSONIETF ))
159
206
if err != nil {
160
207
return nil , err
161
208
}
0 commit comments