mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 14:20:19 +00:00
util: implement CreateObject() with go-ceph
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
6e24b10364
commit
be703d1e42
@ -219,27 +219,31 @@ func RemoveOMapKey(ctx context.Context, monitors string, cr *Credentials, poolNa
|
|||||||
// CreateObject creates the object name passed in and returns ErrObjectExists if the provided object
|
// CreateObject creates the object name passed in and returns ErrObjectExists if the provided object
|
||||||
// is already present in rados
|
// is already present in rados
|
||||||
func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, objectName string) error {
|
func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, objectName string) error {
|
||||||
// Command: "rados <options> create objectName"
|
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,
|
|
||||||
"create", objectName,
|
|
||||||
}
|
}
|
||||||
|
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.Create(objectName, rados.CreateExclusive)
|
||||||
if err != nil {
|
if err == rados.ErrObjectExists {
|
||||||
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 ErrObjectExists{objectName, err}
|
||||||
}
|
} else if err != nil {
|
||||||
|
klog.Errorf(Log(ctx, "failed creating omap (%s) in pool (%s): (%v)"), objectName, poolName, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user