]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add 'group rename' action to CLI and Python API 20577/head
authorsongweibin <song.weibin@zte.com.cn>
Sat, 24 Feb 2018 02:44:30 +0000 (10:44 +0800)
committersongweibin <song.weibin@zte.com.cn>
Mon, 26 Feb 2018 02:21:58 +0000 (10:21 +0800)
Signed-off-by: songweibin <song.weibin@zte.com.cn>
doc/man/8/rbd.rst
qa/workunits/rbd/rbd_groups.sh
src/pybind/rbd/rbd.pyx
src/test/cli/rbd/help.t
src/test/pybind/test_rbd.py
src/tools/rbd/action/Group.cc

index 95a35ab8e1cda35b309c7c90e7c3dafea965582e..1f2ba758f0e78def8bb536e2ddd8083c3d8cd0b1 100644 (file)
@@ -282,6 +282,9 @@ Commands
 :command:`group ls` [-p | --pool *pool-name*]
   List rbd groups.
 
+:command:`group rename` *src-group-spec* *dest-group-spec*
+  Rename a group.  Note: rename across pools is not supported.
+
 :command:`group rm` *group-spec*
   Delete a group.
 
index 3b12d206449d80e63554fb825018cf76a0fb405b..c41389d549fcf3b2dafc2977f8f60189bc6a677b 100755 (executable)
@@ -33,6 +33,14 @@ remove_group()
     rbd group remove $group_name
 }
 
+rename_group()
+{
+    local src_name=$1
+    local dest_name=$2
+
+    rbd group rename $src_name $dest_name
+}
+
 check_group_does_not_exist()
 {
     local group_name=$1
@@ -145,10 +153,13 @@ check_snapshot_not_in_group()
 
 echo "TEST: create remove consistency group"
 group="test_consistency_group"
+new_group="test_new_consistency_group"
 create_group $group
 check_group_exists $group
-remove_group $group
-check_group_does_not_exist $group
+rename_group $group $new_group
+check_group_exists $new_group
+remove_group $new_group
+check_group_does_not_exist $new_group
 echo "PASSED"
 
 echo "TEST: add remove images to consistency group"
index 8da4e6514573110cddca73e5237dbc22b3d9952d..14f77caa6874a8ef7abca5177a5c385bb295ef5c 100644 (file)
@@ -413,6 +413,7 @@ cdef extern from "rbd/librbd.h" nogil:
     int rbd_group_create(rados_ioctx_t p, const char *name)
     int rbd_group_remove(rados_ioctx_t p, const char *name)
     int rbd_group_list(rados_ioctx_t p, char *names, size_t *size)
+    int rbd_group_rename(rados_ioctx_t p, const char *src, const char *dest)
     void rbd_group_info_cleanup(rbd_group_info_t *group_info,
                                 size_t group_info_size)
     int rbd_group_image_add(rados_ioctx_t group_p, const char *group_name,
@@ -1410,6 +1411,32 @@ class RBD(object):
         finally:
             free(c_names)
 
+    def group_rename(self, ioctx, src, dest):
+        """
+        Rename an RBD group.
+
+        :param ioctx: determines which RADOS pool the group is in
+        :type ioctx: :class:`rados.Ioctx`
+        :param src: the current name of the group
+        :type src: str
+        :param dest: the new name of the group
+        :type dest: str
+        :raises: :class:`ObjectExists`
+        :raises: :class:`ObjectNotFound`
+        :raises: :class:`InvalidArgument`
+        :raises: :class:`FunctionNotSupported`
+        """
+        src = cstr(src, 'src')
+        dest = cstr(dest, 'dest')
+        cdef:
+            rados_ioctx_t _ioctx = convert_ioctx(ioctx)
+            char *_src = src
+            char *_dest = dest
+        with nogil:
+            ret = rbd_group_rename(_ioctx, _src, _dest)
+        if ret != 0:
+            raise make_ex(ret, 'error renaming group')
+
 cdef class MirrorPeerIterator(object):
     """
     Iterator over mirror peer info for a pool.
index 231321fa5a53c87be767d783b18358f432d2660f..f87d3347c614a85fd0506f4743682ff66589b932 100644 (file)
@@ -30,6 +30,7 @@
       group image remove (group image rm) Remove an image from a group.
       group list (group ls)               List rbd groups.
       group remove (group rm)             Delete a group.
+      group rename                        Rename a group within pool.
       group snap create                   Make a snapshot of a group.
       group snap list (group snap ls)     List snapshots of a group.
       group snap remove (group snap rm)   Remove a snapshot from a group.
     -p [ --pool ] arg    pool name
     --group arg          group name
   
+  rbd help group rename
+  usage: rbd group rename [--pool <pool>] [--group <group>] 
+                          [--dest-pool <dest-pool>] [--dest-group <dest-group>] 
+                          <source-group-spec> <dest-group-spec> 
+  
+  Rename a group within pool.
+  
+  Positional arguments
+    <source-group-spec>  source group specification
+                         (example: [<pool-name>/]<group-name>)
+    <dest-group-spec>    destination group specification
+                         (example: [<pool-name>/]<group-name>)
+  
+  Optional arguments
+    -p [ --pool ] arg    source pool name
+    --group arg          source group name
+    --dest-pool arg      destination pool name
+    --dest-group arg     destination group name
+  
   rbd help group snap create
   usage: rbd group snap create [--pool <pool>] [--group <group>] [--snap <snap>] 
                                <group-snap-spec> 
index 3a71bee7abf9c31cc0c81958e3c096deaaf926c1..6ce6c32c9d5cc22d7c964dc1caa1d4504c5a200c 100644 (file)
@@ -101,6 +101,10 @@ def remove_group():
     if group_name is not None:
         RBD().group_remove(ioctx, group_name)
 
+def rename_group():
+    new_group_name = "new" + group_name
+    RBD().group_rename(ioctx, group_name, new_group_name)
+
 def require_new_format():
     def wrapper(fn):
         def _require_new_format(*args, **kwargs):
@@ -1719,6 +1723,15 @@ def test_create_group():
     create_group()
     remove_group()
 
+def test_rename_group():
+    create_group()
+    if group_name is not None:
+        rename_group()
+        eq(["new" + group_name], RBD().group_list(ioctx))
+        RBD().group_remove(ioctx, "new" + group_name)
+    else:
+        remove_group()
+
 def test_list_groups_empty():
     eq([], RBD().group_list(ioctx))
 
index 1d77cef5739d03744393b1161afd8cc17648fbd5..04217f7bcce7dd04e2764a3b59a1414203b4481c 100644 (file)
@@ -124,6 +124,57 @@ int execute_remove(const po::variables_map &vm,
   return 0;
 }
 
+int execute_rename(const po::variables_map &vm,
+                   const std::vector<std::string> &ceph_global_init_args) {
+  size_t arg_index = 0;
+
+  std::string group_name;
+  std::string pool_name;
+
+  int r = utils::get_pool_group_names(vm, at::ARGUMENT_MODIFIER_NONE,
+                                      &arg_index, &pool_name, &group_name,
+                                      nullptr);
+  if (r < 0) {
+    return r;
+  }
+
+  std::string dest_group_name;
+  std::string dest_pool_name;
+
+  r = utils::get_pool_group_names(vm, at::ARGUMENT_MODIFIER_NONE,
+                                  &arg_index, &dest_pool_name,
+                                  &dest_group_name, nullptr);
+  if (r < 0) {
+    return r;
+  }
+
+  if (pool_name != dest_pool_name) {
+    std::cerr << "rbd: group rename across pools not supported" << std::endl
+              << "source pool: " << pool_name<< ", dest pool: " << dest_pool_name
+              << std::endl;
+    return -EINVAL;
+  }
+
+  librados::Rados rados;
+  librados::IoCtx io_ctx;
+  r = utils::init(pool_name, &rados, &io_ctx);
+  if (r < 0) {
+    return r;
+  }
+
+  librbd::RBD rbd;
+  r = rbd.group_rename(io_ctx, group_name.c_str(),
+                       dest_group_name.c_str());
+
+  if (r < 0) {
+    std::cerr << "rbd: failed to rename group: "
+              << cpp_strerror(r) << std::endl;
+    return r;
+  }
+
+  return 0;
+}
+
 int execute_add(const po::variables_map &vm,
                 const std::vector<std::string> &ceph_global_init_args) {
   size_t arg_index = 0;
@@ -560,6 +611,14 @@ void get_list_arguments(po::options_description *positional,
   at::add_format_options(options);
 }
 
+void get_rename_arguments(po::options_description *positional,
+                          po::options_description *options) {
+  at::add_group_spec_options(positional, options, at::ARGUMENT_MODIFIER_SOURCE,
+                             false);
+  at::add_group_spec_options(positional, options, at::ARGUMENT_MODIFIER_DEST,
+                             false);
+}
+
 void get_add_arguments(po::options_description *positional,
                        po::options_description *options) {
   positional->add_options()
@@ -651,6 +710,9 @@ Shell::Action action_remove(
 Shell::Action action_list(
   {"group", "list"}, {"group", "ls"}, "List rbd groups.",
   "", &get_list_arguments, &execute_list);
+Shell::Action action_rename(
+  {"group", "rename"}, {}, "Rename a group within pool.",
+  "", &get_rename_arguments, &execute_rename);
 Shell::Action action_add(
   {"group", "image", "add"}, {}, "Add an image to a group.",
   "", &get_add_arguments, &execute_add);