[SEBA-818] Adding onu get command to BBSimCtl
Change-Id: I182effdd2d82e3b57d72c53c89fa978b75f16354
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
index f99cb5c..fc89300 100644
--- a/internal/bbsimctl/commands/onu.go
+++ b/internal/bbsimctl/commands/onu.go
@@ -36,6 +36,13 @@
type OnuSnString string
type ONUList struct{}
+
+type ONUGet struct {
+ Args struct {
+ OnuSn OnuSnString
+ } `positional-args:"yes" required:"yes"`
+}
+
type ONUShutDown struct {
Args struct {
OnuSn OnuSnString
@@ -50,6 +57,7 @@
type ONUOptions struct {
List ONUList `command:"list"`
+ Get ONUGet `command:"get"`
ShutDown ONUShutDown `command:"shutdown"`
PowerOn ONUPowerOn `command:"poweron"`
}
@@ -97,6 +105,30 @@
return nil
}
+func (options *ONUGet) Execute(args []string) error {
+ client, conn := connect()
+ defer conn.Close()
+
+ ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
+ defer cancel()
+ req := pb.ONURequest{
+ SerialNumber: string(options.Args.OnuSn),
+ }
+ res, err := client.GetONU(ctx, &req)
+
+ if err != nil {
+ log.Fatalf("Cannot not shutdown ONU %s: %v", options.Args.OnuSn, err)
+ return err
+ }
+
+ tableFormat := format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT)
+ if err := tableFormat.Execute(os.Stdout, true, []*pb.ONU{res}); err != nil {
+ log.Fatalf("Error while formatting ONUs table: %s", err)
+ }
+
+ return nil
+}
+
func (options *ONUShutDown) Execute(args []string) error {
client, conn := connect()