Re: [ovs-dev] [PATCH] db-ctl-base: Allow record UUIDs to be abbreviated.

2017-04-30 Thread Ben Pfaff
On Fri, Apr 28, 2017 at 04:43:55PM -0700, Andy Zhou wrote:
> On Thu, Apr 27, 2017 at 12:36 PM, Ben Pfaff  wrote:
> > This makes it easier to type ovs-vsctl, ovn-sbctl, ovn-nbctl, and vtep-ctl
> > commands without cut-and-paste.
> >
> > Signed-off-by: Ben Pfaff 
> 
> Very handy!.  Now I can just use ovs-vsctl list a table, and then dump
> a row from the Reftables with quik type of UUID.
> Documentation updates looks good too.
> 
> Acked-by: Andy Zhou 

Thanks! I applied this to master.
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH] db-ctl-base: Allow record UUIDs to be abbreviated.

2017-04-28 Thread Andy Zhou
On Thu, Apr 27, 2017 at 12:36 PM, Ben Pfaff  wrote:
> This makes it easier to type ovs-vsctl, ovn-sbctl, ovn-nbctl, and vtep-ctl
> commands without cut-and-paste.
>
> Signed-off-by: Ben Pfaff 

Very handy!.  Now I can just use ovs-vsctl list a table, and then dump
a row from the Reftables with quik type of UUID.
Documentation updates looks good too.

Acked-by: Andy Zhou 
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH] db-ctl-base: Allow record UUIDs to be abbreviated.

2017-04-27 Thread Ben Pfaff
This makes it easier to type ovs-vsctl, ovn-sbctl, ovn-nbctl, and vtep-ctl
commands without cut-and-paste.

Signed-off-by: Ben Pfaff 
---
 NEWS  |  4 
 lib/db-ctl-base.c | 28 
 ovn/utilities/ovn-nbctl.8.xml | 15 +--
 ovn/utilities/ovn-sbctl.8.in  | 26 ++
 ovn/utilities/ovn-sbctl.c |  3 +++
 utilities/ovs-vsctl.8.in  | 10 ++
 vtep/vtep-ctl.8.in| 10 ++
 7 files changed, 86 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index ea97d84a2dea..7a7e7fcd8a3a 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ Post-v2.7.0
still can be configured via extra arguments for DPDK EAL.
- New support for multiple VLANs (802.1ad or "QinQ"), including a new
  "dot1q-tunnel" port VLAN mode.
+   - In ovn-vsctl and vtep-ctl, record UUIDs in commands may now be
+ abbreviated to 4 hex digits.
- OVN:
  * IPAM for IPv4 can now exclude user-defined addresses from assignment.
  * IPAM can now assign IPv6 addresses.
@@ -20,6 +22,8 @@ Post-v2.7.0
  * Allow ovn-controller SSL configuration to be obtained from vswitchd
database.
  * ovn-trace now has basic support for tracing distributed firewalls.
+ * In ovn-nbctl and ovn-sbctl, record UUIDs in commands may now be
+   abbreviated to 4 hex digits.
- Add the command 'ovs-appctl stp/show' (see ovs-vswitchd(8)).
- OpenFlow:
  * Increased support for OpenFlow 1.6 (draft).
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index afc70eb06e36..ad98454c903d 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -300,6 +300,14 @@ get_row_by_id(struct ctl_context *ctx,
 return final;
 }
 
+static bool
+is_partial_uuid_match(const struct uuid *uuid, const char *match)
+{
+char uuid_s[UUID_LEN + 1];
+snprintf(uuid_s, sizeof uuid_s, UUID_FMT, UUID_ARGS(uuid));
+return !strncmp(uuid_s, match, strlen(match));
+}
+
 static const struct ovsdb_idl_row *
 get_row(struct ctl_context *ctx,
 const struct ovsdb_idl_table_class *table, const char *record_id,
@@ -330,6 +338,26 @@ get_row(struct ctl_context *ctx,
 }
 }
 }
+if (!row
+&& record_id[uuid_is_partial_string(record_id)] == '\0'
+&& strlen(record_id) >= 4) {
+for (const struct ovsdb_idl_row *r = ovsdb_idl_first_row(ctx->idl,
+ table);
+ r != NULL;
+ r = ovsdb_idl_next_row(r)) {
+if (is_partial_uuid_match(>uuid, record_id)) {
+if (!row) {
+row = r;
+} else {
+ctl_fatal("%s contains 2 or more rows whose UUIDs begin "
+  "with %s: at least "UUID_FMT" and "UUID_FMT,
+  table->name, record_id,
+  UUID_ARGS(>uuid),
+  UUID_ARGS(>uuid));
+}
+}
+}
+}
 if (must_exist && !row) {
 ctl_fatal("no row \"%s\" in table %s", record_id, table->name);
 }
diff --git a/ovn/utilities/ovn-nbctl.8.xml b/ovn/utilities/ovn-nbctl.8.xml
index 70afc1080f62..adea29a4e84f 100644
--- a/ovn/utilities/ovn-nbctl.8.xml
+++ b/ovn/utilities/ovn-nbctl.8.xml
@@ -669,12 +669,13 @@
 Database Commands
 These commands query and modify the contents of ovsdb 
tables.
 They are a slight abstraction of the ovsdb interface and
-as suchthey operate at a lower level than other ovn-nbctl 
commands.
+as such they operate at a lower level than other ovn-nbctl 
commands.
 Identifying Tables, Records, and Columns
 Each of these commands has a table parameter to identify a 
table
 within the database.  Many of them also take a record parameter
 that identifies a particular record within a table.  The record
-parameter may be the UUID for a record, and many tables offer
+parameter may be the UUID for a record, which may be abbreviated to its
+first 4 (or more) hex digits, as long as that is unique.  Many tables offer
 additional ways to identify records.  Some commands also take
 column parameters that identify a particular field within the
 records in a table.
@@ -737,6 +738,16 @@
 
 
 
+
+  Record names must be specified in full and with correct capitalization,
+  except that UUIDs may be abbreviated to their first 4 (or more) hex
+  digits, as long as that is unique within the table.  Names of tables and
+  columns are not case-sensitive, and - and _ are
+  treated interchangeably.  Unique abbreviations of table and column names
+  are acceptable, e.g. d or dhcp is sufficient
+  to identify the DHCP_Options table.
+
+
 http://www.w3.org/2003/XInclude"/>
 
 Synchronization Commands
diff --git a/ovn/utilities/ovn-sbctl.8.in b/ovn/utilities/ovn-sbctl.8.in
index