summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>2013-06-13 09:27:38 -0400
committerMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>2013-06-14 00:12:46 -0400
commit73f71555ca16360f06a2337848dfc0a02119508f (patch)
treea5231be3a9b13109681397295821666241a1e117 /nova/api
parentf6838316da6f69851cba06f9b45a91a2ee04179a (diff)
downloadnova-73f71555ca16360f06a2337848dfc0a02119508f.tar.gz
nova-73f71555ca16360f06a2337848dfc0a02119508f.tar.xz
nova-73f71555ca16360f06a2337848dfc0a02119508f.zip
Organize limits units and per-units constants
During v3 api review there was an agreement that would be nice to move limits constants to utils file and refactor its usage inside limits api to avoid unnecessary code duplication. Also changed TestLimiter class to MockLimiter since that name can be confuse to some unit test frameworks. Change-Id: I1b8626e8d1e3257333d4dfee61591fd4cde82bd1
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/limits.py34
1 files changed, 11 insertions, 23 deletions
diff --git a/nova/api/openstack/compute/limits.py b/nova/api/openstack/compute/limits.py
index 07e791306..107f40436 100644
--- a/nova/api/openstack/compute/limits.py
+++ b/nova/api/openstack/compute/limits.py
@@ -33,19 +33,13 @@ from nova.api.openstack import xmlutil
from nova.openstack.common import importutils
from nova.openstack.common import jsonutils
from nova import quota
+from nova import utils
from nova import wsgi as base_wsgi
QUOTAS = quota.QUOTAS
-# Convenience constants for the limits dictionary passed to Limiter().
-PER_SECOND = 1
-PER_MINUTE = 60
-PER_HOUR = 60 * 60
-PER_DAY = 60 * 60 * 24
-
-
limits_nsmap = {None: xmlutil.XMLNS_COMMON_V10, 'atom': xmlutil.XMLNS_ATOM}
@@ -122,14 +116,7 @@ class Limit(object):
Stores information about a limit for HTTP requests.
"""
- UNITS = {
- 1: "SECOND",
- 60: "MINUTE",
- 60 * 60: "HOUR",
- 60 * 60 * 24: "DAY",
- }
-
- UNIT_MAP = dict([(v, k) for k, v in UNITS.items()])
+ UNITS = dict([(v, k) for k, v in utils.TIME_UNITS.items()])
def __init__(self, verb, uri, regex, value, unit):
"""
@@ -223,12 +210,13 @@ class Limit(object):
# a regular-expression to match, value and unit of measure (PER_DAY, etc.)
DEFAULT_LIMITS = [
- Limit("POST", "*", ".*", 10, PER_MINUTE),
- Limit("POST", "*/servers", "^/servers", 50, PER_DAY),
- Limit("PUT", "*", ".*", 10, PER_MINUTE),
- Limit("GET", "*changes-since*", ".*changes-since.*", 3, PER_MINUTE),
- Limit("DELETE", "*", ".*", 100, PER_MINUTE),
- Limit("GET", "*/os-fping", "^/os-fping", 12, PER_HOUR),
+ Limit("POST", "*", ".*", 10, utils.TIME_UNITS['MINUTE']),
+ Limit("POST", "*/servers", "^/servers", 50, utils.TIME_UNITS['DAY']),
+ Limit("PUT", "*", ".*", 10, utils.TIME_UNITS['MINUTE']),
+ Limit("GET", "*changes-since*", ".*changes-since.*", 3,
+ utils.TIME_UNITS['MINUTE']),
+ Limit("DELETE", "*", ".*", 100, utils.TIME_UNITS['MINUTE']),
+ Limit("GET", "*/os-fping", "^/os-fping", 12, utils.TIME_UNITS['HOUR']),
]
@@ -390,9 +378,9 @@ class Limiter(object):
# Convert unit
unit = unit.upper()
- if unit not in Limit.UNIT_MAP:
+ if unit not in utils.TIME_UNITS:
raise ValueError("Invalid units specified")
- unit = Limit.UNIT_MAP[unit]
+ unit = utils.TIME_UNITS[unit]
# Build a limit
result.append(Limit(verb, uri, regex, value, unit))