mirror of https://github.com/ceph/go-ceph
rbd: expose rbd_snap_rename to Go clients
This implements the following method: (snapshot *Snapshot) Rename(destName string) error Signed-off-by: Sanford Miller <smiller@digitalocean.com>
This commit is contained in:
parent
fc91a0661f
commit
68ebb0520a
|
@ -1689,6 +1689,14 @@
|
|||
"name": "Watch.Unwatch",
|
||||
"comment": "Unwatch un-registers the image watch.\n\nImplements:\n int rbd_update_unwatch(rbd_image_t image, uint64_t handle);\n"
|
||||
}
|
||||
],
|
||||
"preview_api": [
|
||||
{
|
||||
"name": "Snapshot.Rename",
|
||||
"comment": "Rename a snapshot.\n PREVIEW\n\nImplements:\n int rbd_snap_rename(rbd_image_t image, const char *snapname, const char* dstsnapsname);\n",
|
||||
"added_in_version": "v0.16.0",
|
||||
"expected_stable_version": "v0.18.0"
|
||||
}
|
||||
]
|
||||
},
|
||||
"rbd/admin": {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
//go:build ceph_preview
|
||||
// +build ceph_preview
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <stdlib.h>
|
||||
// #include <rbd/librbd.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Rename a snapshot.
|
||||
// PREVIEW
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_snap_rename(rbd_image_t image, const char *snapname,
|
||||
// const char* dstsnapsname);
|
||||
func (snapshot *Snapshot) Rename(destName string) error {
|
||||
if err := snapshot.validate(imageNeedsIOContext | imageIsOpen | imageNeedsName | snapshotNeedsName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cSrcName := C.CString(snapshot.name)
|
||||
cDestName := C.CString(destName)
|
||||
defer C.free(unsafe.Pointer(cSrcName))
|
||||
defer C.free(unsafe.Pointer(cDestName))
|
||||
|
||||
err := C.rbd_snap_rename(snapshot.image.image, cSrcName, cDestName)
|
||||
if err != 0 {
|
||||
return getError(err)
|
||||
}
|
||||
|
||||
snapshot.name = destName
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
//go:build ceph_preview
|
||||
// +build ceph_preview
|
||||
|
||||
package rbd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRenameSnapshot(t *testing.T) {
|
||||
conn := radosConnect(t)
|
||||
poolName := GetUUID()
|
||||
err := conn.MakePool(poolName)
|
||||
require.NoError(t, err)
|
||||
ioctx, err := conn.OpenIOContext(poolName)
|
||||
require.NoError(t, err)
|
||||
|
||||
name := GetUUID()
|
||||
err = CreateImage(ioctx, name, 1<<22, NewRbdImageOptions())
|
||||
require.NoError(t, err)
|
||||
|
||||
// create snapshot
|
||||
img, err := OpenImage(ioctx, name, NoSnapshot)
|
||||
require.NoError(t, err)
|
||||
snapshotName := "mysnap"
|
||||
snapshot, err := img.CreateSnapshot(snapshotName)
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify snapshot opens
|
||||
snapImg, err := OpenImage(ioctx, name, snapshotName)
|
||||
require.NoError(t, err)
|
||||
err = snapImg.Close()
|
||||
require.NoError(t, err)
|
||||
|
||||
// rename snapshot
|
||||
newSnapshotName := "myrenamedsnap"
|
||||
err = snapshot.Rename(newSnapshotName)
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify snapshot still opens
|
||||
snapImg, err = OpenImage(ioctx, name, newSnapshotName)
|
||||
require.NoError(t, err)
|
||||
err = snapImg.Close()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = snapshot.Remove()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = img.Close()
|
||||
require.NoError(t, err)
|
||||
err = img.Remove()
|
||||
require.NoError(t, err)
|
||||
|
||||
ioctx.Destroy()
|
||||
err = conn.DeletePool(poolName)
|
||||
require.NoError(t, err)
|
||||
conn.Shutdown()
|
||||
}
|
Loading…
Reference in New Issue