Create uni command in BBSimctl
Clean up UNI command and add filtering to UNI services
Change-Id: I1a54d786ca71a602c0ca0113f030c6caa1bc9cc7
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
index bef627e..4ae8841 100644
--- a/internal/bbsimctl/commands/onu.go
+++ b/internal/bbsimctl/commands/onu.go
@@ -35,8 +35,6 @@
const (
DEFAULT_ONU_DEVICE_HEADER_FORMAT = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .ImageSoftwareExpectedSections }}\t{{ .ImageSoftwareReceivedSections }}\t{{ .ActiveImageEntityId }}\t{{ .CommittedImageEntityId }}"
DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .ImageSoftwareExpectedSections }}\t{{ .ImageSoftwareReceivedSections }}\t{{ .ActiveImageEntityId }}\t{{ .CommittedImageEntityId }}\t{{ .Unis }}"
- DEFAULT_UNI_HEADER_FORMAT = "table{{ .OnuSn }}\t{{ .OnuID }}\t{{ .ID }}\t{{ .MeID }}\t{{ .PortNo }}\t{{ .OperState }}"
- DEFAULT_UNI_HEADER_FORMAT_WITH_SERVICES = "table{{ .OnuSn }}\t{{ .OnuID }}\t{{ .ID }}\t{{ .MeID }}\t{{ .PortNo }}\t{{ .OperState }}\t{{ .Services }}"
)
type OnuSnString string
@@ -111,10 +109,15 @@
} `positional-args:"yes" required:"yes"`
}
+type ONUServices struct {
+ Args struct {
+ OnuSn OnuSnString
+ } `positional-args:"yes"`
+}
+
type ONUOptions struct {
List ONUList `command:"list"`
Get ONUGet `command:"get"`
- Unis ONUUnis `command:"unis"`
ShutDown ONUShutDown `command:"shutdown"`
PowerOn ONUPowerOn `command:"poweron"`
RestartEapol ONUEapolRestart `command:"auth_restart"`
@@ -123,6 +126,7 @@
TrafficSchedulers ONUTrafficSchedulers `command:"traffic_schedulers"`
Alarms AlarmOptions `command:"alarms"`
Flows ONUFlows `command:"flows"`
+ Services ONUServices `command:"services"`
}
func RegisterONUCommands(parser *flags.Parser) {
@@ -192,36 +196,6 @@
return nil
}
-func (options *ONUUnis) 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.GetOnuUnis(ctx, &req)
-
- if err != nil {
- log.Fatalf("Cannot not get unis for ONU %s: %v", options.Args.OnuSn, err)
- return err
- }
-
- var tableFormat format.Format
- if options.Verbose {
- tableFormat = format.Format(DEFAULT_UNI_HEADER_FORMAT_WITH_SERVICES)
- } else {
- tableFormat = format.Format(DEFAULT_UNI_HEADER_FORMAT)
- }
- if err := tableFormat.Execute(os.Stdout, true, res.Items); err != nil {
- log.Fatalf("Error while formatting Unis table: %s", err)
- }
-
- return nil
-}
-
func (options *ONUShutDown) Execute(args []string) error {
client, conn := connect()
@@ -539,3 +513,20 @@
return nil
}
+
+func (options *ONUServices) Execute(args []string) error {
+ services, err := getServices(string(options.Args.OnuSn), "")
+
+ if err != nil {
+ log.Errorf("Cannot get services for ONU %s: %v", options.Args.OnuSn, err)
+ return err
+ }
+
+ // print out
+ tableFormat := format.Format(DEFAULT_SERVICE_HEADER_FORMAT)
+ if err := tableFormat.Execute(os.Stdout, true, services.Items); err != nil {
+ log.Fatalf("Error while formatting ONUs table: %s", err)
+ }
+
+ return nil
+}