2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

python: ovsdb-idl: Add custom transaction operations.

It can be useful to be able to send raw transaction operations
through the Idl's connection. For example, to clean up MAC_Binding
entries for floating IPs without having to monitor the MAC_Binding
table which can be quite large.

Signed-off-by: Terry Wilson <twilson@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Terry Wilson
2024-06-28 14:18:41 -05:00
committed by Ilya Maximets
parent 56e315937e
commit c1dce72a37
4 changed files with 122 additions and 1 deletions

View File

@@ -1708,6 +1708,8 @@ class Transaction(object):
self._inserted_rows = {} # Map from UUID to _InsertedRow
self._operations = []
def add_comment(self, comment):
"""Appends 'comment' to the comments that will be passed to the OVSDB
server when this transaction is committed. (The comment will be
@@ -1843,7 +1845,7 @@ class Transaction(object):
"rows": [rows]})
# Add updates.
any_updates = False
any_updates = bool(self._operations)
for row in self._txn_rows.values():
if row._changes is None:
if row._table.is_root:
@@ -1978,6 +1980,8 @@ class Transaction(object):
operations.append({"op": "comment",
"comment": "\n".join(self._comments)})
operations += self._operations
# Dry run?
if self.dry_run:
operations.append({"op": "abort"})
@@ -1996,6 +2000,21 @@ class Transaction(object):
self.__disassemble()
return self._status
def add_op(self, op):
"""Add a raw OVSDB operation to the transaction
This can be useful for re-using the existing Idl connection to take
actions that are difficult or expensive to do with the Idl itself, e.g.
bulk deleting rows from the server without downloading them into a
local cache.
All ops are applied after any other operations in the transaction.
:param op: An "op" for an OVSDB "transact" request (rfc 7047 Sec 5.2)
:type op: dict
"""
self._operations.append(op)
def commit_block(self):
"""Attempts to commit this transaction, blocking until the commit
either succeeds or fails. Returns the final commit status, which may