]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: added group image remove by id to CLI
authorRicardo Dias <rdias@suse.com>
Mon, 10 Apr 2017 13:26:52 +0000 (14:26 +0100)
committerRicardo Dias <rdias@suse.com>
Tue, 11 Apr 2017 11:09:41 +0000 (12:09 +0100)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/test/cli/rbd/help.t
src/tools/rbd/Utils.cc
src/tools/rbd/Utils.h
src/tools/rbd/action/Group.cc

index ab89eeff306430946b712bb5686ac42f1462a199..7cc9348cf1d1a41c95f3583eaaee32633795ec6a 100644 (file)
   rbd help group image remove
   usage: rbd group image remove [--group-pool <group-pool>] [--group <group>] 
                                 [--image-pool <image-pool>] [--image <image>] 
-                                [--pool <pool>] 
+                                [--pool <pool>] [--image-id <image-id>] 
                                 <group-spec> <image-spec> 
   
   Remove an image from a consistency group.
     --image-pool arg     image pool name
     --image arg          image name
     -p [ --pool ] arg    pool name unless overridden
+    --image-id arg       image id
   
   rbd help group list
   usage: rbd group list [--pool <pool>] [--format <format>] [--pretty-format] 
index 9f9913fbad306c6694ff7f5368cbb66301558879..82a7bc5189bc3cee46c07bbf55a1c16cbd90dc56 100644 (file)
@@ -987,5 +987,23 @@ uint64_t get_rbd_default_features(CephContext* cct) {
   return boost::lexical_cast<uint64_t>(features);
 }
 
+bool check_if_image_spec_present(const po::variables_map &vm,
+                                 at::ArgumentModifier mod,
+                                 size_t spec_arg_index) {
+  std::string image_key = (mod == at::ARGUMENT_MODIFIER_DEST ?
+    at::DEST_IMAGE_NAME : at::IMAGE_NAME);
+
+  if (vm.count(image_key)) {
+    return true;
+  }
+
+  std::string spec = get_positional_argument(vm, spec_arg_index);
+  if (!spec.empty()) {
+    return true;
+  }
+
+  return false;
+}
+
 } // namespace utils
 } // namespace rbd
index 4f338a23ac49ff4b300a194781a1db42b1a3ebd5..ae677e86e033d1b7508b29e9b3f9d936e286af90 100644 (file)
@@ -183,6 +183,10 @@ bool calc_sparse_extent(const bufferptr &bp,
                         size_t *write_length,
                         size_t *offset);
 
+bool check_if_image_spec_present(const boost::program_options::variables_map &vm,
+                                 argument_types::ArgumentModifier mod,
+                                 size_t spec_arg_index);
+
 std::string image_id(librbd::Image& image);
 
 std::string mirror_image_state(librbd::mirror_image_state_t mirror_image_state);
index 6c77da3ff4d0c0b2bc355a1f35937023acde0a37..9bfb58fc588f48cc2842f556308582097b67a58e 100644 (file)
@@ -188,10 +188,27 @@ int execute_remove_image(const po::variables_map &vm) {
 
   std::string image_name;
   std::string image_pool_name;
+  std::string image_id;
 
-  r = utils::get_special_pool_image_names(vm, &arg_index,
-                                         &image_pool_name,
-                                         &image_name);
+  if (vm.count(at::IMAGE_ID)) {
+    image_id = vm[at::IMAGE_ID].as<std::string>();
+  }
+
+  bool has_image_spec = utils::check_if_image_spec_present(
+      vm, at::ARGUMENT_MODIFIER_NONE, arg_index);
+
+  if (!image_id.empty() && has_image_spec) {
+    std::cerr << "rbd: trying to access image using both name and id. "
+              << std::endl;
+    return -EINVAL;
+  }
+
+  if (image_id.empty()) {
+    r = utils::get_special_pool_image_names(vm, &arg_index, &image_pool_name,
+                                            &image_name);
+  } else {
+    image_pool_name = utils::get_pool_name(vm, &arg_index);
+  }
 
   if (r < 0) {
     std::cerr << "rbd: image remove error: " << cpp_strerror(r) << std::endl;
@@ -213,8 +230,13 @@ int execute_remove_image(const po::variables_map &vm) {
   }
 
   librbd::RBD rbd;
-  r = rbd.group_image_remove(cg_io_ctx, group_name.c_str(),
-                            image_io_ctx, image_name.c_str());
+  if (image_id.empty()) {
+    r = rbd.group_image_remove(cg_io_ctx, group_name.c_str(),
+                               image_io_ctx, image_name.c_str());
+  } else {
+    r = rbd.group_image_remove_by_id(cg_io_ctx, group_name.c_str(),
+                                     image_io_ctx, image_id.c_str());
+  }
   if (r < 0) {
     std::cerr << "rbd: remove image error: " << cpp_strerror(r) << std::endl;
     return r;
@@ -350,6 +372,7 @@ void get_remove_image_arguments(po::options_description *positional,
 
   at::add_pool_option(options, at::ARGUMENT_MODIFIER_NONE,
               " unless overridden");
+  at::add_image_id_option(options);
 }
 
 void get_list_images_arguments(po::options_description *positional,