[VOL-3695]: Support to create some of the OLT device events over the Device Management Interface
1. Following events and its corresponding recovered event creation is supported :
EVENT_FAN_FAILURE
EVENT_PSU_FAILURE
EVENT_HW_DEVICE_TEMPERATURE_ABOVE_CRITICAL
2. Following DMI Native Events Management Service APIs are implemented:
ListEvents
UpdateEventsConfiguration
3. Updated docs/source/DMI_Server_README.md
Change-Id: Ibc48302b61fd52a2f83bd888731f611eaf6c4c37
diff --git a/internal/bbsimctl/commands/dmi_events.go b/internal/bbsimctl/commands/dmi_events.go
new file mode 100644
index 0000000..1608965
--- /dev/null
+++ b/internal/bbsimctl/commands/dmi_events.go
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package commands
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/jessevdk/go-flags"
+ "github.com/opencord/bbsim/api/bbsim"
+ "github.com/opencord/bbsim/internal/bbsimctl/config"
+ log "github.com/sirupsen/logrus"
+ "google.golang.org/grpc"
+)
+
+type DMIOptions struct {
+ Events DmiEventOptions `command:"events"`
+}
+
+type DmiEventCreate struct {
+ Args struct {
+ Name string
+ } `positional-args:"yes" required:"yes"`
+}
+
+type DmiEventOptions struct {
+ Create DmiEventCreate `command:"create"`
+}
+
+func RegisterDMICommands(parser *flags.Parser) {
+ _, _ = parser.AddCommand("dmi", "DMI Commands", "Commands to create events", &DMIOptions{})
+}
+
+func dmiEventGrpcClient() (bbsim.BBsimDmiClient, *grpc.ClientConn) {
+ conn, err := grpc.Dial(config.DmiConfig.Server, grpc.WithInsecure())
+ if err != nil {
+ log.Errorf("BBsimDmiClient connection failed : %v", err)
+ return nil, conn
+ }
+ return bbsim.NewBBsimDmiClient(conn), conn
+}
+
+// Execute create event
+func (o *DmiEventCreate) Execute(args []string) error {
+ client, conn := dmiEventGrpcClient()
+ defer conn.Close()
+
+ ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
+ defer cancel()
+
+ req := bbsim.DmiEvent{EventName: o.Args.Name}
+ res, err := client.CreateEvent(ctx, &req)
+ if err != nil {
+ log.Errorf("Cannot create DMI event: %v", err)
+ return err
+ }
+
+ fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
+ return nil
+}
diff --git a/internal/bbsimctl/commands/onualarms.go b/internal/bbsimctl/commands/onualarms.go
index fb1d00e..669c173 100755
--- a/internal/bbsimctl/commands/onualarms.go
+++ b/internal/bbsimctl/commands/onualarms.go
@@ -20,10 +20,11 @@
import (
"context"
"fmt"
- "github.com/opencord/bbsim/internal/common"
"os"
"strings"
+ "github.com/opencord/bbsim/internal/common"
+
"github.com/jessevdk/go-flags"
"github.com/olekukonko/tablewriter"
pb "github.com/opencord/bbsim/api/bbsim"
diff --git a/internal/bbsimctl/config/config.go b/internal/bbsimctl/config/config.go
index 7d11122..4bf762a 100644
--- a/internal/bbsimctl/config/config.go
+++ b/internal/bbsimctl/config/config.go
@@ -57,6 +57,13 @@
},
}
+var DmiConfig = GlobalConfigSpec{
+ Server: "localhost:50075",
+ Grpc: GrpcConfigSpec{
+ Timeout: time.Second * 10,
+ },
+}
+
func ProcessGlobalOptions() {
if len(GlobalOptions.Config) == 0 {
home, err := os.UserHomeDir()