blob: da1e8aef9d60b240e54a30ffa0d2f130eb8330f0 [file] [log] [blame]
amit.ghosh258d14c2020-10-02 15:13:38 +02001/*
2 * Copyright 2018-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 dmiserver
18
19import (
20 "context"
hkouser24361d42020-12-14 19:21:47 +053021 "google.golang.org/grpc/codes"
22 "google.golang.org/grpc/status"
amit.ghosh258d14c2020-10-02 15:13:38 +020023
24 dmi "github.com/opencord/device-management-interface/go/dmi"
25)
26
27//ListEvents lists the supported events for the passed device
28func (dms *DmiAPIServer) ListEvents(ctx context.Context, req *dmi.HardwareID) (*dmi.ListEventsResponse, error) {
29 logger.Debugf("ListEvents called with request %+v", req)
hkouser24361d42020-12-14 19:21:47 +053030 events := getEventsList()
31
amit.ghosh258d14c2020-10-02 15:13:38 +020032 return &dmi.ListEventsResponse{
Humera Kousera4442952020-11-23 23:51:19 +053033 Status: dmi.Status_OK_STATUS,
amit.ghosh258d14c2020-10-02 15:13:38 +020034 Events: &dmi.EventsCfg{
35 Items: events,
36 },
37 }, nil
38}
39
40//UpdateEventsConfiguration updates the configuration of the list of events in the request
41func (dms *DmiAPIServer) UpdateEventsConfiguration(ctx context.Context, req *dmi.EventsConfigurationRequest) (*dmi.EventsConfigurationResponse, error) {
42 logger.Debugf("UpdateEventsConfiguration called with request %+v", req)
hkouser24361d42020-12-14 19:21:47 +053043
44 if req == nil || req.Operation == nil {
45 return &dmi.EventsConfigurationResponse{
46 Status: dmi.Status_ERROR_STATUS,
47 //TODO reason must be INVALID_PARAMS, currently this is not available in Device Management interface (DMI),
48 // change below reason with type INVALID_PARAMS once DMI is updated
49 Reason: dmi.Reason_UNDEFINED_REASON,
50 }, status.Errorf(codes.FailedPrecondition, "request is nil")
51 }
52
53 switch x := req.Operation.(type) {
54 case *dmi.EventsConfigurationRequest_Changes:
55 for _, eventConfig := range x.Changes.Items {
56 UpdateEventConfig(eventConfig)
57 }
58 case *dmi.EventsConfigurationRequest_ResetToDefault:
59 logger.Debugf("To be implemented later")
60 case nil:
61 // The field is not set.
62 logger.Debugf("Update request operation type is nil")
63 return &dmi.EventsConfigurationResponse{
64 Status: dmi.Status_UNDEFINED_STATUS,
65 }, nil
66 }
67
amit.ghosh258d14c2020-10-02 15:13:38 +020068 return &dmi.EventsConfigurationResponse{
Humera Kousera4442952020-11-23 23:51:19 +053069 Status: dmi.Status_OK_STATUS,
amit.ghosh258d14c2020-10-02 15:13:38 +020070 }, nil
71}