.
.IP "\fB-f \fIformat\fR"
.IQ "\fB--format=\fIformat\fR"
-Sets the basic type of output formatting. The following types of
+Sets the type of table formatting. The following types of
\fIformat\fR are available:
.RS
.IP "\fBtable\fR (default)"
Comma-separated values as defined in RFC 4180.
.RE
.
+.IP "\fB-d \fIformat\fR"
+.IP "\fB--data=\fIformat\fR"
+Sets the formatting for cells within output tables. The following
+types of \fIformat\fR are available:
+.RS
+.IP "\fBstring\fR (default)"
+The simple format described in \fBovs-vsctl\fR(8).
+.IP "\fBjson\fR"
+JSON.
+.RE
+.
.IP "\fB--no-heading\fR"
This option suppresses the heading row that otherwise appears in the
first row of table output.
#include "json.h"
#include "jsonrpc.h"
#include "ovsdb.h"
+#include "ovsdb-data.h"
#include "ovsdb-error.h"
#include "stream.h"
#include "stream-ssl.h"
/* --pretty: Flags to pass to json_to_string(). */
static int json_flags = JSSF_SORT;
+/* --data: Format of data in output tables. */
+static enum {
+ DF_STRING, /* String format. */
+ DF_JSON, /* JSON. */
+} data_format;
+
static const struct command all_commands[];
static void usage(void) NO_RETURN;
};
static struct option long_options[] = {
{"format", required_argument, 0, 'f'},
- {"no-headings", no_argument, &output_headings, 0},
+ {"data", required_argument, 0, 'd'},
+ {"no-headings", no_argument, &output_headings, 0},
{"pretty", no_argument, &json_flags, JSSF_PRETTY | JSSF_SORT},
{"verbose", optional_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
}
break;
+ case 'd':
+ if (!strcmp(optarg, "string")) {
+ data_format = DF_STRING;
+ } else if (!strcmp(optarg, "json")) {
+ data_format = DF_JSON;
+ } else {
+ ovs_fatal(0, "unknown data format \"%s\"", optarg);
+ }
+ break;
+
case 'h':
usage();
jsonrpc_close(rpc);
}
+static char *
+format_data(const struct json *json, const struct ovsdb_type *type)
+{
+ if (data_format == DF_JSON) {
+ return json_to_string(json, JSSF_SORT);
+ } else if (data_format == DF_STRING) {
+ struct ovsdb_datum datum;
+ struct ovsdb_error *error;
+ struct ds s;
+
+ error = ovsdb_datum_from_json(&datum, type, json, NULL);
+ if (error) {
+ return json_to_string(json, JSSF_SORT);
+ }
+
+ ds_init(&s);
+ ovsdb_datum_to_string(&datum, type, &s);
+ ovsdb_datum_destroy(&datum, type);
+ return ds_steal_cstr(&s);
+ } else {
+ NOT_REACHED();
+ }
+}
+
static void
monitor_print_row(struct json *row, const char *type, const char *uuid,
const struct ovsdb_column_set *columns, struct table *t)
const struct ovsdb_column *column = columns->columns[i];
struct json *value = shash_find_data(json_object(row), column->name);
if (value) {
- table_add_cell_nocopy(t, json_to_string(value, JSSF_SORT));
+ table_add_cell_nocopy(t, format_data(value, &column->type));
} else {
table_add_cell(t, "");
}
m4_foreach([txn], [$3],
[AT_CHECK([ovsdb-tool transact db 'txn'], [0], [ignore], [ignore])])
AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --remote=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
- AT_CHECK([ovsdb-client --detach --pidfile=$PWD/client-pid monitor --format=csv unix:socket ordinals $4 > output],
+ AT_CHECK([ovsdb-client --detach --pidfile=$PWD/client-pid -d json monitor --format=csv unix:socket ordinals $4 > output],
[0], [ignore], [ignore], [kill `cat server-pid`])
m4_foreach([txn], [$5],
[AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0],