]> git.proxmox.com Git - mirror_ovs.git/commitdiff
db-ctl-base: Allow abbreviating UUIDs embedded in strings.
authorBen Pfaff <blp@ovn.org>
Thu, 27 Apr 2017 23:28:52 +0000 (16:28 -0700)
committerBen Pfaff <blp@ovn.org>
Wed, 3 May 2017 15:31:35 +0000 (08:31 -0700)
This allows commands like "ovn-sbctl lflow-list abcdef" to find a
datapath that has external-ids:logical-switch=abcdef12-3456-...

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
lib/db-ctl-base.c

index d40b5e6a880fd9bf8287d36a1667b7711c2895d8..cb04bbdd8440891b65e4dee439bbf14882af2d42 100644 (file)
@@ -240,6 +240,30 @@ create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp)
     return symbol;
 }
 
+static bool
+record_id_equals(const union ovsdb_atom *name, enum ovsdb_atomic_type type,
+                 const char *record_id)
+{
+    if (type == OVSDB_TYPE_STRING) {
+        if (!strcmp(name->string, record_id)) {
+            return true;
+        }
+
+        struct uuid uuid;
+        size_t len = strlen(record_id);
+        if (len >= 4
+            && uuid_from_string(&uuid, name->string)
+            && !strncmp(name->string, record_id, len)) {
+            return true;
+        }
+
+        return false;
+    } else {
+        ovs_assert(type == OVSDB_TYPE_INTEGER);
+        return name->integer == strtoll(record_id, NULL, 10);
+    }
+}
+
 static const struct ovsdb_idl_row *
 get_row_by_id(struct ctl_context *ctx,
               const struct ovsdb_idl_table_class *table,
@@ -300,9 +324,7 @@ get_row_by_id(struct ctl_context *ctx,
         }
 
         /* If the name equals 'record_id', take it. */
-        if (name_type == OVSDB_TYPE_STRING
-            ? !strcmp(name->string, record_id)
-            : name->integer == strtoll(record_id, NULL, 10)) {
+        if (record_id_equals(name, name_type, record_id)) {
             if (referrer) {
                 ctl_fatal("multiple rows in %s match \"%s\"",
                           id_table->name, record_id);