blob: a96767f0d1f19b2073c74a2c3da0af7fc267acbc [file] [log] [blame]
Elia Battistone1cecb22022-03-21 10:05:25 +01001/*
2* Copyright 2022-present Open Networking Foundation
3
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7
8* http://www.apache.org/licenses/LICENSE-2.0
9
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15 */
16
17package core
18
19import (
20 "context"
21 "fmt"
22
23 "github.com/golang/protobuf/ptypes/empty"
24 "github.com/opencord/voltha-lib-go/v7/pkg/log"
25 "github.com/opencord/voltha-northbound-bbf-adapter/internal/clients"
26)
27
28var AdapterInstance *VolthaYangAdapter
29
30type VolthaYangAdapter struct {
31 volthaNbiClient *clients.VolthaNbiClient
32 oltAppClient *clients.OltAppClient
33}
34
35func NewVolthaYangAdapter(nbiClient *clients.VolthaNbiClient, oltClient *clients.OltAppClient) *VolthaYangAdapter {
36 return &VolthaYangAdapter{
37 volthaNbiClient: nbiClient,
38 oltAppClient: oltClient,
39 }
40}
41
42func (t *VolthaYangAdapter) GetDevices(ctx context.Context) ([]YangItem, error) {
43 devices, err := t.volthaNbiClient.Service.ListDevices(ctx, &empty.Empty{})
44 if err != nil {
45 err = fmt.Errorf("get-devices-failed: %v", err)
46 return nil, err
47 }
48
49 items := translateDevices(*devices)
50
51 logger.Debugw(ctx, "get-devices-success", log.Fields{"items": items})
52
53 return items, nil
54}