@@ -112,7 +112,7 @@ func NewKentikApi(ctx context.Context, log logger.ContextL, cfg *ktranslate.Conf
112112 return kapi , err
113113}
114114
115- func (api * KentikApi ) getDeviceInfo (ctx context.Context , apiUrl string , apiEmail string , apiToken string ) ([]byte , error ) {
115+ func (api * KentikApi ) callRestAPI (ctx context.Context , apiUrl string , apiEmail string , apiToken string ) ([]byte , error ) {
116116 if apiEmail == "" {
117117 if v := api .config .API .DeviceFile ; v != "" {
118118 api .Infof ("Reading devices from local file: %s" , v )
@@ -243,68 +243,6 @@ func (api *KentikApi) GetDevice(cid kt.Cid, did kt.DeviceID) *kt.Device {
243243 return nil
244244}
245245
246- /**
247- func (api *KentikApi) getInterfaces(ctx context.Context, did kt.DeviceID, info ktranslate.KentikCred) ([]kt.Interface, error) {
248- res, err := api.getDeviceInfo(ctx, fmt.Sprintf(api.config.APIBaseURL+"/api/internal/device/%d/interfaces", did), info.APIEmail, info.APIToken)
249- if err != nil {
250- return nil, err
251- }
252- interfaces := []kt.Interface{}
253- err = json.Unmarshal(res, &interfaces)
254- return interfaces, err
255- }
256-
257- func (api *KentikApi) getDevices(ctx context.Context) error {
258- stime := time.Now()
259- resDev := map[kt.Cid]kt.Devices{}
260- num := 0
261- for _, info := range api.config.KentikCreds {
262- res, err := api.getDeviceInfo(ctx, api.config.APIBaseURL+"/api/internal/devices", info.APIEmail, info.APIToken)
263- if err != nil {
264- return err
265- }
266- var devices kt.DeviceList
267- err = json.Unmarshal(res, &devices)
268- if err != nil {
269- return err
270- }
271-
272- for _, device := range devices.Devices {
273- myd := device
274- if _, ok := resDev[device.CompanyID]; !ok {
275- resDev[device.CompanyID] = map[kt.DeviceID]*kt.Device{}
276- }
277- myd.Interfaces = map[kt.IfaceID]kt.Interface{}
278- interfaces, err := api.getInterfaces(ctx, device.ID, info)
279- if err != nil {
280- api.Errorf("Cannot get interfaces for %v: %v", device.Name, err)
281- } else {
282- for _, intf := range interfaces {
283- intfl := intf // Should this be a pointer?
284- myd.Interfaces[intf.SnmpID] = intfl
285- }
286- }
287- resDev[device.CompanyID][device.ID] = &myd
288- num++
289- }
290-
291- api.Infof("Loaded %d Kentik devices via API for %s", len(devices.Devices), info.APIEmail)
292- }
293-
294- api.setTime = time.Now()
295- api.Infof("Loaded %d Kentik devices via API in %v", num, api.setTime.Sub(stime))
296- api.devices = resDev
297-
298- // Now pull in site info for these devices.
299- err := api.getSites(ctx)
300- if err != nil {
301- return err
302- }
303-
304- return nil
305- }
306- */
307-
308246func (api * KentikApi ) getSites (ctx context.Context ) error {
309247 stime := time .Now ()
310248 num := 0
@@ -314,7 +252,7 @@ func (api *KentikApi) getSites(ctx context.Context) error {
314252
315253 for _ , info := range api .config .KentikCreds {
316254 for _ , version := range versions {
317- res , err := api .getDeviceInfo (ctx , fmt .Sprintf ("%s/site/%s/sites" , api .config .GRPCBaseURL , version ), info .APIEmail , info .APIToken )
255+ res , err := api .callRestAPI (ctx , fmt .Sprintf ("%s/site/%s/sites" , api .config .GRPCBaseURL , version ), info .APIEmail , info .APIToken )
318256 if err != nil {
319257 api .Warnf ("Skipping site version %s" , version )
320258 continue
0 commit comments