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

Commit

Permalink
Adding CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
rishubhjain committed Jul 12, 2018
1 parent 486e079 commit ef84e98
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions glustercli/cmd/rebalance.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
package cmd

import (
fmt
"fmt"

"github.com/gluster/glusterd2/pkg/restclient"
rebalance "github.com/gluster/glusterd2/plugins/rebalance/api"
)

const (
helpRebalanceCmd = "Gluster Rebalance"
helpRebalanceStartCmd = "Start rebalance session for gluster volume"
helpRebalanceStatusCmd = "Status of rebalance seesion"
helpRebalanceStopCmd = "Stop rebalance session"
helpRebalanceCmd = "Gluster Rebalance"
helpRebalanceStartCmd = "Start rebalance session for gluster volume"
helpRebalanceStatusCmd = "Status of rebalance seesion"
helpRebalanceStopCmd = "Stop rebalance session"
)

(
flagRebalanceStartCmdForce bool
flagRebalanceStartCmdFixLayout bool
var (
flagRebalanceStartCmdForce bool
flagRebalanceStartCmdFixLayout bool
)

var rebalanceCmd = &cobra.Command{
Use: "volume rebalance",
Short: helpRebalanceCmd
Use: "volume rebalance",
Short: helpRebalanceCmd,
}


func init() {

// Rebalance Start
Expand All @@ -36,20 +35,31 @@ func init() {
}

var rebalaceStartCmd = &cobra.Command{
Use: "<VOLNAME> start [flags]",
Short: helpRebalanceStartCmd,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
volname := cmd.Flags().Args()[0]
err := client.VolumeStart(volname, "")
if err != nil {
if verbose {
log.WithError(err.Error()).WithFields(log.Fields{
"volume": volname,
}).Error("rebalance start failed")
Use: "<VOLNAME> start [flags]",
Short: helpRebalanceStartCmd,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
volname := cmd.Flags().Args()[0]
var err error
if flagRebalanceStartCmdForce && flagRebalanceStartCmdFixLayout {
err := errors.New("Conflicting options found")
failure("Please provide only 1 option", err, 1)
}
if flagRebalanceStartCmdForce {
err = client.VolumeStart(volname, "force")
} else if flagRebalanceStartCmdFixLayout {
err = client.VolumeStart(volname, "fix-layout")
} else {
err = client.VolumeStart(volname, "")
}
if err != nil {
if verbose {
log.WithError(err.Error()).WithFields(log.Fields{
"volume": volname,
}).Error("rebalance start failed")
}
failure("rebalance start failed", err, 1)
}
fmt.Printf("Rebalance for %s started successfully\n", volname)
},
},
}

0 comments on commit ef84e98

Please sign in to comment.