Skip to content

Commit

Permalink
Update tridentctl get snapshot usage instructions
Browse files Browse the repository at this point in the history
Update tridentctl get snapshot usage instructions
  • Loading branch information
nazneeninc committed Apr 13, 2021
1 parent f9ca699 commit 47d6c18
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cli/cmd/get_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"os"
"strings"

"github.com/dustin/go-humanize"

Expand All @@ -24,11 +25,12 @@ var getSnapshotVolume string

func init() {
getCmd.AddCommand(getSnapshotCmd)
getSnapshotCmd.Flags().StringVar(&getSnapshotVolume, "volume", "", "Limit query to volume")
getSnapshotCmd.Flags().StringVar(&getSnapshotVolume, "volume", "", "Limit query to volume "+
"(unless additional arguments are provided)")
}

var getSnapshotCmd = &cobra.Command{
Use: "snapshot [<id>...]",
Use: "snapshot [<volume name>/<snapshot name>...]",
Short: "Get one or more snapshots from Trident",
Aliases: []string{"s", "snap", "snapshots"},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -106,8 +108,12 @@ func GetSnapshots(volume string) ([]string, error) {

func GetSnapshot(snapshotID string) (storage.SnapshotExternal, error) {

url := BaseURL() + "/snapshot/" + snapshotID
if !strings.ContainsRune(snapshotID, '/') {
return storage.SnapshotExternal{}, utils.InvalidInputError(fmt.Sprintf("invalid snapshot ID: %s; "+
"Please use the format <volume name>/<snapshot name>", snapshotID))
}

url := BaseURL() + "/snapshot/" + snapshotID
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
if err != nil {
return storage.SnapshotExternal{}, err
Expand Down
22 changes: 22 additions & 0 deletions utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,25 @@ func IsTempOperatorError(err error) bool {
_, ok := err.(*tempOperatorError)
return ok
}

/////////////////////////////////////////////////////////////////////////////
// invalidInputError
/////////////////////////////////////////////////////////////////////////////

type invalidInputError struct {
message string
}

func (e *invalidInputError) Error() string { return e.message }

func InvalidInputError(message string) error {
return &invalidInputError{message}
}

func IsInvalidInputError(err error) bool {
if err == nil {
return false
}
_, ok := err.(*invalidInputError)
return ok
}

0 comments on commit 47d6c18

Please sign in to comment.