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

Commit

Permalink
Add CLI command for editing and deleting metadata keys. Currently
Browse files Browse the repository at this point in the history
keys can be edited/deleted one at a time.

Signed-off-by: Vishal Pandey <vpandey@redhat.com>
  • Loading branch information
root committed May 9, 2018
1 parent 11fece9 commit dd54a87
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions glustercli/cmd/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
helpVolumeListCmd = "List all Gluster Volumes"
helpVolumeStatusCmd = "Get Gluster Volume Status"
helpVolumeExpandCmd = "Expand a Gluster Volume"
helpVolumeEditCmd = "Edit Volinfo properties of a Gluster Volume"
)

var (
Expand All @@ -39,6 +40,11 @@ var (
// Expand Command Flags
flagExpandCmdReplicaCount int
flagExpandCmdForce bool

// Edit Command Flags
flagCmdMetadataKey string
flagCmdMetadataValue string
flagCmdDeleteMetadata bool
)

func init() {
Expand Down Expand Up @@ -67,6 +73,12 @@ func init() {
volumeExpandCmd.Flags().BoolVarP(&flagExpandCmdForce, "force", "f", false, "Force")
volumeCmd.AddCommand(volumeExpandCmd)

// Volume Edit
volumeEditCmd.Flags().StringVar(&flagCmdMetadataKey, "key", "", "Metadata Key")
volumeEditCmd.Flags().StringVar(&flagCmdMetadataValue, "value", "", "Metadata Value")
volumeEditCmd.Flags().BoolVar(&flagCmdDeleteMetadata, "delete", false, "Metadata Delete Flag")
volumeCmd.AddCommand(volumeEditCmd)

RootCmd.AddCommand(volumeCmd)
}

Expand Down Expand Up @@ -412,3 +424,28 @@ var volumeExpandCmd = &cobra.Command{
fmt.Printf("%s Volume expanded successfully\n", vol.Name)
},
}

var volumeEditCmd = &cobra.Command{
Use: "edit <volname> flags",
Short: helpVolumeEditCmd,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
volname := args[0]
metadata := make(map[string]string)
metadata[flagCmdMetadataKey] = flagCmdMetadataValue
editMetadataReq := api.VolEditReq{
Metadata: metadata,
MetadataDel: flagCmdDeleteMetadata,
}
_, err := client.EditVolume(volname, editMetadataReq)
if err != nil {
if verbose {
log.WithFields(log.Fields{
"error": err.Error(),
}).Error("failed to edit metadata")
}
failure("Failed to edit metadata", err, 1)
}
fmt.Printf("Metadata edit successfull\n")
},
}

0 comments on commit dd54a87

Please sign in to comment.