summaryrefslogtreecommitdiff
path: root/nova/limit
diff options
context:
space:
mode:
authorJohn Garbutt <john@johngarbutt.com>2020-03-17 16:26:20 +0000
committermelanie witt <melwittt@gmail.com>2022-02-24 16:21:03 +0000
commitd80d253cf90843d6721f71d31f1a24e68674e99a (patch)
treef30c493c034391e73386b19e0bedc27bb2488e1f /nova/limit
parent140b3b81f924c98299c361a76042873b77745fbe (diff)
downloadnova-d80d253cf90843d6721f71d31f1a24e68674e99a.tar.gz
Add legacy limits and usage to placement unified limits
Before we can update the API to say what limits are set in keystone we need to logic to pull that information from keystone. blueprint unified-limits-nova Change-Id: I322d5143f3088b04d1d990880b57afc9dc08af6c
Diffstat (limited to 'nova/limit')
-rw-r--r--nova/limit/placement.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/nova/limit/placement.py b/nova/limit/placement.py
index 2e04e015e6..95beffaff0 100644
--- a/nova/limit/placement.py
+++ b/nova/limit/placement.py
@@ -32,6 +32,12 @@ CONF = nova.conf.CONF
# Cache to avoid repopulating ksa state
PLACEMENT_CLIENT = None
+LEGACY_LIMITS = {
+ "servers": "instances",
+ "class:VCPU": "cores",
+ "class:MEMORY_MB": "ram",
+}
+
def _get_placement_usages(context, project_id):
global PLACEMENT_CLIENT
@@ -166,3 +172,30 @@ def enforce_num_instances_and_flavor(context, project_id, flavor, is_bfvm,
# no problems with max_count, so we return max count
return max_count
+
+
+def _convert_keys_to_legacy_name(new_dict):
+ legacy = {}
+ for new_name, old_name in LEGACY_LIMITS.items():
+ # defensive incase oslo or keystone doesn't give us an answer
+ legacy[old_name] = new_dict.get(new_name) or 0
+ return legacy
+
+
+def get_legacy_default_limits():
+ enforcer = limit.Enforcer(lambda: None)
+ new_limits = enforcer.get_registered_limits(LEGACY_LIMITS.keys())
+ return _convert_keys_to_legacy_name(dict(new_limits))
+
+
+def get_legacy_project_limits(project_id):
+ enforcer = limit.Enforcer(lambda: None)
+ new_limits = enforcer.get_project_limits(project_id, LEGACY_LIMITS.keys())
+ return _convert_keys_to_legacy_name(dict(new_limits))
+
+
+def get_legacy_counts(context, project_id):
+ resource_names = list(LEGACY_LIMITS.keys())
+ resource_names.sort()
+ new_usage = _get_usage(context, project_id, resource_names)
+ return _convert_keys_to_legacy_name(new_usage)