diff --git a/doc/endpoints.md b/doc/endpoints.md index dd69067d7..15511049a 100644 --- a/doc/endpoints.md +++ b/doc/endpoints.md @@ -44,9 +44,12 @@ SnapshotInfo | GET | /snapshots/{snapname} | [](https://godoc.org/github.com/glu SnapshotListAll | GET | /snapshots | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [SnapListResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#SnapListResp) SnapshotStatus | GET | /snapshots/{snapname}/status | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [SnapStatusResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#SnapStatusResp) SnapshotDelete | DELETE | /snapshots/{snapname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) -SnapshotConfigGet | GET | /snapshots/config | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) -SnapshotConfigSet | POST | /snapshots/config | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) -SnapshotConfigReset | DELETE | /snapshots/config | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) +LabelCreate | POST | /snapshots/labels/create | [LabelCreateReq](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelCreateReq) | [LabelCreateResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelCreateResp) +LabelInfo | GET | snapshots/labels/{labelname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [LabelGetResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelGetResp) +LabelListAll | GET | snapshots/labels/list | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [LabelListResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelListResp) +LabelDelete | DELETE | snapshots/labels/{labelname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) +LabelConfigSet | POST | snapshots/labels/{labelname}/config | [LabelSetReq](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelSetReq) | [LabelConfigResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelConfigResp) +LabelConfigReset | DELETE | snapshots/labels/{labelname}/config | [LabelResetReq](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelResetReq) | [LabelConfigResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#LabelConfigResp) GetPeer | GET | /peers/{peerid} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [PeerGetResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#PeerGetResp) GetPeers | GET | /peers | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [PeerListResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#PeerListResp) DeletePeer | DELETE | /peers/{peerid} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) diff --git a/glustercli/cmd/label-create.go b/glustercli/cmd/label-create.go new file mode 100644 index 000000000..c30ad9523 --- /dev/null +++ b/glustercli/cmd/label-create.go @@ -0,0 +1,66 @@ +package cmd + +import ( + "fmt" + + "github.com/gluster/glusterd2/pkg/api" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + labelCreateHelpShort = "Create a label" + labelCreateHelpLong = "Create a label that can use to tag different objects. Label values will be created with default values if choose to omit, specific label values should provide using relevant flags." +) + +var ( + flagSnapMaxHardLimit uint64 + flagSnapMaxSoftLimit uint64 + flagActivateOnCreate bool + flagAutoDelete bool + flagDescription string + + labelCreateCmd = &cobra.Command{ + Use: "create ", + Short: labelCreateHelpShort, + Long: labelCreateHelpLong, + Args: cobra.MinimumNArgs(1), + Run: labelCreateCmdRun, + } +) + +func init() { + labelCreateCmd.Flags().Uint64Var(&flagSnapMaxHardLimit, "snap-max-hard-limit", 256, "Snapshot maximum hard limit count") + labelCreateCmd.Flags().Uint64Var(&flagSnapMaxSoftLimit, "snap-max-soft-limit", 230, "Snapshot maximum soft limit count") + labelCreateCmd.Flags().BoolVar(&flagActivateOnCreate, "activate-on-create", false, "If enabled, Further snapshots will be activated after creation") + labelCreateCmd.Flags().BoolVar(&flagAutoDelete, "auto-delete", false, "If enabled, Snapshots will be deleted upon reaching snap-max-soft-limit. If disabled A warning log will be generated") + labelCreateCmd.Flags().StringVar(&flagDescription, "description", "", "Label description") + + labelCmd.AddCommand(labelCreateCmd) +} + +func labelCreateCmdRun(cmd *cobra.Command, args []string) { + labelname := args[0] + + req := api.LabelCreateReq{ + Name: labelname, + SnapMaxHardLimit: flagSnapMaxHardLimit, + SnapMaxSoftLimit: flagSnapMaxSoftLimit, + ActivateOnCreate: flagActivateOnCreate, + AutoDelete: flagAutoDelete, + Description: flagDescription, + } + + info, err := client.LabelCreate(req) + if err != nil { + if GlobalFlag.Verbose { + log.WithError(err).WithFields( + log.Fields{ + "labelname": labelname, + }).Error("label creation failed") + } + failure("Label creation failed", err, 1) + } + fmt.Printf("%s Label created successfully\n", info.Name) +} diff --git a/glustercli/cmd/label-delete.go b/glustercli/cmd/label-delete.go new file mode 100644 index 000000000..95aceb22f --- /dev/null +++ b/glustercli/cmd/label-delete.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "fmt" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + labelDeleteHelpShort = "Delete labels" +) + +var ( + labelDeleteCmd = &cobra.Command{ + Use: "delete ", + Short: labelDeleteHelpShort, + Args: cobra.ExactArgs(1), + Run: labelDeleteCmdRun, + } +) + +func init() { + labelCmd.AddCommand(labelDeleteCmd) +} + +func labelDeleteCmdRun(cmd *cobra.Command, args []string) { + labelname := args[0] + + if err := client.LabelDelete(labelname); err != nil { + if GlobalFlag.Verbose { + log.WithError(err).WithField( + "label", labelname).Error("label delete failed") + } + failure("Label delete failed", err, 1) + } + fmt.Printf("%s Label deleted successfully\n", labelname) +} diff --git a/glustercli/cmd/label-info.go b/glustercli/cmd/label-info.go new file mode 100644 index 000000000..fce58267d --- /dev/null +++ b/glustercli/cmd/label-info.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + + "github.com/gluster/glusterd2/pkg/api" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + labelInfoHelpShort = "Get Gluster Label Info" +) + +var ( + labelInfoCmd = &cobra.Command{ + Use: "info ", + Short: labelInfoHelpShort, + Args: cobra.ExactArgs(1), + Run: labelInfoCmdRun, + } +) + +func init() { + labelCmd.AddCommand(labelInfoCmd) +} + +func labelInfoDisplay(info *api.LabelGetResp) { + fmt.Println() + fmt.Println("Label Name:", info.Name) + fmt.Println("Snap Max Hard Limit:", info.SnapMaxHardLimit) + fmt.Println("Snap Max Soft Limit:", info.SnapMaxSoftLimit) + fmt.Println("Auto Delete:", info.AutoDelete) + fmt.Println("Activate On Create:", info.ActivateOnCreate) + fmt.Println("Snapshot List:", info.SnapList) + fmt.Println("Description:", info.Description) + fmt.Println() + + return +} + +func labelInfoHandler(cmd *cobra.Command) error { + var info api.LabelGetResp + var err error + + labelname := cmd.Flags().Args()[0] + info, err = client.LabelInfo(labelname) + if err != nil { + return err + } + labelInfoDisplay(&info) + return err +} + +func labelInfoCmdRun(cmd *cobra.Command, args []string) { + if err := labelInfoHandler(cmd); err != nil { + if GlobalFlag.Verbose { + log.WithError(err).Error("error getting label info") + } + failure("Error getting Label info", err, 1) + } +} diff --git a/glustercli/cmd/label-list.go b/glustercli/cmd/label-list.go new file mode 100644 index 000000000..3cd429d3c --- /dev/null +++ b/glustercli/cmd/label-list.go @@ -0,0 +1,61 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/gluster/glusterd2/pkg/api" + "github.com/olekukonko/tablewriter" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + helpLabelListCmd = "List all Gluster Labels" +) + +func init() { + + labelCmd.AddCommand(labelListCmd) + +} + +func labelListHandler(cmd *cobra.Command) error { + var infos api.LabelListResp + var err error + + infos, err = client.LabelList() + if err != nil { + return err + } + + table := tablewriter.NewWriter(os.Stdout) + table.SetAutoMergeCells(true) + table.SetRowLine(true) + if len(infos) == 0 { + fmt.Println("There are no labels in the system") + return nil + } + table.SetHeader([]string{"Name"}) + for _, info := range infos { + table.Append([]string{info.Name}) + } + table.Render() + return err +} + +var labelListCmd = &cobra.Command{ + Use: "list", + Short: helpLabelListCmd, + Args: cobra.NoArgs, + Run: labelListCmdRun, +} + +func labelListCmdRun(cmd *cobra.Command, args []string) { + if err := labelListHandler(cmd); err != nil { + if GlobalFlag.Verbose { + log.WithError(err).Error("error getting label list") + } + failure("Error getting Label list", err, 1) + } +} diff --git a/glustercli/cmd/label-reset.go b/glustercli/cmd/label-reset.go new file mode 100644 index 000000000..6fb458880 --- /dev/null +++ b/glustercli/cmd/label-reset.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "errors" + "fmt" + + "github.com/gluster/glusterd2/pkg/api" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + labelResetCmdHelpShort = "Reset value of label configuratio options" + labelResetCmdHelpLong = "Reset options on a specified gluster snapshot label. Needs a label name and at least one option" +) + +var labelResetCmd = &cobra.Command{ + Use: "reset ", + Short: labelResetCmdHelpShort, + Long: labelResetCmdHelpLong, + Args: cobra.RangeArgs(1, 2), + Run: func(cmd *cobra.Command, args []string) { + var req api.LabelResetReq + labelname := args[0] + options := args[1:] + if len(args) < 2 { + failure("Specify atleast one label option to reset", errors.New("Specify atleast one label option to reset"), 1) + } else { + req.Configurations = options + } + + err := client.LabelReset(req, labelname) + if err != nil { + if GlobalFlag.Verbose { + log.WithError(err).WithField("label", labelname).Error("label reset failed") + } + failure("Snapshot label reset failed", err, 1) + } + fmt.Printf("Snapshot label options reset successfully\n") + }, +} + +func init() { + labelCmd.AddCommand(labelResetCmd) +} diff --git a/glustercli/cmd/label-set.go b/glustercli/cmd/label-set.go new file mode 100644 index 000000000..e7079ebeb --- /dev/null +++ b/glustercli/cmd/label-set.go @@ -0,0 +1,73 @@ +package cmd + +import ( + "errors" + "fmt" + + "github.com/gluster/glusterd2/pkg/api" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + labelSetHelpShort = "Set a label value" + labelSetHelpLong = "Modify one or more label value ." +) + +var ( + labelSetCmd = &cobra.Command{ + Use: "set