db: Migrate "driver initiator data" APIs to enginefacade

Migrate driver initiator data-related APIs from the legacy enginefacade
to the modern context-based enginefacade.

Change-Id: I95cdc8b6eec37503c266e131f22d29f809623a92
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2022-02-17 16:05:17 +00:00
parent 3975230ca2
commit 43c1f3107e

View File

@ -8373,30 +8373,36 @@ def cleanup_expired_messages(context):
@require_context @require_context
def driver_initiator_data_insert_by_key(context, initiator, namespace, @main_context_manager.writer
key, value): def driver_initiator_data_insert_by_key(
context,
initiator,
namespace,
key,
value,
):
data = models.DriverInitiatorData() data = models.DriverInitiatorData()
data.initiator = initiator data.initiator = initiator
data.namespace = namespace data.namespace = namespace
data.key = key data.key = key
data.value = value data.value = value
session = get_session()
try: try:
with session.begin(): with main_context_manager.writer.savepoint.using(context):
session.add(data) data.save(context.session)
return True return True
except db_exc.DBDuplicateEntry: except db_exc.DBDuplicateEntry:
return False return False
@require_context @require_context
@main_context_manager.reader
def driver_initiator_data_get(context, initiator, namespace): def driver_initiator_data_get(context, initiator, namespace):
session = get_session() return (
with session.begin(): context.session.query(models.DriverInitiatorData)
return session.query(models.DriverInitiatorData).\ .filter_by(initiator=initiator)
filter_by(initiator=initiator).\ .filter_by(namespace=namespace)
filter_by(namespace=namespace).\ .all()
all() )
############################### ###############################