diff options
author | melanie witt <melwittt@gmail.com> | 2022-02-24 23:20:54 +0000 |
---|---|---|
committer | melanie witt <melwittt@gmail.com> | 2022-03-04 03:42:58 +0000 |
commit | 5505b6f438853a6c738f7192479edd8a0318284f (patch) | |
tree | 9736c7693de6be327ff09d3d80d5287587a2e2b4 /nova/limit | |
parent | 9ec6afe8939d6f3d72317b1cc8e0f4273bf31e43 (diff) | |
download | nova-5505b6f438853a6c738f7192479edd8a0318284f.tar.gz |
Follow up for unified limits
This addresses remaining comments from the unified limits series to add
type hints to new code and add a docstring to the is_qfd_populated()
method in nova/quota.py.
Related to blueprint unified-limits-nova
Change-Id: I948647b04b260e888a4c71c1fa3c2a7be5d140c5
Diffstat (limited to 'nova/limit')
-rw-r--r-- | nova/limit/local.py | 13 | ||||
-rw-r--r-- | nova/limit/placement.py | 32 |
2 files changed, 33 insertions, 12 deletions
diff --git a/nova/limit/local.py b/nova/limit/local.py index 38e7db05b7..f4e02c8020 100644 --- a/nova/limit/local.py +++ b/nova/limit/local.py @@ -20,7 +20,6 @@ from oslo_limit import limit from oslo_log import log as logging import nova.conf -from nova import context as nova_context from nova import exception from nova.limit import utils as nova_limit_utils from nova import objects @@ -80,7 +79,9 @@ LEGACY_LIMITS = { } -def get_in_use(context, project_id): +def get_in_use( + context: 'nova.context.RequestContext', project_id: str +) -> ty.Dict[str, int]: """Returns in use counts for each resource, for given project. This sounds simple but many resources can't be counted per project, @@ -144,7 +145,7 @@ def enforce_api_limit(entity_type: str, count: int) -> None: def enforce_db_limit( - context: nova_context.RequestContext, + context: 'nova.context.RequestContext', entity_type: str, entity_scope: ty.Any, delta: int @@ -192,7 +193,9 @@ def enforce_db_limit( raise EXCEPTIONS.get(entity_type, exception.OverQuota)(str(e)) -def _convert_keys_to_legacy_name(new_dict): +def _convert_keys_to_legacy_name( + new_dict: ty.Dict[str, int] +) -> ty.Dict[str, int]: legacy = {} for new_name, old_name in LEGACY_LIMITS.items(): # defensive incase oslo or keystone doesn't give us an answer @@ -200,7 +203,7 @@ def _convert_keys_to_legacy_name(new_dict): return legacy -def get_legacy_default_limits(): +def get_legacy_default_limits() -> ty.Dict[str, int]: # TODO(johngarbutt): need oslo.limit API for this, it should do caching enforcer = limit.Enforcer(lambda: None) new_limits = enforcer.get_registered_limits(LEGACY_LIMITS.keys()) diff --git a/nova/limit/placement.py b/nova/limit/placement.py index 95beffaff0..497986c4ab 100644 --- a/nova/limit/placement.py +++ b/nova/limit/placement.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import typing as ty import os_resource_classes as orc from oslo_limit import exception as limit_exceptions @@ -39,17 +40,23 @@ LEGACY_LIMITS = { } -def _get_placement_usages(context, project_id): +def _get_placement_usages( + context: 'nova.context.RequestContext', project_id: str +) -> ty.Dict[str, int]: global PLACEMENT_CLIENT if not PLACEMENT_CLIENT: PLACEMENT_CLIENT = report.SchedulerReportClient() return PLACEMENT_CLIENT.get_usages_counts_for_limits(context, project_id) -def _get_usage(context, project_id, resource_names): +def _get_usage( + context: 'nova.context.RequestContext', + project_id: str, + resource_names: ty.List[str], +) -> ty.Dict[str, int]: """Called by oslo_limit's enforcer""" if not limit_utils.use_unified_limits(): - raise NotImplementedError("unified limits is disabled") + raise NotImplementedError("Unified limits support is disabled") count_servers = False resource_classes = [] @@ -113,7 +120,9 @@ def _get_usage(context, project_id, resource_names): return resource_counts -def _get_deltas_by_flavor(flavor, is_bfv, count): +def _get_deltas_by_flavor( + flavor: 'objects.Flavor', is_bfv: bool, count: int +) -> ty.Dict[str, int]: if flavor is None: raise ValueError("flavor") if count < 0: @@ -132,7 +141,9 @@ def _get_deltas_by_flavor(flavor, is_bfv, count): return deltas -def _get_enforcer(context, project_id): +def _get_enforcer( + context: 'nova.context.RequestContext', project_id: str +) -> limit.Enforcer: # NOTE(johngarbutt) should we move context arg into oslo.limit? def callback(project_id, resource_names): return _get_usage(context, project_id, resource_names) @@ -140,8 +151,15 @@ def _get_enforcer(context, project_id): return limit.Enforcer(callback) -def enforce_num_instances_and_flavor(context, project_id, flavor, is_bfvm, - min_count, max_count, enforcer=None): +def enforce_num_instances_and_flavor( + context: 'nova.context.RequestContext', + project_id: str, + flavor: 'objects.Flavor', + is_bfvm: bool, + min_count: int, + max_count: int, + enforcer: ty.Optional[limit.Enforcer] = None +) -> int: """Return max instances possible, else raise TooManyInstances exception.""" if not limit_utils.use_unified_limits(): return max_count |