]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osdmaptool: dump 'osd tree' in specified format
authorKefu Chai <kchai@redhat.com>
Wed, 20 May 2015 06:16:14 +0000 (14:16 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 28 May 2015 08:39:35 +0000 (01:39 -0700)
* so we are able to dump more info from osdmap using this tool,
  and this allows us to reproduce the behavior of "ceph osd tree".
* add a test for 'osdmaptool --tree=<format> filepath'

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/cli/osdmaptool/tree.t [new file with mode: 0644]
src/tools/osdmaptool.cc

diff --git a/src/test/cli/osdmaptool/tree.t b/src/test/cli/osdmaptool/tree.t
new file mode 100644 (file)
index 0000000..00eb0be
--- /dev/null
@@ -0,0 +1,19 @@
+  $ osdmaptool --createsimple 3 om
+  osdmaptool: osdmap file 'om'
+  osdmaptool: writing epoch 1 to om
+
+  $ osdmaptool --tree=plain om
+  osdmaptool: osdmap file 'om'
+  ID WEIGHT  TYPE NAME              UP/DOWN REWEIGHT PRIMARY-AFFINITY 
+  -1 3.00000 root default                                             
+  -3 3.00000     rack localrack                                       
+  -2 3.00000         host localhost                                   
+   0 1.00000             osd.0          DNE        0                  
+   1 1.00000             osd.1          DNE        0                  
+   2 1.00000             osd.2          DNE        0                  
+
+  $ osdmaptool --tree=json om
+  osdmaptool: osdmap file 'om'
+  {"nodes":[{"id":-1,"name":"default","type":"root","type_id":10,"children":[-3]},{"id":-3,"name":"localrack","type":"rack","type_id":3,"children":[-2]},{"id":-2,"name":"localhost","type":"host","type_id":1,"children":[2,1,0]},{"id":0,"name":"osd.0","type":"osd","type_id":0,"crush_weight":1.000000,"depth":3,"exists":0,"status":"down","reweight":0.000000,"primary_affinity":1.000000},{"id":1,"name":"osd.1","type":"osd","type_id":0,"crush_weight":1.000000,"depth":3,"exists":0,"status":"down","reweight":0.000000,"primary_affinity":1.000000},{"id":2,"name":"osd.2","type":"osd","type_id":0,"crush_weight":1.000000,"depth":3,"exists":0,"status":"down","reweight":0.000000,"primary_affinity":1.000000}],"stray":[]}
+  $ rm -f om
+
index 14331c33200530350ca3cb50a75952569285322e..fd344c99fc8d767125c60986cefffc25a16cf53b 100644 (file)
@@ -55,6 +55,7 @@ int main(int argc, const char **argv)
   bool print = false;
   bool print_json = false;
   bool tree = false;
+  boost::scoped_ptr<Formatter> tree_formatter;
   bool createsimple = false;
   bool create_from_conf = false;
   int num_osd = 0;
@@ -84,8 +85,11 @@ int main(int argc, const char **argv)
       print = true;
     } else if (ceph_argparse_flag(args, i, "--dump-json", (char*)NULL)) {
       print_json = true;
-    } else if (ceph_argparse_flag(args, i, "--tree", (char*)NULL)) {
+    } else if (ceph_argparse_witharg(args, i, &val, err, "--tree", (char*)NULL)) {
       tree = true;
+      if (!val.empty() && val != "plain") {
+       tree_formatter.reset(Formatter::create(val, "", "json"));
+      }
     } else if (ceph_argparse_witharg(args, i, &num_osd, err, "--createsimple", (char*)NULL)) {
       if (!err.str().empty()) {
        cerr << err.str() << std::endl;
@@ -465,9 +469,17 @@ int main(int argc, const char **argv)
     osdmap.print(cout);
   if (print_json)
     osdmap.dump_json(cout);
-  if (tree) 
-    osdmap.print_tree(&cout, NULL);
-
+  if (tree) {
+    if (tree_formatter) {
+      tree_formatter->open_object_section("tree");
+      osdmap.print_tree(NULL, tree_formatter.get());
+      tree_formatter->close_section();
+      tree_formatter->flush(cout);
+      cout << std::endl;
+    } else {
+      osdmap.print_tree(&cout, NULL);
+    }
+  }
   if (modified) {
     bl.clear();
     osdmap.encode(bl, CEPH_FEATURES_SUPPORTED_DEFAULT | CEPH_FEATURE_RESERVED);