rp: fix up AllocList.get_by_resource_provider_uuid

Changes the AllocationList.get_by_resource_provider_uuid() to
AllocationList.get_by_resource_provider(), accepting a ResourceProvider
object parameter instead of a UUID. This is exactly how the
InventoryList object was changed in an earlier patch. A new
module-scoped _get_allocations_by_provider_id() function is added that
bypasses the ORM and uses the SQLAlchemy core expression API directly
to produce a smaller query with no joins.

blueprint: de-orm-resource-providers

Change-Id: Id866ab8353077cfeeae693c2958f412930f0f24d
This commit is contained in:
Jay Pipes 2017-10-02 18:23:52 -04:00
parent 12d7a465b6
commit 112ce2bce3

View File

@ -192,19 +192,16 @@ def list_for_resource_provider(req):
# confirm existence of resource provider so we get a reasonable
# 404 instead of empty list
try:
resource_provider = rp_obj.ResourceProvider.get_by_uuid(
context, uuid)
rp = rp_obj.ResourceProvider.get_by_uuid(context, uuid)
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("Resource provider '%(rp_uuid)s' not found: %(error)s") %
{'rp_uuid': uuid, 'error': exc})
allocations = rp_obj.AllocationList.get_all_by_resource_provider_uuid(
context, uuid)
allocs = rp_obj.AllocationList.get_all_by_resource_provider(context, rp)
allocations_json = jsonutils.dumps(
_serialize_allocations_for_resource_provider(
allocations, resource_provider))
_serialize_allocations_for_resource_provider(allocs, rp))
req.response.status = 200
req.response.body = encodeutils.to_utf8(allocations_json)