RequestGroup class for placement & consumers

This change introduces a new module, nova.api.openstack.placement.lib,
with a class RequestGroup, which is to be used both by the placement API
internally (when parsing the querystring to GET /allocation_candidates)
and nova (when parsing extra_specs and producing said querystring for
said API).

The decision to put this into a placement-specific package is
deliberate: when placement gets split out, this should go with it, so it
can be imported by any placement API consumer.  In the meantime, we
accept that it will feel a little weird for nova code to import from a
placement API package; but this should be the only module for which that
happens - i.e. any other "shared" classes/utils should go in this same
module.

Change-Id: I8a70347d06d032788d27d1af8967a65d530c15fe
blueprint: granular-resource-requests
This commit is contained in:
Eric Fried 2017-11-02 11:06:07 -05:00
parent 069e5ec67c
commit dcacc2e2b2

@ -0,0 +1,34 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Symbols intended to be imported by both placement code and placement API
consumers. When placement is separated out, this module should be part of a
common library that both placement and its consumers can require."""
class RequestGroup(object):
def __init__(self, use_same_provider=True, resources=None,
required_traits=None):
"""Create a grouping of resource and trait requests.
:param use_same_provider:
If True, (the default) this RequestGroup represents requests for
resources and traits which must be satisfied by a single resource
provider. If False, represents a request for resources and traits
in any resource provider in the same tree, or a sharing provider.
:param resources: A dict of { resource_class: amount, ... }
:param required_traits: A set of { trait_name, ... }
"""
self.use_same_provider = use_same_provider
self.resources = resources or {}
self.required_traits = required_traits or set()