Skip to content
Snippets Groups Projects
Commit 8dac05dc authored by Malte Bauch's avatar Malte Bauch
Browse files

WIP

parent 8edcc098
No related branches found
No related tags found
1 merge request!284Improve usability and better output formatting for gosndc
Pipeline #99524 failed
This commit is part of merge request !284. Comments created here will be created in the context of that merge request.
...@@ -119,7 +119,7 @@ func (p *PndAdapter) ChangeOND(duid uuid.UUID, operation ppb.ApiOperation, path ...@@ -119,7 +119,7 @@ func (p *PndAdapter) ChangeOND(duid uuid.UUID, operation ppb.ApiOperation, path
// Request sends an API call to the controller requesting the specified path // Request sends an API call to the controller requesting the specified path
// for the specified device // for the specified device
func (p *PndAdapter) Request(did uuid.UUID, path string) (proto.Message, error) { func (p *PndAdapter) Request(did uuid.UUID, path string) (*ppb.GetPathResponse, error) {
resp, err := api.GetPath(p.endpoint, p.id.String(), did.String(), path) resp, err := api.GetPath(p.endpoint, p.id.String(), did.String(), path)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -53,6 +53,7 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`, ...@@ -53,6 +53,7 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`,
spinner, _ := pterm.DefaultSpinner.Start("Creating new device") spinner, _ := pterm.DefaultSpinner.Start("Creating new device")
err := checkIPPort(address) err := checkIPPort(address)
if err != nil { if err != nil {
spinner.Fail(err)
return err return err
} }
...@@ -74,6 +75,7 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`, ...@@ -74,6 +75,7 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`,
} }
sid, err := uuid.Parse(cliSbi) sid, err := uuid.Parse(cliSbi)
if err != nil { if err != nil {
spinner.Fail(err)
return err return err
} }
...@@ -82,13 +84,13 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`, ...@@ -82,13 +84,13 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`,
return err return err
} }
if resp.GetStatus() == pnd.Status_STATUS_OK { for _, r := range resp.GetResponses() {
// TODO: we should return a ID here, changes needed for AddDevice() if r.GetStatus() == pnd.Status_STATUS_OK {
spinner.Success("Device has been created with ID: ") spinner.Success("Device has been created with ID: ", r.GetId())
return nil } else {
spinner.Fail("An error occured while creating Device with ID: ", r.GetId(), r.GetStatus())
}
} }
spinner.Warning("Creating new device: ", resp.GetStatus())
return nil return nil
}, },
} }
......
...@@ -34,7 +34,7 @@ package cmd ...@@ -34,7 +34,7 @@ package cmd
import ( import (
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
"github.com/google/uuid" "github.com/google/uuid"
log "github.com/sirupsen/logrus" "github.com/pterm/pterm"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
...@@ -46,16 +46,22 @@ var deviceDeleteCmd = &cobra.Command{ ...@@ -46,16 +46,22 @@ var deviceDeleteCmd = &cobra.Command{
Long: `Delete a path for a given orchestrated network device. Long: `Delete a path for a given orchestrated network device.
The device UUID and request path must be specified as a positional arguments.`, The device UUID and request path must be specified as a positional arguments.`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
spinner, _ := pterm.DefaultSpinner.Start("Create a path deletion request.")
did, err := uuid.Parse(args[0]) did, err := uuid.Parse(args[0])
if err != nil { if err != nil {
log.Fatal(err) spinner.Fail(err)
return err
} }
log.Info(pndAdapter.ChangeOND( resp, err := pndAdapter.ChangeOND(did, ppb.ApiOperation_API_OPERATION_DELETE, args[1])
did, for _, r := range resp.Responses {
ppb.ApiOperation_API_OPERATION_DELETE, if r.Status == ppb.Status_STATUS_OK {
args[1], spinner.Success("A change for path deletion for Device: ", did.String(), "has been created -> Change ID: ", r.GetId())
)) } else {
spinner.Fail("An error occured while creating a path deletion request for Device with ID: ", r.GetId(), r.GetStatus())
}
}
return nil
}, },
} }
......
...@@ -33,7 +33,7 @@ package cmd ...@@ -33,7 +33,7 @@ package cmd
import ( import (
"github.com/google/uuid" "github.com/google/uuid"
log "github.com/sirupsen/logrus" "github.com/pterm/pterm"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/protojson"
) )
...@@ -46,21 +46,37 @@ var deviceGetCmd = &cobra.Command{ ...@@ -46,21 +46,37 @@ var deviceGetCmd = &cobra.Command{
Long: `Requests a path from a specified orchestrated network device on the controller. Long: `Requests a path from a specified orchestrated network device on the controller.
The device UUID and request path must be specified as a positional arguments.`, The device UUID and request path must be specified as a positional arguments.`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
did, err := uuid.Parse(args[0]) did, err := uuid.Parse(args[0])
if err != nil { if err != nil {
log.Fatal(err) pterm.Error.Println(err)
return err
} }
message, err := pndAdapter.Request( res, err := pndAdapter.Request(
did, did,
args[1], args[1],
) )
if err != nil { if err != nil {
log.Error(err) pterm.Error.Println(err)
return err
} }
log.Info(protojson.Format(message)) for _, n := range res.Device {
title := pterm.Sprintf("gNMI Notification for device with ID: ", did)
panel1 := pterm.DefaultBox.WithTitle("Timestamp:").Sprint(n.GetTimestamp())
panel2 := pterm.DefaultBox.WithTitle("Requested Path:").Sprint(args[1])
panel3 := pterm.DefaultBox.WithTitle("Result:").Sprint(protojson.Format(n.Update[0]))
panels, _ := pterm.DefaultPanel.WithPanels(pterm.Panels{
{{Data: panel1}},
{{Data: panel2}},
{{Data: panel3}},
}).Srender()
pterm.DefaultBox.WithTitle(title).WithTitleTopCenter().WithRightPadding(0).WithBottomPadding(0).Println(panels)
}
return nil
}, },
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment