Skip to content

Commit

Permalink
vtep-ctl: Use db-ctl-base.
Browse files Browse the repository at this point in the history
This commit makes vtep-ctl use db-ctl-base to avoid duplicate code.
As an addition, a 'show' command is added to vtep-ctl.

Signed-off-by: Alex Wang <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
yew011 committed Jun 23, 2015
1 parent f6a2e15 commit 3935f67
Show file tree
Hide file tree
Showing 4 changed files with 482 additions and 2,288 deletions.
2 changes: 2 additions & 0 deletions manpages.mk
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ ovsdb/remote-passive.man:
vtep/vtep-ctl.8: \
vtep/vtep-ctl.8.in \
lib/common.man \
lib/db-ctl-base.man \
lib/ssl-bootstrap.man \
lib/ssl-peer-ca-cert.man \
lib/ssl.man \
Expand All @@ -290,6 +291,7 @@ vtep/vtep-ctl.8: \
ovsdb/remote-passive.man
vtep/vtep-ctl.8.in:
lib/common.man:
lib/db-ctl-base.man:
lib/ssl-bootstrap.man:
lib/ssl-peer-ca-cert.man:
lib/ssl.man:
Expand Down
22 changes: 22 additions & 0 deletions tests/vtep-ctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -887,3 +887,25 @@ tcp:5.4.3.2\ntcp:8.9.10.11
], [], [VTEP_CTL_CLEANUP])
VTEP_CTL_CLEANUP
AT_CLEANUP

AT_SETUP([show command])
AT_KEYWORDS([vtep-ctl show])
VTEP_CTL_SETUP
AT_CHECK([RUN_VTEP_CTL(
[set-manager tcp:4.5.6.7],
[add-ps a],
[add-port a a1],
[add-ls ls1],
[bind-ls a a1 100 ls1],
[set Physical_Switch a tunnel_ips=[[1.2.3.4]]])], [0], [ignore], [], [VTEP_CTL_CLEANUP])

AT_CHECK([vtep-ctl --timeout=5 -vreconnect:emer --db=unix:socket show | tail -n+2 | sed 's/=[[a-f0-9-]][[a-f0-9-]]*\}/=<ls>\}/' ], [0], [dnl
Manager "tcp:4.5.6.7"
Physical_Switch a
tunnel_ips: [["1.2.3.4"]]
Physical_Port "a1"
vlan_bindings: {100=<ls>}
], [], [VTEP_CTL_CLEANUP])

VTEP_CTL_CLEANUP
AT_CLEANUP
227 changes: 1 addition & 226 deletions vtep/vtep-ctl.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -348,232 +348,7 @@ and \fB\-\-\fR and \fB_\fR are treated interchangeably. Unique
abbreviations are acceptable, e.g. \fBman\fR or \fBm\fR is sufficient
to identify the \fBManager\fR table.
.
.ST "Database Values"
.PP
Each column in the database accepts a fixed type of data. The
currently defined basic types, and their representations, are:
.IP "integer"
A decimal integer in the range \-2**63 to 2**63\-1, inclusive.
.IP "real"
A floating-point number.
.IP "Boolean"
True or false, written \fBtrue\fR or \fBfalse\fR, respectively.
.IP "string"
An arbitrary Unicode string, except that null bytes are not allowed.
Quotes are optional for most strings that begin with an English letter
or underscore and consist only of letters, underscores, hyphens, and
periods. However, \fBtrue\fR and \fBfalse\fR and strings that match
the syntax of UUIDs (see below) must be enclosed in double quotes to
distinguish them from other basic types. When double quotes are used,
the syntax is that of strings in JSON, e.g. backslashes may be used to
escape special characters. The empty string must be represented as a
pair of double quotes (\fB""\fR).
.IP "UUID"
Either a universally unique identifier in the style of RFC 4122,
e.g. \fBf81d4fae\-7dec\-11d0\-a765\-00a0c91e6bf6\fR, or an \fB@\fIname\fR
defined by a \fBget\fR or \fBcreate\fR command within the same \fBvtep\-ctl\fR
invocation.
.PP
Multiple values in a single column may be separated by spaces or a
single comma. When multiple values are present, duplicates are not
allowed, and order is not important. Conversely, some database
columns can have an empty set of values, represented as \fB[]\fR, and
square brackets may optionally enclose other non-empty sets or single
values as well.
.PP
A few database columns are ``maps'' of key-value pairs, where the key
and the value are each some fixed database type. These are specified
in the form \fIkey\fB=\fIvalue\fR, where \fIkey\fR and \fIvalue\fR
follow the syntax for the column's key type and value type,
respectively. When multiple pairs are present (separated by spaces or
a comma), duplicate keys are not allowed, and again the order is not
important. Duplicate values are allowed. An empty map is represented
as \fB{}\fR. Curly braces may optionally enclose non-empty maps as
well (but use quotes to prevent the shell from expanding
\fBother-config={0=x,1=y}\fR into \fBother-config=0=x
other-config=1=y\fR, which may not have the desired effect).
.
.ST "Database Command Syntax"
.IP "[\fB\-\-columns=\fIcolumn\fR[\fB,\fIcolumn\fR]...] \fBlist \fItable \fR[\fIrecord\fR]..."
Lists the data in each specified \fIrecord\fR. If no
records are specified, lists all the records in \fItable\fR.
.IP
If \fB\-\-columns\fR is specified, only the requested columns are
listed, in the specified order. Otherwise, all columns are listed, in
alphabetical order by column name.
.
.IP "[\fB\-\-columns=\fIcolumn\fR[\fB,\fIcolumn\fR]...] \fBfind \fItable \fR[\fIcolumn\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR]..."
Lists the data in each record in \fItable\fR whose \fIcolumn\fR equals
\fIvalue\fR or, if \fIkey\fR is specified, whose \fIcolumn\fR contains
a \fIkey\fR with the specified \fIvalue\fR. The following operators
may be used where \fB=\fR is written in the syntax summary:
.RS
.IP "\fB= != < > <= >=\fR"
Selects records in which \fIcolumn\fR[\fB:\fIkey\fR] equals, does not
equal, is less than, is greater than, is less than or equal to, or is
greater than or equal to \fIvalue\fR, respectively.
.IP
Consider \fIcolumn\fR[\fB:\fIkey\fR] and \fIvalue\fR as sets of
elements. Identical sets are considered equal. Otherwise, if the
sets have different numbers of elements, then the set with more
elements is considered to be larger. Otherwise, consider a element
from each set pairwise, in increasing order within each set. The
first pair that differs determines the result. (For a column that
contains key-value pairs, first all the keys are compared, and values
are considered only if the two sets contain identical keys.)
.IP "\fB{=} {!=}\fR"
Test for set equality or inequality, respectively.
.IP "\fB{<=}\fR"
Selects records in which \fIcolumn\fR[\fB:\fIkey\fR] is a subset of
\fIvalue\fR. For example, \fBflood-vlans{<=}1,2\fR selects records in
which the \fBflood-vlans\fR column is the empty set or contains 1 or 2
or both.
.IP "\fB{<}\fR"
Selects records in which \fIcolumn\fR[\fB:\fIkey\fR] is a proper
subset of \fIvalue\fR. For example, \fBflood-vlans{<}1,2\fR selects
records in which the \fBflood-vlans\fR column is the empty set or
contains 1 or 2 but not both.
.IP "\fB{>=} {>}\fR"
Same as \fB{<=}\fR and \fB{<}\fR, respectively, except that the
relationship is reversed. For example, \fBflood-vlans{>=}1,2\fR
selects records in which the \fBflood-vlans\fR column contains both 1
and 2.
.RE
.IP
For arithmetic operators (\fB= != < > <= >=\fR), when \fIkey\fR is
specified but a particular record's \fIcolumn\fR does not contain
\fIkey\fR, the record is always omitted from the results. Thus, the
condition \fBother-config:mtu!=1500\fR matches records that have a
\fBmtu\fR key whose value is not 1500, but not those that lack an
\fBmtu\fR key.
.IP
For the set operators, when \fIkey\fR is specified but a particular
record's \fIcolumn\fR does not contain \fIkey\fR, the comparison is
done against an empty set. Thus, the condition
\fBother-config:mtu{!=}1500\fR matches records that have a \fBmtu\fR
key whose value is not 1500 and those that lack an \fBmtu\fR key.
.IP
Don't forget to escape \fB<\fR or \fB>\fR from interpretation by the
shell.
.IP
If \fB\-\-columns\fR is specified, only the requested columns are
listed, in the specified order. Otherwise all columns are listed, in
alphabetical order by column name.
.IP
The UUIDs shown for rows created in the same \fBvtep\-ctl\fR
invocation will be wrong.
.
.IP "[\fB\-\-id=@\fIname\fR] [\fB\-\-if\-exists\fR] \fBget \fItable record \fR[\fIcolumn\fR[\fB:\fIkey\fR]]..."
Prints the value of each specified \fIcolumn\fR in the given
\fIrecord\fR in \fItable\fR. For map columns, a \fIkey\fR may
optionally be specified, in which case the value associated with
\fIkey\fR in the column is printed, instead of the entire map.
.IP
For a map column, without \fB\-\-if\-exists\fR it is an error if
\fIkey\fR does not exist; with it, a blank line is printed. If
\fIcolumn\fR is not a map column or if \fIkey\fR is not specified,
\fB\-\-if\-exists\fR has no effect.
.IP
If \fB@\fIname\fR is specified, then the UUID for \fIrecord\fR may be
referred to by that name later in the same \fBvtep\-ctl\fR
invocation in contexts where a UUID is expected.
.IP
Both \fB\-\-id\fR and the \fIcolumn\fR arguments are optional, but
usually at least one or the other should be specified. If both are
omitted, then \fBget\fR has no effect except to verify that
\fIrecord\fR exists in \fItable\fR.
.
.IP "\fBset \fItable record column\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR..."
Sets the value of each specified \fIcolumn\fR in the given
\fIrecord\fR in \fItable\fR to \fIvalue\fR. For map columns, a
\fIkey\fR may optionally be specified, in which case the value
associated with \fIkey\fR in that column is changed (or added, if none
exists), instead of the entire map.
.
.IP "\fBadd \fItable record column \fR[\fIkey\fB=\fR]\fIvalue\fR..."
Adds the specified value or key-value pair to \fIcolumn\fR in
\fIrecord\fR in \fItable\fR. If \fIcolumn\fR is a map, then \fIkey\fR
is required, otherwise it is prohibited. If \fIkey\fR already exists
in a map column, then the current \fIvalue\fR is not replaced (use the
\fBset\fR command to replace an existing value).
.
.IP "\fBremove \fItable record column \fR\fIvalue\fR..."
.IQ "\fBremove \fItable record column \fR\fIkey\fR..."
.IQ "\fBremove \fItable record column \fR\fIkey\fB=\fR\fIvalue\fR..."
Removes the specified values or key-value pairs from \fIcolumn\fR in
\fIrecord\fR in \fItable\fR. The first form applies to columns that
are not maps: each specified \fIvalue\fR is removed from the column.
The second and third forms apply to map columns: if only a \fIkey\fR
is specified, then any key-value pair with the given \fIkey\fR is
removed, regardless of its value; if a \fIvalue\fR is given then a
pair is removed only if both key and value match.
.IP
It is not an error if the column does not contain the specified key or
value or pair.
.
.IP "\fBclear\fR \fItable record column\fR..."
Sets each \fIcolumn\fR in \fIrecord\fR in \fItable\fR to the empty set
or empty map, as appropriate. This command applies only to columns
that are allowed to be empty.
.
.IP "[\fB\-\-id=@\fIname\fR] \fBcreate\fR \fItable column\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR..."
Creates a new record in \fItable\fR and sets the initial values of
each \fIcolumn\fR. Columns not explicitly set will receive their
default values. Outputs the UUID of the new row.
.IP
If \fB@\fIname\fR is specified, then the UUID for the new row may be
referred to by that name elsewhere in the same \fBvtep\-ctl\fR
invocation in contexts where a UUID is expected. Such references may
precede or follow the \fBcreate\fR command.
.IP
Records in the Open vSwitch database are significant only when they
can be reached directly or indirectly from the \fBOpen_vSwitch\fR
table. Except for records in the \fBQoS\fR or \fBQueue\fR tables,
records that are not reachable from the \fBOpen_vSwitch\fR table are
automatically deleted from the database. This deletion happens
immediately, without waiting for additional \fBvtep\-ctl\fR commands
or other database activity. Thus, a \fBcreate\fR command must
generally be accompanied by additional commands \fIwithin the same
\fBvtep\-ctl\fI invocation\fR to add a chain of references to the
newly created record from the top-level \fBOpen_vSwitch\fR record.
The \fBEXAMPLES\fR section gives some examples that show how to do
this.
.
.IP "\fR[\fB\-\-if\-exists\fR] \fBdestroy \fItable record\fR..."
Deletes each specified \fIrecord\fR from \fItable\fR. Unless
\fB\-\-if\-exists\fR is specified, each \fIrecord\fRs must exist.
.IP "\fB\-\-all destroy \fItable\fR"
Deletes all records from the \fItable\fR.
.IP
The \fBdestroy\fR command is only useful for records in the \fBQoS\fR
or \fBQueue\fR tables. Records in other tables are automatically
deleted from the database when they become unreachable from the
\fBOpen_vSwitch\fR table. This means that deleting the last reference
to a record is sufficient for deleting the record itself. For records
in these tables, \fBdestroy\fR is silently ignored. See the
\fBEXAMPLES\fR section below for more information.
.
.IP "\fBwait\-until \fItable record \fR[\fIcolumn\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR]..."
Waits until \fItable\fR contains a record named \fIrecord\fR whose
\fIcolumn\fR equals \fIvalue\fR or, if \fIkey\fR is specified, whose
\fIcolumn\fR contains a \fIkey\fR with the specified \fIvalue\fR. Any
of the operators \fB!=\fR, \fB<\fR, \fB>\fR, \fB<=\fR, or \fB>=\fR may
be substituted for \fB=\fR to test for inequality, less than, greater
than, less than or equal to, or greater than or equal to,
respectively. (Don't forget to escape \fB<\fR or \fB>\fR from
interpretation by the shell.)
.IP
If no \fIcolumn\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR arguments are given,
this command waits only until \fIrecord\fR exists. If more than one
such argument is given, the command waits until all of them are
satisfied.
.IP
Consider specifying \fB\-\-timeout=0\fR along with
\fB\-\-wait\-until\fR, to prevent \fBvtep\-ctl\fR from terminating
after waiting only at most 5 seconds.
.IP "\fBcomment \fR[\fIarg\fR]..."
This command has no effect on behavior, but any database log record
created by the command will include the command and its arguments.
.so lib/db-ctl-base.man
.PP
.SH "EXIT STATUS"
.IP "0"
Expand Down
Loading

0 comments on commit 3935f67

Please sign in to comment.