diff --git a/cli/adapter/PndAdapter.go b/cli/adapter/PndAdapter.go index 3f4908a24c06538d6aa87fa662c237150b4d2215..601e2d68175e9411d762c1019e0d4399a408c6f1 100644 --- a/cli/adapter/PndAdapter.go +++ b/cli/adapter/PndAdapter.go @@ -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 // 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) if err != nil { return nil, err diff --git a/cli/cmd/deviceCreate.go b/cli/cmd/deviceCreate.go index 15980f11335c1e959bd154c13f41652c4ed8cb9c..19dc2dd35573e35ec794e8f2abdabddcbc235237 100644 --- a/cli/cmd/deviceCreate.go +++ b/cli/cmd/deviceCreate.go @@ -53,6 +53,7 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`, spinner, _ := pterm.DefaultSpinner.Start("Creating new device") err := checkIPPort(address) if err != nil { + spinner.Fail(err) return err } @@ -74,6 +75,7 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`, } sid, err := uuid.Parse(cliSbi) if err != nil { + spinner.Fail(err) return err } @@ -82,13 +84,13 @@ if they diverge from the default credentials (user:'admin' and pw:'arista').`, return err } - if resp.GetStatus() == pnd.Status_STATUS_OK { - // TODO: we should return a ID here, changes needed for AddDevice() - spinner.Success("Device has been created with ID: ") - return nil + for _, r := range resp.GetResponses() { + if r.GetStatus() == pnd.Status_STATUS_OK { + spinner.Success("Device has been created with ID: ", r.GetId()) + } else { + spinner.Fail("An error occured while creating Device with ID: ", r.GetId(), r.GetStatus()) + } } - spinner.Warning("Creating new device: ", resp.GetStatus()) - return nil }, } diff --git a/cli/cmd/deviceDelete.go b/cli/cmd/deviceDelete.go index 1dc333899aa5de5740e9e99515db96df64c43e85..0f939a69723a2b45036cb6830d54bd52594e1935 100644 --- a/cli/cmd/deviceDelete.go +++ b/cli/cmd/deviceDelete.go @@ -34,7 +34,7 @@ package cmd import ( ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" "github.com/google/uuid" - log "github.com/sirupsen/logrus" + "github.com/pterm/pterm" "github.com/spf13/cobra" ) @@ -46,16 +46,22 @@ var deviceDeleteCmd = &cobra.Command{ Long: `Delete a path for a given orchestrated network device. 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]) if err != nil { - log.Fatal(err) + spinner.Fail(err) + return err } - log.Info(pndAdapter.ChangeOND( - did, - ppb.ApiOperation_API_OPERATION_DELETE, - args[1], - )) + resp, err := pndAdapter.ChangeOND(did, ppb.ApiOperation_API_OPERATION_DELETE, args[1]) + for _, r := range resp.Responses { + if r.Status == ppb.Status_STATUS_OK { + 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 }, } diff --git a/cli/cmd/deviceGet.go b/cli/cmd/deviceGet.go index feb2c5c2d1c392d048237fce68fdfe18fc892758..322c17f6c8911f2fee3594cbceec2937682a368d 100644 --- a/cli/cmd/deviceGet.go +++ b/cli/cmd/deviceGet.go @@ -33,7 +33,7 @@ package cmd import ( "github.com/google/uuid" - log "github.com/sirupsen/logrus" + "github.com/pterm/pterm" "github.com/spf13/cobra" "google.golang.org/protobuf/encoding/protojson" ) @@ -46,21 +46,37 @@ var deviceGetCmd = &cobra.Command{ 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.`, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { did, err := uuid.Parse(args[0]) if err != nil { - log.Fatal(err) + pterm.Error.Println(err) + return err } - message, err := pndAdapter.Request( + res, err := pndAdapter.Request( did, args[1], ) 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 }, }