Skip to content

Commit

Permalink
util/cephcmd: implement CreateObject() with go-ceph
Browse files Browse the repository at this point in the history
Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic committed Jan 27, 2020
1 parent 8d82e0b commit 1ab621e
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions pkg/util/cephcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"os/exec"
"strings"
"time"

"github.com/ceph/go-ceph/rados"
Expand Down Expand Up @@ -230,27 +229,27 @@ func RemoveOMapKey(ctx context.Context, monitors string, cr *Credentials, poolNa
// CreateObject creates the object name passed in and returns ErrObjectExists if the provided object
// is already present in rados
func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, objectName string) error {
// Command: "rados <options> create objectName"
args := []string{
"-m", monitors,
"--id", cr.ID,
"--keyfile=" + cr.KeyFile,
"-c", CephConfigPath,
"-p", poolName,
"create", objectName,
conn, unique, err := connPool.Get(poolName, monitors, cr.KeyFile)
if err != nil {
return err
}
defer connPool.Put(unique)

ioctx, err := conn.OpenIOContext(poolName)
if err != nil {
return err
}
defer ioctx.Destroy()

if namespace != "" {
args = append(args, "--namespace="+namespace)
ioctx.SetNamespace(namespace)
}

_, stderr, err := ExecCommand("rados", args[:]...)
if err != nil {
err = ioctx.Create(objectName, rados.RadosCreateExclusive)
if err == rados.RadosErrorObjectExist {
return ErrObjectExists{objectName, err}
} else if err != nil {
klog.Errorf(Log(ctx, "failed creating omap (%s) in pool (%s): (%v)"), objectName, poolName, err)
if strings.Contains(string(stderr), "error creating "+poolName+"/"+objectName+
": (17) File exists") {
return ErrObjectExists{objectName, err}
}
return err
}

Expand Down

0 comments on commit 1ab621e

Please sign in to comment.