Hi, I am trying to execute a query on nova db in a custom code file in nova. During the execution of a function like 'instance_get_all_by_filters_sort' from nova/db/main/api.py , I see this --- try: query_prefix = sqlalchemyutils.paginate_query( query_prefix, models.Instance, limit, sort_keys, marker=marker, sort_dirs=sort_dirs, ) except db_exc.InvalidSortKey: raise exception.InvalidSortKey() instances = query_prefix.all() --- So, my question is how does query_prefix.all() know the mysql db connection url to connect to for executing the query ? Thanks elinux
Hi,
I am trying to execute a query on nova db in a custom code file in nova. During the execution of a function like 'instance_get_all_by_filters_sort' from nova/db/main/api.py , I see this
--- try: query_prefix = sqlalchemyutils.paginate_query( query_prefix, models.Instance, limit, sort_keys, marker=marker, sort_dirs=sort_dirs, ) except db_exc.InvalidSortKey: raise exception.InvalidSortKey()
instances = query_prefix.all() ---
So, my question is how does query_prefix.all() know the mysql db connection url to connect to for executing the query ? we use engine fasades and context managers taht allow you to a create a reader/wirter transaction to hide this form most of the code internally.
On Sat, 2024-08-03 at 01:27 +0530, engineer2024 wrote: those are usign config option to encode this db conenction url. by the way we do not provide supprot for using nova as a libary in general. i.e. we do not support importing nova/db/main/api.py form outside of nova to create custom tools. that is a purly internal api for our own use. https://github.com/openstack/nova/blob/master/nova/db/main/api.py#L64-L135 instance_get_all_by_filters_sort is using the db sessionf object form the context parmater https://github.com/openstack/nova/blob/master/nova/db/main/api.py#L1698 to construct the query. the session is construction by oslo deb as part of the tasnaction context https://github.com/openstack/oslo.db/blob/master/oslo_db/sqlalchemy/enginefa... so basicaly you need to registert the config options related to the and read the config file before making any quires using that code to ensure it can constcution the context manager and conenct to the db properly.
Thanks elinux
participants (2)
-
engineer2024
-
smooney@redhat.com