summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorNuman Siddique <numans@ovn.org>2022-11-27 22:56:13 -0500
committerIlya Maximets <i.maximets@ovn.org>2022-11-30 15:15:57 +0100
commit55b9507e6824b935ffa0205fc7c7bebfe4e54279 (patch)
tree6793b9321b9c5653ebc627648b256900d1d98a05 /python
parent954ae38a12f0c0d7bab1334c9ba353da94de887c (diff)
downloadopenvswitch-55b9507e6824b935ffa0205fc7c7bebfe4e54279.tar.gz
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>
Diffstat (limited to 'python')
-rw-r--r--python/ovs/db/idl.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index 8e31e02d7..fe66402cf 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -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