mirror of https://github.com/ceph/go-ceph
rbd: add GroupCreate, GroupRemove, & GroupRename functions
Add GroupCreate implementing rbd_group_create Add GroupRemove implementing rbd_group_remove Add GroupRename implementing rbd_group_rename Naming was <noun><verb> to better match other functions in rbd like NamespaceCreate, etc. even though I don't prefer that ordering ;-). Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
76bca17e43
commit
7eeb5f79ab
|
@ -0,0 +1,53 @@
|
|||
package rbd
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -lrbd
|
||||
#include <stdlib.h>
|
||||
#include <rbd/librbd.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// GroupCreate is used to create an image group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_create(rados_ioctx_t p, const char *name);
|
||||
func GroupCreate(ioctx *rados.IOContext, name string) error {
|
||||
cName := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
|
||||
ret := C.rbd_group_create(cephIoctx(ioctx), cName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupRemove is used to remove an image group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_remove(rados_ioctx_t p, const char *name);
|
||||
func GroupRemove(ioctx *rados.IOContext, name string) error {
|
||||
cName := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
|
||||
ret := C.rbd_group_remove(cephIoctx(ioctx), cName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupRename will rename an existing image group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_rename(rados_ioctx_t p, const char *src_name,
|
||||
// const char *dest_name);
|
||||
func GroupRename(ioctx *rados.IOContext, src, dest string) error {
|
||||
cSrc := C.CString(src)
|
||||
defer C.free(unsafe.Pointer(cSrc))
|
||||
cDest := C.CString(dest)
|
||||
defer C.free(unsafe.Pointer(cDest))
|
||||
|
||||
ret := C.rbd_group_rename(cephIoctx(ioctx), cSrc, cDest)
|
||||
return getError(ret)
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package rbd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGroupCreateRemove(t *testing.T) {
|
||||
conn := radosConnect(t)
|
||||
require.NotNil(t, conn)
|
||||
defer conn.Shutdown()
|
||||
|
||||
poolname := GetUUID()
|
||||
err := conn.MakePool(poolname)
|
||||
require.NoError(t, err)
|
||||
defer conn.DeletePool(poolname)
|
||||
|
||||
ioctx, err := conn.OpenIOContext(poolname)
|
||||
require.NoError(t, err)
|
||||
defer ioctx.Destroy()
|
||||
|
||||
err = GroupCreate(ioctx, "group1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = GroupRemove(ioctx, "group1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = GroupRemove(ioctx, "group2")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = GroupCreate(ioctx, "group2")
|
||||
assert.NoError(t, err)
|
||||
err = GroupCreate(ioctx, "group")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = GroupRemove(ioctx, "group2")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGroupRename(t *testing.T) {
|
||||
conn := radosConnect(t)
|
||||
require.NotNil(t, conn)
|
||||
defer conn.Shutdown()
|
||||
|
||||
poolname := GetUUID()
|
||||
err := conn.MakePool(poolname)
|
||||
require.NoError(t, err)
|
||||
defer conn.DeletePool(poolname)
|
||||
|
||||
ioctx, err := conn.OpenIOContext(poolname)
|
||||
require.NoError(t, err)
|
||||
defer ioctx.Destroy()
|
||||
|
||||
err = GroupCreate(ioctx, "group1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = GroupRename(ioctx, "group1", "club1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = GroupRemove(ioctx, "club1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
// unlike remove, rename does return an error if the src name
|
||||
// doesn't exist
|
||||
err = GroupRename(ioctx, "club1", "nowhere")
|
||||
assert.Error(t, err)
|
||||
}
|
Loading…
Reference in New Issue