From f1d991b9189987385577ed305321da399c599cd2 Mon Sep 17 00:00:00 2001 From: rishubhjain Date: Fri, 14 Dec 2018 08:21:19 -0500 Subject: [PATCH] Resource name should not be among the reserveed GD2 keywords Signed-off-by: rishubhjain --- glustercli/cmd/volume.go | 18 ++++++++---------- glusterd2/commands/volumes/volume-create.go | 6 ++++++ pkg/utils/utils.go | 10 ++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/glustercli/cmd/volume.go b/glustercli/cmd/volume.go index 156189fc2..35248a701 100644 --- a/glustercli/cmd/volume.go +++ b/glustercli/cmd/volume.go @@ -237,13 +237,9 @@ var volumeGetCmd = &cobra.Command{ Short: helpVolumeGetCmd, Args: cobra.ExactArgs(2), Run: func(cmd *cobra.Command, args []string) { - - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Volume Name", "Name", "Modified", "Value", "Default Value", "Option Level"}) - table.SetAlignment(tablewriter.ALIGN_LEFT) - volname := args[0] optname := args[1] + table := tablewriter.NewWriter(os.Stdout) var volList []string if volname == "all" { @@ -259,11 +255,15 @@ var volumeGetCmd = &cobra.Command{ } for _, volume := range volList { + fmt.Println("Volume :", volume) opts, err := client.VolumeGet(volume, optname) if err != nil { log.WithError(err).Error("error getting volume options") failure("Error getting volume options", err, 1) } + table = tablewriter.NewWriter(os.Stdout) + table.SetHeader([]string{"Name", "Modified", "Value", "Default Value", "Option Level"}) + table.SetAlignment(tablewriter.ALIGN_LEFT) for _, opt := range opts { //if modified flag is set, discard unmodified options @@ -271,17 +271,15 @@ var volumeGetCmd = &cobra.Command{ continue } if flagGetBsc && opt.OptionLevel == "Basic" { - table.Append([]string{volume, opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel}) + table.Append([]string{opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel}) } if flagGetAdv && opt.OptionLevel == "Advanced" { - table.Append([]string{volume, opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel}) + table.Append([]string{opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel}) } } - table.Append([]string{"-", "-", "-", "-", "-", "-"}) + table.Render() } - table.Render() - }, } diff --git a/glusterd2/commands/volumes/volume-create.go b/glusterd2/commands/volumes/volume-create.go index 716175e81..fe4e7f610 100644 --- a/glusterd2/commands/volumes/volume-create.go +++ b/glusterd2/commands/volumes/volume-create.go @@ -2,6 +2,7 @@ package volumecommands import ( "errors" + "fmt" "net/http" "path/filepath" "strconv" @@ -42,6 +43,11 @@ func validateVolCreateReq(req *api.VolCreateReq) error { return gderrors.ErrInvalidVolName } + if gutils.IsReservedKeyword(req.Name) { + errMsg := fmt.Sprintf("invalid name, volume name cannot be among GD2 reserved keywords:%v", gutils.ReservedKeywords) + return errors.New(errMsg) + } + if req.Transport != "" && req.Transport != "tcp" && req.Transport != "rdma" { return errors.New("invalid transport. Supported values: tcp or rdma") } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index a515aa4b6..6c75872c7 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -31,6 +31,16 @@ const ( TiB = 1024 * GiB ) +var ( + ReservedKeywords = []string{"all", "volume", "status", "list"} +) + +// IsReservedKeyword returns true if the resource name is one of the +// GD2 Reserved Keyword +func IsReservedKeyword(resourceName string) bool { + return StringInSlice(resourceName, ReservedKeywords) +} + // IsLocalAddress checks whether a given host/IP is local // Does lookup only after string matching IP addresses func IsLocalAddress(address string) (bool, error) {