[VOL-5305] added voltctl implementation to fetch onu distance
Change-Id: Ie1452252c5517f37bebfd2bdc2a5b83e7d4dc0df
Signed-off-by: Akash Soni <akash.soni@radisys.com>
diff --git a/internal/pkg/commands/devices.go b/internal/pkg/commands/devices.go
index 6b8756e..c9410d2 100644
--- a/internal/pkg/commands/devices.go
+++ b/internal/pkg/commands/devices.go
@@ -122,6 +122,7 @@
DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t"
+ DEFAULT_ONU_DISTANCE_FORMAT = `Distance`
)
type DeviceList struct {
@@ -136,6 +137,7 @@
}
type DeviceId string
+type OnuId string
type MetricName string
type GroupName string
@@ -452,6 +454,14 @@
} `positional-args:"yes"`
}
+type GetOnuDistance struct {
+ ListOutputOptions
+ Args struct {
+ Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
+ OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
+ } `positional-args:"yes"` //onu device id
+}
+
type DeviceOpts struct {
List DeviceList `command:"list"`
Create DeviceCreate `command:"create"`
@@ -516,6 +526,7 @@
OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
PonRxPower PonRxPower `command:"pon_rx_power"`
+ OnuDistance GetOnuDistance `command:"onu_distance"`
} `command:"getextval"`
}
@@ -2458,6 +2469,53 @@
return nil
}
+/*Device get Onu Active Alarms */
+func (options *GetOnuDistance) Execute(args []string) error {
+ conn, err := NewConnection()
+ if err != nil {
+ return err
+ }
+ defer conn.Close()
+ client := extension.NewExtensionClient(conn)
+
+ singleGetValReq := extension.SingleGetValueRequest{
+ TargetId: string(options.Args.Id),
+ Request: &extension.GetValueRequest{
+ Request: &extension.GetValueRequest_Distance{
+ Distance: &extension.GetDistanceRequest{
+ OnuDeviceId: string(options.Args.OnuId),
+ },
+ },
+ },
+ }
+ Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
+ ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
+ defer cancel()
+ rv, err := client.GetExtValue(ctx, &singleGetValReq)
+ if err != nil {
+ Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
+ return err
+ }
+
+ if rv.Response.Status != extension.GetValueResponse_OK {
+ return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
+ }
+ outputFormat := CharReplacer.Replace(options.Format)
+ if outputFormat == "" {
+ outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
+ }
+
+ result := CommandResult{
+ Format: format.Format(outputFormat),
+ OutputAs: toOutputType(options.OutputAs),
+ NameLimit: options.NameLimit,
+ Data: rv.GetResponse().GetDistance().GetDistance(),
+ }
+ fmt.Println("onu distance : ", rv)
+ GenerateOutput(&result)
+ return nil
+}
+
func (options *PonRxPower) Execute(args []string) error {
conn, err := NewConnection()
if err != nil {