2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-19 14:37:21 +00:00

ovsdb-idl: Add the support to specify the uuid for row insert.

ovsdb-server allows the OVSDB clients to specify the uuid for
the row inserts [1].  Both the C IDL client library and Python
IDL are missing this feature.  This patch adds this support.

In C IDL, for each schema table, a new function is generated -
<schema_table>insert_persistent_uuid(txn, uuid) which can
be used the clients to persist the uuid.

ovs-vsctl and other derivatives of ctl now supports the same
in the generic 'create' command with the option "--id=<UUID>".

In Python IDL, the uuid to persist can be specified in
the Transaction.insert() function.

[1] - a529e3cd1f("ovsdb-server: Allow OVSDB clients to specify the UUID for inserted rows.:)

Acked-by: Adrian Moreno <amorenoz@redhat.com>
Acked-by: Han Zhou <hzhou@ovn.org>
Acked-by: Terry Wilson <twilson@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Numan Siddique
2022-11-27 22:56:13 -05:00
committed by Ilya Maximets
parent 954ae38a12
commit 55b9507e68
13 changed files with 264 additions and 51 deletions

View File

@@ -1223,7 +1223,7 @@ class Row(object):
d["a"] = "b"
row.mycolumn = d
"""
def __init__(self, idl, table, uuid, data):
def __init__(self, idl, table, uuid, data, persist_uuid=False):
# All of the explicit references to self.__dict__ below are required
# to set real attributes with invoking self.__getattr__().
self.__dict__["uuid"] = uuid
@@ -1278,6 +1278,10 @@ class Row(object):
# in the dictionary are all None.
self.__dict__["_prereqs"] = {}
# Indicates if the specified 'uuid' should be used as the row uuid
# or let the server generate it.
self.__dict__["_persist_uuid"] = persist_uuid
def __lt__(self, other):
if not isinstance(other, Row):
return NotImplemented
@@ -1816,7 +1820,11 @@ class Transaction(object):
op = {"table": row._table.name}
if row._data is None:
op["op"] = "insert"
op["uuid-name"] = _uuid_name_from_uuid(row.uuid)
if row._persist_uuid:
op["uuid"] = row.uuid
else:
op["uuid-name"] = _uuid_name_from_uuid(row.uuid)
any_updates = True
op_index = len(operations) - 1
@@ -2056,20 +2064,22 @@ class Transaction(object):
row._mutations['_removes'].pop(column.name, None)
row._changes[column.name] = datum.copy()
def insert(self, table, new_uuid=None):
def insert(self, table, new_uuid=None, persist_uuid=False):
"""Inserts and returns a new row in 'table', which must be one of the
ovs.db.schema.TableSchema objects in the Idl's 'tables' dict.
The new row is assigned a provisional UUID. If 'uuid' is None then one
is randomly generated; otherwise 'uuid' should specify a randomly
generated uuid.UUID not otherwise in use. ovsdb-server will assign a
different UUID when 'txn' is committed, but the IDL will replace any
uses of the provisional UUID in the data to be to be committed by the
UUID assigned by ovsdb-server."""
generated uuid.UUID not otherwise in use. If 'persist_uuid' is true
and 'new_uuid' is specified, IDL requests the ovsdb-server to assign
the same UUID, otherwise ovsdb-server will assign a different UUID when
'txn' is committed and the IDL will replace any uses of the provisional
UUID in the data to be committed by the UUID assigned by
ovsdb-server."""
assert self._status == Transaction.UNCOMMITTED
if new_uuid is None:
new_uuid = uuid.uuid4()
row = Row(self.idl, table, new_uuid, None)
row = Row(self.idl, table, new_uuid, None, persist_uuid=persist_uuid)
table.rows[row.uuid] = row
self._txn_rows[row.uuid] = row
return row