]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados command: Add format support for ls operation 2456/head
authorDavid Zafman <dzafman@redhat.com>
Tue, 9 Sep 2014 18:10:16 +0000 (11:10 -0700)
committerDavid Zafman <dzafman@redhat.com>
Mon, 20 Oct 2014 17:47:51 +0000 (10:47 -0700)
Signed-off-by: David Zafman <dzafman@redhat.com>
src/tools/rados/rados.cc

index 6afcc0ed21016dc39ed8897a8cdbbe3a7b2e0dca..ec793cc49871445c0ecf3530fa9a379192727cb9 100644 (file)
@@ -1613,17 +1613,28 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
       outstream = new ofstream(nargs[1]);
 
     {
+      if (formatter)
+        formatter->open_array_section("objects");
       try {
        librados::NObjectIterator i = io_ctx.nobjects_begin();
        librados::NObjectIterator i_end = io_ctx.nobjects_end();
        for (; i != i_end; ++i) {
-         // Only include namespace in output when wildcard specified
-         if (wildcard)
-           *outstream << i->get_nspace() << "\t";
-         *outstream << i->get_oid();
-         if (i->get_locator().size())
-           *outstream << "\t" << i->get_locator();
-         *outstream << std::endl;
+         if (!formatter) {
+           // Only include namespace in output when wildcard specified
+           if (wildcard)
+             *outstream << i->get_nspace() << "\t";
+           *outstream << i->get_oid();
+           if (i->get_locator().size())
+             *outstream << "\t" << i->get_locator();
+           *outstream << std::endl;
+         } else {
+           formatter->open_object_section("object");
+           formatter->dump_string("namespace", i->get_nspace());
+           formatter->dump_string("name", i->get_oid());
+           if (i->get_locator().size())
+             formatter->dump_string("locator", i->get_locator());
+           formatter->close_section(); //object
+         }
        }
       }
       catch (const std::runtime_error& e) {
@@ -1632,6 +1643,13 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
        goto out;
       }
     }
+    if (formatter) {
+      formatter->close_section(); //objects
+      formatter->flush(*outstream);
+      if (pretty_format)
+       *outstream << std::endl;
+      formatter->flush(*outstream);
+    }
     if (!stdout)
       delete outstream;
   }