Skip to content

Commit

Permalink
util: use go-ceph for SetOMapKeyValue()
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 17, 2020
1 parent 4a59150 commit 2cee603
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/util/cephcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,25 @@ func GetPoolName(ctx context.Context, monitors string, cr *Credentials, poolID i

// SetOMapKeyValue sets the given key and value into the provided Ceph omap name
func SetOMapKeyValue(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName, oMapKey, keyValue string) error {
// Command: "rados <options> setomapval oMapName oMapKey keyValue"
args := []string{
"-m", monitors,
"--id", cr.ID,
"--keyfile=" + cr.KeyFile,
"-c", CephConfigPath,
"-p", poolName,
"setomapval", oMapName, oMapKey, keyValue,
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)
}

_, _, err := ExecCommand("rados", args[:]...)
pair := make(map[string][]byte, 1)
pair[oMapKey] = []byte(keyValue)
err = ioctx.SetOmap(oMapName, pair)
if err != nil {
klog.Errorf(Log(ctx, "failed adding key (%s with value %s), to omap (%s) in "+
"pool (%s): (%v)"), oMapKey, keyValue, oMapName, poolName, err)
Expand Down

0 comments on commit 2cee603

Please sign in to comment.