ceph: simplify the ceph command execution interface
this adds a structure to hold various settings related to executing ceph cli commands, and introduces a common interface for configuring and running such commands. Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
1 parent
b29ba26b12
commit
c2dbb93096
17 files changed
+155
-111
No files matched your search
@@ -26,7 +26,7 @@ import (
|
||||
// found at the given keyring path. This should not be used when the user may already exist.
|
||||
func AuthAdd(context *clusterd.Context, clusterName, name, keyringPath string, caps []string) error {
|
||||
args := append([]string{"auth", "add", name, "-i", keyringPath}, caps...)
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to auth add for %s: %+v", name, err)
|
||||
}
|
||||
@@ -38,7 +38,11 @@ func AuthAdd(context *clusterd.Context, clusterName, name, keyringPath string, c
|
||||
// user will be written to the given keyring path.
|
||||
func AuthGetOrCreate(context *clusterd.Context, clusterName, name, keyringPath string, caps []string) error {
|
||||
args := append([]string{"auth", "get-or-create", name, "-o", keyringPath}, caps...)
|
||||
_, err := ExecuteCephCommandPlainNoOutputFile(context, clusterName, args)
|
||||
|
||||
cmd := NewCephCommand(context, clusterName, args)
|
||||
cmd.JsonOutput = false
|
||||
cmd.OutputFile = false
|
||||
_, err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to auth get-or-create for %s: %+v", name, err)
|
||||
}
|
||||
@@ -49,7 +53,7 @@ func AuthGetOrCreate(context *clusterd.Context, clusterName, name, keyringPath s
|
||||
// AuthGetKey gets the key for the given user.
|
||||
func AuthGetKey(context *clusterd.Context, clusterName, name string) (string, error) {
|
||||
args := []string{"auth", "get-key", name}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get key for %s: %+v", name, err)
|
||||
}
|
||||
@@ -60,7 +64,7 @@ func AuthGetKey(context *clusterd.Context, clusterName, name string) (string, er
|
||||
// AuthGetOrCreateKey gets or creates the key for the given user.
|
||||
func AuthGetOrCreateKey(context *clusterd.Context, clusterName, name string, caps []string) (string, error) {
|
||||
args := append([]string{"auth", "get-or-create-key", name}, caps...)
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed get-or-create-key %s: %+v", name, err)
|
||||
}
|
||||
@@ -71,7 +75,7 @@ func AuthGetOrCreateKey(context *clusterd.Context, clusterName, name string, cap
|
||||
// AuthUpdateCaps updates the capabilities for the given user.
|
||||
func AuthUpdateCaps(context *clusterd.Context, clusterName, name string, caps []string) error {
|
||||
args := append([]string{"auth", "caps", name}, caps...)
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update caps for %s. %+v", name, err)
|
||||
}
|
||||
@@ -81,7 +85,7 @@ func AuthUpdateCaps(context *clusterd.Context, clusterName, name string, caps []
|
||||
// AuthDelete will delete the given user.
|
||||
func AuthDelete(context *clusterd.Context, clusterName, name string) error {
|
||||
args := []string{"auth", "del", name}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete auth for %s. %v", name, err)
|
||||
}
|
||||
|
||||
@@ -78,75 +78,101 @@ func FinalizeCephCommandArgs(command string, args []string, configDir, clusterNa
|
||||
return command, append(args, configArgs...)
|
||||
}
|
||||
|
||||
// ExecuteCephCommandDebugLog executes the 'ceph' command with 'debug' logs instead of 'info' logs
|
||||
func ExecuteCephCommandDebugLog(context *clusterd.Context, clusterName string, args []string) ([]byte, error) {
|
||||
return executeCephCommandWithOutputFile(context, clusterName, true, args)
|
||||
type CephToolCommand struct {
|
||||
context *clusterd.Context
|
||||
tool string
|
||||
clusterName string
|
||||
args []string
|
||||
timeout time.Duration
|
||||
Debug bool
|
||||
JsonOutput bool
|
||||
OutputFile bool
|
||||
}
|
||||
|
||||
// ExecuteCephCommand executes the 'ceph' command
|
||||
func ExecuteCephCommand(context *clusterd.Context, clusterName string, args []string) ([]byte, error) {
|
||||
return executeCephCommandWithOutputFile(context, clusterName, false, args)
|
||||
func newCephToolCommand(tool string, context *clusterd.Context, clusterName string, args []string, debug bool) *CephToolCommand {
|
||||
return &CephToolCommand{
|
||||
context: context,
|
||||
tool: tool,
|
||||
clusterName: clusterName,
|
||||
args: args,
|
||||
Debug: debug,
|
||||
JsonOutput: true,
|
||||
OutputFile: true,
|
||||
}
|
||||
}
|
||||
|
||||
// ExecuteCephCommandDebug executes the 'ceph' command with debug output
|
||||
func ExecuteCephCommandDebug(context *clusterd.Context, clusterName string, debug bool, args []string) ([]byte, error) {
|
||||
return executeCephCommandWithOutputFile(context, clusterName, debug, args)
|
||||
func NewCephCommand(context *clusterd.Context, clusterName string, args []string) *CephToolCommand {
|
||||
return newCephToolCommand(CephTool, context, clusterName, args, false)
|
||||
}
|
||||
|
||||
// ExecuteCephCommandPlain executes the 'ceph' command and returns stdout in PLAIN format instead of JSON
|
||||
func ExecuteCephCommandPlain(context *clusterd.Context, clusterName string, args []string) ([]byte, error) {
|
||||
command, args := FinalizeCephCommandArgs(CephTool, args, context.ConfigDir, clusterName)
|
||||
args = append(args, "--format", "plain")
|
||||
return executeCommandWithOutputFile(context, false, command, args)
|
||||
func NewRBDCommand(context *clusterd.Context, clusterName string, args []string) *CephToolCommand {
|
||||
cmd := newCephToolCommand(RBDTool, context, clusterName, args, false)
|
||||
cmd.JsonOutput = false
|
||||
cmd.OutputFile = false
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ExecuteCephCommandPlainNoOutputFile executes the 'ceph' command and returns stdout in PLAIN format instead of JSON
|
||||
// with no output file, suppresses '--out-file' option
|
||||
func ExecuteCephCommandPlainNoOutputFile(context *clusterd.Context, clusterName string, args []string) ([]byte, error) {
|
||||
command, args := FinalizeCephCommandArgs(CephTool, args, context.ConfigDir, clusterName)
|
||||
args = append(args, "--format", "plain")
|
||||
return executeCommand(context, command, args)
|
||||
func (c *CephToolCommand) run() ([]byte, error) {
|
||||
command, args := FinalizeCephCommandArgs(c.tool, c.args, c.context.ConfigDir, c.clusterName)
|
||||
if c.JsonOutput {
|
||||
args = append(args, "--format", "json")
|
||||
} else {
|
||||
// the `rbd` tool doesn't use special flag for plain format
|
||||
if c.tool != RBDTool {
|
||||
args = append(args, "--format", "plain")
|
||||
}
|
||||
}
|
||||
|
||||
var output string
|
||||
var err error
|
||||
|
||||
if c.OutputFile {
|
||||
if command == Kubectl {
|
||||
// Kubectl commands targeting the toolbox container generate a temp
|
||||
// file in the wrong place, so we will instead capture the output
|
||||
// from stdout for the tests
|
||||
if c.timeout == 0 {
|
||||
output, err = c.context.Executor.ExecuteCommandWithOutput(c.Debug, "", command, args...)
|
||||
} else {
|
||||
output, err = c.context.Executor.ExecuteCommandWithTimeout(c.Debug, c.timeout, "", command, args...)
|
||||
}
|
||||
} else {
|
||||
if c.timeout == 0 {
|
||||
output, err = c.context.Executor.ExecuteCommandWithOutputFile(c.Debug, "", command, "--out-file", args...)
|
||||
} else {
|
||||
output, err = c.context.Executor.ExecuteCommandWithOutputFileTimeout(c.Debug, c.timeout, "", command, "--out-file", args...)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if c.timeout == 0 {
|
||||
output, err = c.context.Executor.ExecuteCommandWithOutput(c.Debug, "", command, args...)
|
||||
} else {
|
||||
output, err = c.context.Executor.ExecuteCommandWithTimeout(c.Debug, c.timeout, "", command, args...)
|
||||
}
|
||||
}
|
||||
|
||||
return []byte(output), err
|
||||
}
|
||||
|
||||
func executeCephCommandWithOutputFile(context *clusterd.Context, clusterName string, debug bool, args []string) ([]byte, error) {
|
||||
command, args := FinalizeCephCommandArgs(CephTool, args, context.ConfigDir, clusterName)
|
||||
args = append(args, "--format", "json")
|
||||
return executeCommandWithOutputFile(context, debug, command, args)
|
||||
func (c *CephToolCommand) Run() ([]byte, error) {
|
||||
c.timeout = 0
|
||||
return c.run()
|
||||
}
|
||||
|
||||
// ExecuteRBDCommand executes the 'rbd' command
|
||||
func ExecuteRBDCommand(context *clusterd.Context, clusterName string, args []string) ([]byte, error) {
|
||||
command, args := FinalizeCephCommandArgs(RBDTool, args, context.ConfigDir, clusterName)
|
||||
args = append(args, "--format", "json")
|
||||
return executeCommand(context, command, args)
|
||||
func (c *CephToolCommand) RunWithTimeout(timeout time.Duration) ([]byte, error) {
|
||||
c.timeout = timeout
|
||||
return c.run()
|
||||
}
|
||||
|
||||
// ExecuteRBDCommandNoFormat executes the 'rbd' command and returns stdout in PLAIN format
|
||||
func ExecuteRBDCommandNoFormat(context *clusterd.Context, clusterName string, args []string) ([]byte, error) {
|
||||
command, args := FinalizeCephCommandArgs(RBDTool, args, context.ConfigDir, clusterName)
|
||||
return executeCommand(context, command, args)
|
||||
}
|
||||
|
||||
// ExecuteRBDCommandWithTimeout executes the 'rbd' command with a timeout of 1 minute
|
||||
// ExecuteRBDCommandWithTimeout executes the 'rbd' command with a timeout of 1
|
||||
// minute. This method is left as a special case in which the caller has fully
|
||||
// configured its arguments. It is future work to integrate this case into the
|
||||
// generalization.
|
||||
func ExecuteRBDCommandWithTimeout(context *clusterd.Context, clusterName string, args []string) (string, error) {
|
||||
output, err := context.Executor.ExecuteCommandWithTimeout(false, cmdExecuteTimeout, "", RBDTool, args...)
|
||||
return output, err
|
||||
}
|
||||
|
||||
func executeCommand(context *clusterd.Context, command string, args []string) ([]byte, error) {
|
||||
output, err := context.Executor.ExecuteCommandWithOutput(false, "", command, args...)
|
||||
return []byte(output), err
|
||||
}
|
||||
|
||||
func executeCommandWithOutputFile(context *clusterd.Context, debug bool, command string, args []string) ([]byte, error) {
|
||||
if command == Kubectl {
|
||||
// Kubectl commands targeting the toolbox container generate a temp file in the wrong place, so we will instead capture the output from stdout for the tests
|
||||
return executeCommand(context, command, args)
|
||||
}
|
||||
output, err := context.Executor.ExecuteCommandWithOutputFile(debug, "", command, "--out-file", args...)
|
||||
return []byte(output), err
|
||||
}
|
||||
|
||||
func ExecuteCephCommandWithRetry(
|
||||
cmd func() ([]byte, error),
|
||||
getExitCode func(err error) (int, bool),
|
||||
|
||||
@@ -128,7 +128,7 @@ type CrushFindResult struct {
|
||||
func GetCrushMap(context *clusterd.Context, clusterName string) (CrushMap, error) {
|
||||
var c CrushMap
|
||||
args := []string{"osd", "crush", "dump"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return c, fmt.Errorf("failed to get crush map. %v", err)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func GetCrushMap(context *clusterd.Context, clusterName string) (CrushMap, error
|
||||
|
||||
func SetCrushMap(context *clusterd.Context, clusterName, compiledMap string) (string, error) {
|
||||
args := []string{"osd", "setcrushmap", "-i", compiledMap}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return string(buf), fmt.Errorf("failed to set compiled crushmap. %v", err)
|
||||
}
|
||||
@@ -153,7 +153,9 @@ func SetCrushMap(context *clusterd.Context, clusterName, compiledMap string) (st
|
||||
|
||||
func SetCrushTunables(context *clusterd.Context, clusterName, profile string) (string, error) {
|
||||
args := []string{"osd", "crush", "tunables", profile}
|
||||
buf, err := ExecuteCephCommandPlain(context, clusterName, args)
|
||||
cmd := NewCephCommand(context, clusterName, args)
|
||||
cmd.JsonOutput = false
|
||||
buf, err := cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%+v, %s", err, string(buf))
|
||||
}
|
||||
@@ -163,14 +165,14 @@ func SetCrushTunables(context *clusterd.Context, clusterName, profile string) (s
|
||||
|
||||
func CrushReweight(context *clusterd.Context, clusterName string, id int, weight float64) (string, error) {
|
||||
args := []string{"osd", "crush", "reweight", fmt.Sprintf("osd.%d", id), fmt.Sprintf("%.1f", weight)}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
|
||||
return string(buf), err
|
||||
}
|
||||
|
||||
func CrushRemove(context *clusterd.Context, clusterName, name string) (string, error) {
|
||||
args := []string{"osd", "crush", "rm", name}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to crush rm: %+v, %s", err, string(buf))
|
||||
}
|
||||
@@ -180,7 +182,7 @@ func CrushRemove(context *clusterd.Context, clusterName, name string) (string, e
|
||||
|
||||
func FindOSDInCrushMap(context *clusterd.Context, clusterName string, osdID int) (*CrushFindResult, error) {
|
||||
args := []string{"osd", "find", strconv.Itoa(osdID)}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find osd.%d in crush map: %+v, %s", osdID, err, string(buf))
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ type CephErasureCodeProfile struct {
|
||||
|
||||
func ListErasureCodeProfiles(context *clusterd.Context, clusterName string) ([]string, error) {
|
||||
args := []string{"osd", "erasure-code-profile", "ls"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list erasure-code-profiles: %+v", err)
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func ListErasureCodeProfiles(context *clusterd.Context, clusterName string) ([]s
|
||||
|
||||
func GetErasureCodeProfileDetails(context *clusterd.Context, clusterName, name string) (CephErasureCodeProfile, error) {
|
||||
args := []string{"osd", "erasure-code-profile", "get", name}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return CephErasureCodeProfile{}, fmt.Errorf("failed to get erasure-code-profile for '%s': %+v", name, err)
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func CreateErasureCodeProfile(context *clusterd.Context, clusterName string, con
|
||||
|
||||
args := []string{"osd", "erasure-code-profile", "set", name}
|
||||
args = append(args, profilePairs...)
|
||||
_, err = ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set ec-profile. %+v", err)
|
||||
}
|
||||
@@ -98,7 +98,9 @@ func CreateErasureCodeProfile(context *clusterd.Context, clusterName string, con
|
||||
func DeleteErasureCodeProfile(context *clusterd.Context, clusterName string, erasureCodeProfile string) error {
|
||||
args := []string{"osd", "erasure-code-profile", "rm", erasureCodeProfile}
|
||||
|
||||
buf, err := ExecuteCephCommandPlain(context, clusterName, args)
|
||||
cmd := NewCephCommand(context, clusterName, args)
|
||||
cmd.JsonOutput = false
|
||||
buf, err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete erasure-code-profile %s. Output: %s. Error: %+v", erasureCodeProfile, string(buf), err)
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ type MDSInfo struct {
|
||||
// ListFilesystems lists all filesystems provided by the Ceph cluster.
|
||||
func ListFilesystems(context *clusterd.Context, clusterName string) ([]CephFilesystem, error) {
|
||||
args := []string{"fs", "ls"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list filesystems: %+v", err)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func ListFilesystems(context *clusterd.Context, clusterName string) ([]CephFiles
|
||||
// GetFilesystem gets detailed status information about a Ceph filesystem.
|
||||
func GetFilesystem(context *clusterd.Context, clusterName string, fsName string) (*CephFilesystemDetails, error) {
|
||||
args := []string{"fs", "get", fsName}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get file system %s: %+v", fsName, err)
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func GetFilesystem(context *clusterd.Context, clusterName string, fsName string)
|
||||
// AllowStandbyReplay gets detailed status information about a Ceph filesystem.
|
||||
func AllowStandbyReplay(context *clusterd.Context, clusterName string, fsName string, allowStandbyReplay bool) error {
|
||||
args := []string{"fs", "set", fsName, "allow_standby_replay", strconv.FormatBool(allowStandbyReplay)}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set allow_standby_replay to filesystem %s: %+v", fsName, err)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func CreateFilesystem(context *clusterd.Context, clusterName, name, metadataPool
|
||||
if IsMultiFSEnabled() {
|
||||
// enable multiple file systems in case this is not the first
|
||||
args = []string{"fs", "flag", "set", "enable_multiple", "true", confirmFlag}
|
||||
_, err = ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
// continue if this fails
|
||||
logger.Warning("failed enabling multiple file systems. %+v", err)
|
||||
@@ -141,7 +141,7 @@ func CreateFilesystem(context *clusterd.Context, clusterName, name, metadataPool
|
||||
|
||||
// create the filesystem
|
||||
args = []string{"fs", "new", name, metadataPool, dataPools[0]}
|
||||
_, err = ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed enabling ceph fs %s. %+v", name, err)
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func CreateFilesystem(context *clusterd.Context, clusterName, name, metadataPool
|
||||
for i := 1; i < len(dataPools); i++ {
|
||||
poolName := dataPools[i]
|
||||
args = []string{"fs", "add_data_pool", name, poolName}
|
||||
_, err = ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
logger.Errorf("failed to add pool %s to file system %s. %+v", poolName, name, err)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func SetNumMDSRanks(context *clusterd.Context, cephVersion cephver.CephVersion,
|
||||
|
||||
// Always tell Ceph to set the new max_mds value
|
||||
args := []string{"fs", "set", fsName, "max_mds", strconv.Itoa(int(activeMDSCount))}
|
||||
if _, err := ExecuteCephCommand(context, clusterName, args); err != nil {
|
||||
if _, err := NewCephCommand(context, clusterName, args).Run(); err != nil {
|
||||
return fmt.Errorf("failed to set filesystem %s num mds ranks (max_mds) to %d: %v",
|
||||
fsName, activeMDSCount, err)
|
||||
}
|
||||
@@ -231,7 +231,7 @@ func deactivateMdsWithRetry(context *clusterd.Context, mdsGid int, namespace, fs
|
||||
var err error
|
||||
for i := 1; i <= retries; i++ {
|
||||
args := []string{"mds", "deactivate", fmt.Sprintf("%s:%d", fsName, mdsGid)}
|
||||
if _, err = ExecuteCephCommand(context, namespace, args); err == nil {
|
||||
if _, err = NewCephCommand(context, namespace, args).Run(); err == nil {
|
||||
logger.Infof("successfully disabled mds with rank %d on attempt %d", mdsGid, i)
|
||||
return nil
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func activeRanksSuccess(upCount, desiredRanks int, moreIsOkay bool) bool {
|
||||
// MarkFilesystemAsDown marks a Ceph filesystem as down.
|
||||
func MarkFilesystemAsDown(context *clusterd.Context, clusterName string, fsName string) error {
|
||||
args := []string{"fs", "set", fsName, "cluster_down", "true"}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set file system %s to cluster_down: %+v", fsName, err)
|
||||
}
|
||||
@@ -302,7 +302,7 @@ func MarkFilesystemAsDown(context *clusterd.Context, clusterName string, fsName
|
||||
// FailMDS instructs Ceph to fail an mds daemon.
|
||||
func FailMDS(context *clusterd.Context, clusterName string, gid int) error {
|
||||
args := []string{"mds", "fail", strconv.Itoa(gid)}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fail mds %d: %+v", gid, err)
|
||||
}
|
||||
@@ -314,7 +314,7 @@ func FailMDS(context *clusterd.Context, clusterName string, gid int) error {
|
||||
// of Ceph onwards.
|
||||
func FailFilesystem(context *clusterd.Context, clusterName, fsName string) error {
|
||||
args := []string{"fs", "fail", fsName}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fail filesystem %s: %+v", fsName, err)
|
||||
}
|
||||
@@ -330,7 +330,7 @@ func RemoveFilesystem(context *clusterd.Context, clusterName, fsName string) err
|
||||
}
|
||||
|
||||
args := []string{"fs", "rm", fsName, confirmFlag}
|
||||
_, err = ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to delete ceph fs %s. err=%+v", fsName, err)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@ type CephBlockImage struct {
|
||||
|
||||
func ListImages(context *clusterd.Context, clusterName, poolName string) ([]CephBlockImage, error) {
|
||||
args := []string{"ls", "-l", poolName}
|
||||
buf, err := ExecuteRBDCommand(context, clusterName, args)
|
||||
cmd := NewRBDCommand(context, clusterName, args)
|
||||
cmd.JsonOutput = true
|
||||
buf, err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list images for pool %s: %+v", poolName, err)
|
||||
}
|
||||
@@ -86,7 +88,7 @@ func CreateImage(context *clusterd.Context, clusterName, name, poolName, dataPoo
|
||||
args = append(args, fmt.Sprintf("--data-pool=%s", dataPoolName))
|
||||
}
|
||||
|
||||
buf, err := ExecuteRBDCommandNoFormat(context, clusterName, args)
|
||||
buf, err := NewRBDCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
cmdErr, ok := err.(*exec.CommandError)
|
||||
if ok && cmdErr.ExitStatus() == int(syscall.EEXIST) {
|
||||
@@ -104,7 +106,7 @@ func CreateImage(context *clusterd.Context, clusterName, name, poolName, dataPoo
|
||||
func DeleteImage(context *clusterd.Context, clusterName, name, poolName string) error {
|
||||
imageSpec := getImageSpec(name, poolName)
|
||||
args := []string{"rm", imageSpec}
|
||||
buf, err := ExecuteRBDCommandNoFormat(context, clusterName, args)
|
||||
buf, err := NewRBDCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete image %s in pool %s: %+v. output: %s",
|
||||
name, poolName, err, string(buf))
|
||||
|
||||
@@ -59,12 +59,12 @@ func MgrSetConfig(context *clusterd.Context, clusterName, mgrName string, cephVe
|
||||
|
||||
// Retrieve previous value to monitor changes
|
||||
var prevVal string
|
||||
buf, err := ExecuteCephCommand(context, clusterName, getArgs)
|
||||
buf, err := NewCephCommand(context, clusterName, getArgs).Run()
|
||||
if err == nil {
|
||||
prevVal = strings.TrimSpace(string(buf))
|
||||
}
|
||||
|
||||
if _, err := ExecuteCephCommand(context, clusterName, setArgs); err != nil {
|
||||
if _, err := NewCephCommand(context, clusterName, setArgs).Run(); err != nil {
|
||||
return false, fmt.Errorf("failed to set mgr config key %s to \"%s\": %+v", key, val, err)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func enableModule(context *clusterd.Context, clusterName, name string, force boo
|
||||
if force {
|
||||
args = append(args, "--force")
|
||||
}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to mgr module enable for %s: %+v", name, err)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,9 @@ type MonMapEntry struct {
|
||||
// GetMonStatus calls mon_status mon_command
|
||||
func GetMonStatus(context *clusterd.Context, clusterName string, debug bool) (MonStatusResponse, error) {
|
||||
args := []string{"mon_status"}
|
||||
buf, err := executeCephCommandWithOutputFile(context, clusterName, debug, args)
|
||||
cmd := NewCephCommand(context, clusterName, args)
|
||||
cmd.Debug = debug
|
||||
buf, err := cmd.Run()
|
||||
if err != nil {
|
||||
return MonStatusResponse{}, fmt.Errorf("mon status failed. %+v", err)
|
||||
}
|
||||
@@ -84,7 +86,7 @@ type MonTimeSkewStatus struct {
|
||||
|
||||
func GetMonTimeStatus(context *clusterd.Context, clusterName string) (*MonTimeStatus, error) {
|
||||
args := []string{"time-sync-status"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get time sync status: %+v", err)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (dump *OSDDump) StatusByID(id int64) (int64, int64, error) {
|
||||
|
||||
func GetOSDUsage(context *clusterd.Context, clusterName string) (*OSDUsage, error) {
|
||||
args := []string{"osd", "df"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get osd df: %+v", err)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func GetOSDUsage(context *clusterd.Context, clusterName string) (*OSDUsage, erro
|
||||
|
||||
func GetOSDPerfStats(context *clusterd.Context, clusterName string) (*OSDPerfStats, error) {
|
||||
args := []string{"osd", "perf"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get osd perf: %+v", err)
|
||||
}
|
||||
@@ -123,7 +123,9 @@ func GetOSDPerfStats(context *clusterd.Context, clusterName string) (*OSDPerfSta
|
||||
|
||||
func GetOSDDump(context *clusterd.Context, clusterName string) (*OSDDump, error) {
|
||||
args := []string{"osd", "dump"}
|
||||
buf, err := executeCephCommandWithOutputFile(context, clusterName, true, args)
|
||||
cmd := NewCephCommand(context, clusterName, args)
|
||||
cmd.Debug = true
|
||||
buf, err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get osd dump: %+v", err)
|
||||
}
|
||||
@@ -138,13 +140,13 @@ func GetOSDDump(context *clusterd.Context, clusterName string) (*OSDDump, error)
|
||||
|
||||
func OSDOut(context *clusterd.Context, clusterName string, osdID int) (string, error) {
|
||||
args := []string{"osd", "out", strconv.Itoa(osdID)}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
return string(buf), err
|
||||
}
|
||||
|
||||
func OSDRemove(context *clusterd.Context, clusterName string, osdID int) (string, error) {
|
||||
args := []string{"osd", "rm", strconv.Itoa(osdID)}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
return string(buf), err
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ type PGDumpBrief struct {
|
||||
|
||||
func GetPGDumpBrief(context *clusterd.Context, clusterName string) ([]PGDumpBrief, error) {
|
||||
args := []string{"pg", "dump", "pgs_brief"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get pg dump: %+v", err)
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ type CephStoragePoolStats struct {
|
||||
|
||||
func ListPoolSummaries(context *clusterd.Context, clusterName string) ([]CephStoragePoolSummary, error) {
|
||||
args := []string{"osd", "lspools"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list pools: %+v", err)
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func GetPoolNamesByID(context *clusterd.Context, clusterName string) (map[int]st
|
||||
|
||||
func GetPoolDetails(context *clusterd.Context, clusterName, name string) (CephStoragePoolDetails, error) {
|
||||
args := []string{"osd", "pool", "get", name, "all"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return CephStoragePoolDetails{}, fmt.Errorf("failed to get pool %s details: %+v", name, err)
|
||||
}
|
||||
@@ -159,14 +159,14 @@ func DeletePool(context *clusterd.Context, clusterName string, name string) erro
|
||||
|
||||
logger.Infof("purging pool %s (id=%d)", name, pool.Number)
|
||||
args := []string{"osd", "pool", "delete", name, name, reallyConfirmFlag}
|
||||
_, err = ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete pool %s. %+v", name, err)
|
||||
}
|
||||
|
||||
// remove the crush rule for this pool and ignore the error in case the rule is still in use or not found
|
||||
args = []string{"osd", "crush", "rule", "rm", name}
|
||||
_, err = ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
logger.Infof("did not delete crush rule %s. %+v", name, err)
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func DeletePool(context *clusterd.Context, clusterName string, name string) erro
|
||||
|
||||
func givePoolAppTag(context *clusterd.Context, clusterName string, poolName string, appName string) error {
|
||||
args := []string{"osd", "pool", "application", "enable", poolName, appName, confirmFlag}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to enable application %s on pool %s. %+v", appName, poolName, err)
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func givePoolAppTag(context *clusterd.Context, clusterName string, poolName stri
|
||||
func CreateECPoolForApp(context *clusterd.Context, clusterName string, newPool CephStoragePoolDetails, appName string, enableECOverwrite bool, erasureCodedConfig model.ErasureCodedPoolConfig) error {
|
||||
args := []string{"osd", "pool", "create", newPool.Name, strconv.Itoa(newPool.Number), "erasure", newPool.ErasureCodeProfile}
|
||||
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create EC pool %s. %+v", newPool.Name, err)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func CreateReplicatedPoolForApp(context *clusterd.Context, clusterName string, n
|
||||
|
||||
args := []string{"osd", "pool", "create", newPool.Name, strconv.Itoa(newPool.Number), "replicated", newPool.Name}
|
||||
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create replicated pool %s. %+v", newPool.Name, err)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func createReplicationCrushRule(context *clusterd.Context, clusterName string, n
|
||||
}
|
||||
|
||||
args := []string{"osd", "crush", "rule", "create-simple", ruleName, crushRoot, failureDomain}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create crush rule %s. %+v", ruleName, err)
|
||||
}
|
||||
@@ -265,7 +265,7 @@ func createReplicationCrushRule(context *clusterd.Context, clusterName string, n
|
||||
|
||||
func SetPoolProperty(context *clusterd.Context, clusterName, name, propName string, propVal string) error {
|
||||
args := []string{"osd", "pool", "set", name, propName, propVal}
|
||||
_, err := ExecuteCephCommand(context, clusterName, args)
|
||||
_, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set pool property %s on pool %s, %+v", propName, name, err)
|
||||
}
|
||||
@@ -274,7 +274,7 @@ func SetPoolProperty(context *clusterd.Context, clusterName, name, propName stri
|
||||
|
||||
func GetPoolStats(context *clusterd.Context, clusterName string) (*CephStoragePoolStats, error) {
|
||||
args := []string{"df", "detail"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get pool stats: %+v", err)
|
||||
}
|
||||
|
||||
@@ -125,7 +125,9 @@ type PgStateEntry struct {
|
||||
|
||||
func Status(context *clusterd.Context, clusterName string, debug bool) (CephStatus, error) {
|
||||
args := []string{"status"}
|
||||
buf, err := ExecuteCephCommandDebug(context, clusterName, debug, args)
|
||||
cmd := NewCephCommand(context, clusterName, args)
|
||||
cmd.Debug = debug
|
||||
buf, err := cmd.Run()
|
||||
if err != nil {
|
||||
return CephStatus{}, fmt.Errorf("failed to get status: %+v", err)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ type CephUsage struct {
|
||||
|
||||
func Usage(context *clusterd.Context, clusterName string) (*CephUsage, error) {
|
||||
args := []string{"df", "detail"}
|
||||
buf, err := ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get usage: %+v", err)
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ func initializeOSD(config *osdConfig, context *clusterd.Context, cluster *cephco
|
||||
func createOSD(context *clusterd.Context, clusterName string, osdUUID uuid.UUID) (int, error) {
|
||||
// TODO: "entity": "client.bootstrap-osd",
|
||||
args := []string{"osd", "create", osdUUID.String()}
|
||||
buf, err := client.ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := client.NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to create osd %s: %+v", osdUUID, err)
|
||||
}
|
||||
@@ -589,7 +589,7 @@ func createOSD(context *clusterd.Context, clusterName string, osdUUID uuid.UUID)
|
||||
func getMonMap(context *clusterd.Context, clusterName string) ([]byte, error) {
|
||||
// TODO: "entity": "client.bootstrap-osd",
|
||||
args := []string{"mon", "getmap"}
|
||||
buf, err := client.ExecuteCephCommand(context, clusterName, args)
|
||||
buf, err := client.NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get mon map: %+v", err)
|
||||
}
|
||||
@@ -652,7 +652,7 @@ func addOSDToCrushMap(context *clusterd.Context, config *osdConfig, clusterName,
|
||||
osdEntity, osdDataPath, totalBytes, weight, location)
|
||||
args := []string{"osd", "crush", "create-or-move", strconv.Itoa(osdID), fmt.Sprintf("%.4f", weight)}
|
||||
args = append(args, strings.Split(location, " ")...)
|
||||
_, err = client.ExecuteCephCommand(context, clusterName, args)
|
||||
_, err = client.NewCephCommand(context, clusterName, args).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed adding %s to crush map: %+v", osdEntity, err)
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func (c *Cluster) createSelfSignedCert() (bool, error) {
|
||||
|
||||
// retry a few times in the case that the mgr module is not ready to accept commands
|
||||
for i := 0; i < 5; i++ {
|
||||
_, err := client.ExecuteCephCommand(c.context, c.Namespace, args)
|
||||
_, err := client.NewCephCommand(c.context, c.Namespace, args).Run()
|
||||
if err != nil {
|
||||
exitCode, parsed := c.exitCode(err)
|
||||
if parsed {
|
||||
@@ -222,7 +222,9 @@ func (c *Cluster) setLoginCredentials(password string) error {
|
||||
// retry a few times in the case that the mgr module is not ready to accept commands
|
||||
_, err := client.ExecuteCephCommandWithRetry(func() ([]byte, error) {
|
||||
args := []string{"dashboard", "set-login-credentials", dashboardUsername, password}
|
||||
return client.ExecuteCephCommandDebugLog(c.context, c.Namespace, args)
|
||||
cmd := client.NewCephCommand(c.context, c.Namespace, args)
|
||||
cmd.Debug = true
|
||||
return cmd.Run()
|
||||
}, c.exitCode, 5, invalidArgErrorCode, dashboardInitWaitTime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set login creds on mgr. %+v", err)
|
||||
|
||||
@@ -49,7 +49,7 @@ func (c *Cluster) configureOrchestratorModules() error {
|
||||
// retry a few times in the case that the mgr module is not ready to accept commands
|
||||
_, err := client.ExecuteCephCommandWithRetry(func() ([]byte, error) {
|
||||
args := []string{"orchestrator", "set", "backend", "rook"}
|
||||
return client.ExecuteCephCommand(c.context, c.Namespace, args)
|
||||
return client.NewCephCommand(c.context, c.Namespace, args).Run()
|
||||
}, c.exitCode, 5, invalidArgErrorCode, orchestratorInitWaitTime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set rook as the orchestrator backend. %+v", err)
|
||||
|
||||
@@ -359,7 +359,7 @@ func (c *Cluster) removeMon(daemonName string) error {
|
||||
func removeMonitorFromQuorum(context *clusterd.Context, clusterName, name string) error {
|
||||
logger.Debugf("removing monitor %s", name)
|
||||
args := []string{"mon", "remove", name}
|
||||
if _, err := client.ExecuteCephCommand(context, clusterName, args); err != nil {
|
||||
if _, err := client.NewCephCommand(context, clusterName, args).Run(); err != nil {
|
||||
return fmt.Errorf("mon %s remove failed: %+v", name, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user