util: implement RemoveObject() with go-ceph

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-02 10:02:02 +02:00 committed by mergify[bot]
parent 926f1e813c
commit 6e24b10364

View File

@ -249,27 +249,31 @@ func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolNam
// RemoveObject removes the entire omap name passed in and returns ErrObjectNotFound is provided omap // RemoveObject removes the entire omap name passed in and returns ErrObjectNotFound is provided omap
// is not found in rados // is not found in rados
func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName string) error { func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName string) error {
// Command: "rados <options> rm oMapName" conn := ClusterConnection{}
args := []string{ err := conn.Connect(monitors, cr)
"-m", monitors, if err != nil {
"--id", cr.ID, return err
"--keyfile=" + cr.KeyFile,
"-c", CephConfigPath,
"-p", poolName,
"rm", oMapName,
} }
defer conn.Destroy()
ioctx, err := conn.GetIoctx(poolName)
if err != nil {
if _, ok := err.(ErrPoolNotFound); ok {
err = ErrObjectNotFound{poolName, err}
}
return err
}
defer ioctx.Destroy()
if namespace != "" { if namespace != "" {
args = append(args, "--namespace="+namespace) ioctx.SetNamespace(namespace)
} }
_, stderr, err := ExecCommand("rados", args[:]...) err = ioctx.Delete(oMapName)
if err != nil { if err == rados.ErrNotFound {
klog.Errorf(Log(ctx, "failed removing omap (%s) in pool (%s): (%v)"), oMapName, poolName, err)
if strings.Contains(string(stderr), "error removing "+poolName+">"+oMapName+
": (2) No such file or directory") {
return ErrObjectNotFound{oMapName, err} return ErrObjectNotFound{oMapName, err}
} } else if err != nil {
klog.Errorf(Log(ctx, "failed removing omap (%s) in pool (%s): (%v)"), oMapName, poolName, err)
return err return err
} }