Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Adding glustercli command to get options of all volumes
Browse files Browse the repository at this point in the history
Signed-off-by: rishubhjain <rishubhjain47@gmail.com>
  • Loading branch information
rishubhjain committed Dec 14, 2018
1 parent 040c63d commit cd8527b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
52 changes: 34 additions & 18 deletions glustercli/cmd/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,36 +233,52 @@ var volumeDeleteCmd = &cobra.Command{
}

var volumeGetCmd = &cobra.Command{
Use: "get",
Use: "get <VOLNAME|all> <key|all>",
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]

opts, err := client.VolumeGet(volname, optname)
if err != nil {
log.WithError(err).Error("error getting volume options")
failure("Error getting volume options", err, 1)
var volList []string
if volname == "all" {
volInfoList, err := client.Volumes("")
if len(volInfoList) <= 0 {
failure("No volumes found", err, 1)
}
for _, volInfo := range volInfoList {
volList = append(volList, volInfo.Name)
}
} else {
volList = append(volList, volname)
}
for _, volume := range volList {

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
if flagGetMdf && !opt.Modified {
continue
}
if flagGetBsc && opt.OptionLevel == "Basic" {
table.Append([]string{opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel})
opts, err := client.VolumeGet(volume, optname)
if err != nil {
log.WithError(err).Error("error getting volume options")
failure("Error getting volume options", err, 1)
}
if flagGetAdv && opt.OptionLevel == "Advanced" {
table.Append([]string{opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel})

for _, opt := range opts {
//if modified flag is set, discard unmodified options
if flagGetMdf && !opt.Modified {
continue
}
if flagGetBsc && opt.OptionLevel == "Basic" {
table.Append([]string{volume, 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{"-", "-", "-", "-", "-", "-"})
}
table.Render()

Expand Down
2 changes: 1 addition & 1 deletion pkg/restclient/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *Client) ClusterOptionSet(req api.ClusterOptionReq) error {
}

// VolumeGet gets volume options for a Gluster Volume
func (c *Client) VolumeGet(volname string, optname string) (api.VolumeOptionsGetResp, error) {
func (c *Client) VolumeGet(volname, optname string) (api.VolumeOptionsGetResp, error) {
if optname == "all" {
var opts api.VolumeOptionsGetResp
url := fmt.Sprintf("/v1/volumes/%s/options", volname)
Expand Down

0 comments on commit cd8527b

Please sign in to comment.