From 112ce2bce3aff38b7722e4488eb5d17435f49850 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Mon, 2 Oct 2017 18:23:52 -0400 Subject: [PATCH] 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 --- nova/api/openstack/placement/handlers/allocation.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nova/api/openstack/placement/handlers/allocation.py b/nova/api/openstack/placement/handlers/allocation.py index 1e028efde..944edf0b3 100644 --- a/nova/api/openstack/placement/handlers/allocation.py +++ b/nova/api/openstack/placement/handlers/allocation.py @@ -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)