]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: add --dump to crushtool 13726/head
authorLoic Dachary <ldachary@redhat.com>
Wed, 1 Mar 2017 14:16:28 +0000 (15:16 +0100)
committerLoic Dachary <ldachary@redhat.com>
Wed, 1 Mar 2017 16:04:46 +0000 (17:04 +0100)
So it can display the same as ceph osd crush dump from a file instead of
a live cluster. The default format is json-pretty and can be modified
via -f or --format in the same way as the ceph cli.

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/test/cli/crushtool/help.t
src/tools/crushtool.cc

index 1c9c342ec7910b7b4e0568c8a3fc39ba1597f8a9..65323c33482304a0d4005724486b02ca2c7d706f 100755 (executable)
   
   Options for the display/test stage
   
+     -f --format           the format of --dump, defaults to json-pretty
+                           can be one of json, json-pretty, xml, xml-pretty,
+                           table, table-kv, html, html-pretty
+     --dump                dump the crush map
      --tree                print map summary as a tree
      --check [max_id]      check if any item is referencing an unknown name/type
      -i mapfn --show-location id
index 201147392d18b64ef33a2bb681f3661b52021bdb..12eff342fdd9e278ce7673175f4705709afd3584 100644 (file)
@@ -25,6 +25,7 @@
 #include "common/debug.h"
 #include "common/errno.h"
 #include "common/config.h"
+#include "common/Formatter.h"
 
 #include "common/ceph_argparse.h"
 #include "include/stringify.h"
@@ -168,6 +169,10 @@ void usage()
   cout << "\n";
   cout << "Options for the display/test stage\n";
   cout << "\n";
+  cout << "   -f --format           the format of --dump, defaults to json-pretty\n";
+  cout << "                         can be one of json, json-pretty, xml, xml-pretty,\n";
+  cout << "                         table, table-kv, html, html-pretty\n";
+  cout << "   --dump                dump the crush map\n";
   cout << "   --tree                print map summary as a tree\n";
   cout << "   --check [max_id]      check if any item is referencing an unknown name/type\n";
   cout << "   -i mapfn --show-location id\n";
@@ -237,6 +242,8 @@ int main(int argc, const char **argv)
   bool test = false;
   bool display = false;
   bool tree = false;
+  string dump_format = "json-pretty";
+  bool dump = false;
   int full_location = -1;
   bool write_to_file = false;
   int verbose = 0;
@@ -304,6 +311,10 @@ int main(int argc, const char **argv)
       verbose += 1;
     } else if (ceph_argparse_flag(args, i, "--tree", (char*)NULL)) {
       tree = true;
+    } else if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL)) {
+      dump_format = val;
+    } else if (ceph_argparse_flag(args, i, "--dump", (char*)NULL)) {
+      dump = true;
     } else if (ceph_argparse_flag(args, i, "--show_utilization", (char*)NULL)) {
       display = true;
       tester.set_output_utilization(true);
@@ -536,7 +547,7 @@ int main(int argc, const char **argv)
     cerr << "cannot specify more than one of compile, decompile, and build" << std::endl;
     return EXIT_FAILURE;
   }
-  if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree &&
+  if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && !dump &&
       add_item < 0 && full_location < 0 &&
       remove_name.empty() && reweight_name.empty()) {
     cerr << "no action specified; -h for help" << std::endl;
@@ -849,6 +860,15 @@ int main(int argc, const char **argv)
     crush.dump_tree(&cout, NULL);
   }
 
+  if (dump) {
+    boost::scoped_ptr<Formatter> f(Formatter::create(dump_format, "json-pretty", "json-pretty"));
+    f->open_object_section("crush_map");
+    crush.dump(f.get());
+    f->close_section();
+    f->flush(cout);
+    cout << "\n";
+  }
+
   if (decompile) {
     CrushCompiler cc(crush, cerr, verbose);
     if (!outfn.empty()) {