Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
heketi cli: add commands to get and set server admin modes
The command `heketi-cli server mode get` will print out the server's
current administrative mode.
The command `heketi-cli server mode set VALUE` will set the server's
administrative mode. Supported modes are "normal", "local-client",
and "read-only".

Signed-off-by: John Mulligan <jmulligan@redhat.com>
  • Loading branch information
phlogistonjohn authored and raghavendra-talur committed Aug 10, 2018
1 parent f888240 commit b743623
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions client/cli/go/cmds/server.go
Expand Up @@ -13,9 +13,12 @@
package cmds

import (
"fmt"
"os"
"text/template"

"github.com/heketi/heketi/pkg/glusterfs/api"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -60,10 +63,65 @@ var operationsInfoCommand = &cobra.Command{
},
}

var modeCommand = &cobra.Command{
Use: "mode",
Short: "Manage server mode",
Long: "Manage server mode",
}

var getModeCommand = &cobra.Command{
Use: "get",
Short: "Print current server mode",
Long: "Print current server mode",
Example: ` $ heketi-cli server operations info`,
RunE: func(cmd *cobra.Command, args []string) error {
heketi, err := newHeketiClient()
if err != nil {
return err
}
adminStatus, err := heketi.AdminStatusGet()
if err != nil {
return err
}
fmt.Printf("%v\n", adminStatus.State)
return nil
},
}

var setModeCommand = &cobra.Command{
Use: "set [normal|local-client|read-only]",
Short: "Print current server mode",
Long: "Print current server mode",
Example: ` $ heketi-cli server operations info`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("missing mode argument")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments")
}
heketi, err := newHeketiClient()
if err != nil {
return err
}
value := api.AdminState(args[0])
err = heketi.AdminStatusSet(&api.AdminStatus{State: value})
return err
},
}

func init() {
RootCmd.AddCommand(serverCommand)
// operations command(s)
serverCommand.AddCommand(operationsCommand)
operationsCommand.SilenceUsage = true
operationsCommand.AddCommand(operationsInfoCommand)
operationsInfoCommand.SilenceUsage = true
// admin mode command(s)
serverCommand.AddCommand(modeCommand)
modeCommand.SilenceUsage = true
modeCommand.AddCommand(getModeCommand)
getModeCommand.SilenceUsage = true
modeCommand.AddCommand(setModeCommand)
setModeCommand.SilenceUsage = true
}

0 comments on commit b743623

Please sign in to comment.