diff mbox series

[ovs-dev,RFC,51/52] ovsdb-tool: Add new "db-name" and "schema-name" commands.

Message ID 20170919220125.32535-52-blp@ovn.org
State RFC
Headers show
Series clustering implementation | expand

Commit Message

Ben Pfaff Sept. 19, 2017, 10:01 p.m. UTC
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 NEWS                  |  1 +
 ovsdb/ovsdb-tool.1.in |  4 ++++
 ovsdb/ovsdb-tool.c    | 26 ++++++++++++++++++++++++++
 3 files changed, 31 insertions(+)
diff mbox series

Patch

diff --git a/NEWS b/NEWS
index fc8db4965737..d7d594546f01 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@  Post-v2.8.0
        ovsdb-server(5) for more details.
      * ovsdb-client: New "get-schema-cksum" and "query" commands.
      * ovsdb-client: New "backup" and "restore" commands.
+     * ovsdb-tool: New "db-name" and "schema-name" commands.
    - ovs-vsctl and other commands that display data in tables now support a
      --max-column-width option to limit column width.
    - OVN:
diff --git a/ovsdb/ovsdb-tool.1.in b/ovsdb/ovsdb-tool.1.in
index ebfd33b27163..f6144e7021c0 100644
--- a/ovsdb/ovsdb-tool.1.in
+++ b/ovsdb/ovsdb-tool.1.in
@@ -37,6 +37,10 @@  ovsdb\-tool \- Open vSwitch database management utility
 .br
 \fBovsdb\-tool \fR[\fIoptions\fR] [\fB\-m\fR | \fB\-\-more\fR]... \fBshow\-log \fR[\fIdb\fR]
 .br
+\fBovsdb\-tool \fR[\fIoptions\fR] \fBdb\-name \fR[\fIdb\fR]
+.br
+\fBovsdb\-tool \fR[\fIoptions\fR] \fBschema\-name \fR[\fIschema\fR]
+.br
 \fBovsdb\-tool help\fR
 .so lib/vlog-syn.man
 .so lib/common-syn.man
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index 45b3f7348c3d..228bcf1dac54 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -135,8 +135,10 @@  usage(void)
            "  create [DB [SCHEMA]]    create DB with the given SCHEMA\n"
            "  compact [DB [DST]]      compact DB in-place (or to DST)\n"
            "  convert [DB [SCHEMA [DST]]]   convert DB to SCHEMA (to DST)\n"
+           "  db-name [DB]            report name of schema used by DB\n"
            "  db-version [DB]         report version of schema used by DB\n"
            "  db-cksum [DB]           report checksum of schema used by DB\n"
+           "  schema-name [SCHEMA]    report SCHEMA's name\n"
            "  schema-version [SCHEMA] report SCHEMA's schema version\n"
            "  schema-cksum [SCHEMA]   report SCHEMA's checksum\n"
            "  query [DB] TRNS         execute read-only transaction on DB\n"
@@ -325,6 +327,17 @@  do_needs_conversion(struct ovs_cmdl_context *ctx)
 }
 
 static void
+do_db_name(struct ovs_cmdl_context *ctx)
+{
+    const char *db_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_db();
+    struct ovsdb_schema *schema;
+
+    check_ovsdb_error(ovsdb_file_read_schema(db_file_name, &schema));
+    puts(schema->name);
+    ovsdb_schema_destroy(schema);
+}
+
+static void
 do_db_version(struct ovs_cmdl_context *ctx)
 {
     const char *db_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_db();
@@ -369,6 +382,17 @@  do_schema_cksum(struct ovs_cmdl_context *ctx)
 }
 
 static void
+do_schema_name(struct ovs_cmdl_context *ctx)
+{
+    const char *schema_file_name = ctx->argc >= 2 ? ctx->argv[1] : default_schema();
+    struct ovsdb_schema *schema;
+
+    check_ovsdb_error(ovsdb_schema_from_file(schema_file_name, &schema));
+    puts(schema->name);
+    ovsdb_schema_destroy(schema);
+}
+
+static void
 transact(bool read_only, int argc, char *argv[])
 {
     const char *db_file_name = argc >= 3 ? argv[1] : default_db();
@@ -590,8 +614,10 @@  static const struct ovs_cmdl_command all_commands[] = {
     { "compact", "[db [dst]]", 0, 2, do_compact, OVS_RW },
     { "convert", "[db [schema [dst]]]", 0, 3, do_convert, OVS_RW },
     { "needs-conversion", NULL, 0, 2, do_needs_conversion, OVS_RO },
+    { "db-name", "[db]",  0, 1, do_db_name, OVS_RO },
     { "db-version", "[db]",  0, 1, do_db_version, OVS_RO },
     { "db-cksum", "[db]", 0, 1, do_db_cksum, OVS_RO },
+    { "schema-name", "[schema]", 0, 1, do_schema_name, OVS_RO },
     { "schema-version", "[schema]", 0, 1, do_schema_version, OVS_RO },
     { "schema-cksum", "[schema]", 0, 1, do_schema_cksum, OVS_RO },
     { "query", "[db] trns", 1, 2, do_query, OVS_RO },