From ffdcd5d6e9de1511679e0c51a806ca8815c2d368 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Tue, 31 Oct 2017 15:03:30 -0400 Subject: [PATCH] create allocation request for single provider Pulls some more code out of the AllocationCandidates._get_by_filters() mega method into a separate function that constructs an AllocationRequest for a single provider that provides all of the resources being requested. Change-Id: I0e0ad23bb1c4e836c87f43c1fffddef45b241b11 --- nova/objects/resource_provider.py | 36 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/nova/objects/resource_provider.py b/nova/objects/resource_provider.py index 404907d15fee..fc3cd4565c2b 100644 --- a/nova/objects/resource_provider.py +++ b/nova/objects/resource_provider.py @@ -2602,6 +2602,25 @@ def _shared_allocation_request_resources(ctx, requested_resources, sharing, return res_requests +def _allocation_request_for_provider(ctx, requested_resources, rp_uuid): + """Returns an AllocationRequest object contains AllocationRequestResource + objects for each resource class in the supplied requested resources dict. + + :param ctx: nova.context.Context object + :param requested_resources: dict, keyed by resource class ID, of amounts + being requested for that resource class + :param rp_uuid: UUID of the resource provider supplying the resources + """ + resource_requests = [ + AllocationRequestResource( + ctx, resource_provider=ResourceProvider(ctx, uuid=rp_uuid), + resource_class=_RC_CACHE.string_from_id(rc_id), + amount=amount, + ) for rc_id, amount in requested_resources.items() + ] + return AllocationRequest(ctx, resource_requests=resource_requests) + + @base.NovaObjectRegistry.register_if(False) class AllocationCandidates(base.NovaObject): """The AllocationCandidates object is a collection of possible allocations @@ -2766,21 +2785,8 @@ class AllocationCandidates(base.NovaObject): # alternative containing this resource for each sharing provider has_all = len(shared_resources) == 0 if has_all: - resource_requests = [ - AllocationRequestResource( - context, - resource_provider=ResourceProvider( - context, - uuid=rp_uuid, - ), - resource_class=_RC_CACHE.string_from_id(rc_id), - amount=amount, - ) for rc_id, amount in resources.items() - ] - req_obj = AllocationRequest( - context, - resource_requests=resource_requests, - ) + req_obj = _allocation_request_for_provider(context, resources, + rp_uuid) alloc_request_objs.append(req_obj) continue