Clean up cache interface, add support for services
We just added an unreleased interface method to the CloudConfig object - but maybe that should have been more aligned with dogpile words. SO - change the docs to reference the dogpile words and add support for that, while keeping backwards compat support for people using max_age. Also, do the -/_ transform on the cache config like elsewhere. Then, while we're in there, add support for per-service cache timings. We need this in nodepool and shade is adding support, so ability to configure it will be important. Change-Id: I31190a31ab0b79fc080db3611c0cd584076387d4
This commit is contained in:
13
README.rst
13
README.rst
@@ -168,9 +168,15 @@ understands passing through cache settings to dogpile.cache, with the following
|
|||||||
behaviors:
|
behaviors:
|
||||||
|
|
||||||
* Listing no config settings means you get a null cache.
|
* Listing no config settings means you get a null cache.
|
||||||
* `cache.max_age` and nothing else gets you memory cache.
|
* `cache.expiration_time` and nothing else gets you memory cache.
|
||||||
* Otherwise, `cache.class` and `cache.arguments` are passed in
|
* Otherwise, `cache.class` and `cache.arguments` are passed in
|
||||||
|
|
||||||
|
Different cloud behaviors are also differently expensive to deal with. If you
|
||||||
|
want to get really crazy and tweak stuff, you can specify different expiration
|
||||||
|
times on a per-resource basis by passing values, in seconds to an expiration
|
||||||
|
mapping keyed on the singular name of the resource. A value of `-1` indicates
|
||||||
|
that the resource should never expire.
|
||||||
|
|
||||||
`os-client-config` does not actually cache anything itself, but it collects
|
`os-client-config` does not actually cache anything itself, but it collects
|
||||||
and presents the cache information so that your various applications that
|
and presents the cache information so that your various applications that
|
||||||
are connecting to OpenStack can share a cache should you desire.
|
are connecting to OpenStack can share a cache should you desire.
|
||||||
@@ -179,10 +185,13 @@ are connecting to OpenStack can share a cache should you desire.
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
class: dogpile.cache.pylibmc
|
class: dogpile.cache.pylibmc
|
||||||
max_age: 3600
|
expiration_time: 3600
|
||||||
arguments:
|
arguments:
|
||||||
url:
|
url:
|
||||||
- 127.0.0.1
|
- 127.0.0.1
|
||||||
|
expiration:
|
||||||
|
server: 5
|
||||||
|
flavor: -1
|
||||||
clouds:
|
clouds:
|
||||||
mordred:
|
mordred:
|
||||||
profile: hp
|
profile: hp
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ class CloudConfig(object):
|
|||||||
"""Return a keystoneauth plugin from the auth credentials."""
|
"""Return a keystoneauth plugin from the auth credentials."""
|
||||||
return self._auth
|
return self._auth
|
||||||
|
|
||||||
def get_cache_interval(self):
|
def get_cache_expiration_time(self):
|
||||||
if self._openstack_config:
|
if self._openstack_config:
|
||||||
return self._openstack_config.get_cache_interval()
|
return self._openstack_config.get_cache_expiration_time()
|
||||||
|
|
||||||
def get_cache_path(self):
|
def get_cache_path(self):
|
||||||
if self._openstack_config:
|
if self._openstack_config:
|
||||||
@@ -134,3 +134,20 @@ class CloudConfig(object):
|
|||||||
def get_cache_arguments(self):
|
def get_cache_arguments(self):
|
||||||
if self._openstack_config:
|
if self._openstack_config:
|
||||||
return self._openstack_config.get_cache_arguments()
|
return self._openstack_config.get_cache_arguments()
|
||||||
|
|
||||||
|
def get_cache_expiration(self):
|
||||||
|
if self._openstack_config:
|
||||||
|
return self._openstack_config.get_cache_expiration()
|
||||||
|
|
||||||
|
def get_cache_resource_expiration(self, resource):
|
||||||
|
"""Get expiration time for a resource
|
||||||
|
|
||||||
|
:param resource: Name of the resource type
|
||||||
|
|
||||||
|
:returns: Expiration time for the resource type or None
|
||||||
|
"""
|
||||||
|
if self._openstack_config:
|
||||||
|
expiration = self._openstack_config.get_cache_expiration()
|
||||||
|
if resource not in expiration:
|
||||||
|
return None
|
||||||
|
return expiration[resource]
|
||||||
|
|||||||
@@ -182,21 +182,34 @@ class OpenStackConfig(object):
|
|||||||
self.cloud_config = dict(
|
self.cloud_config = dict(
|
||||||
clouds=dict(defaults=dict(self.defaults)))
|
clouds=dict(defaults=dict(self.defaults)))
|
||||||
|
|
||||||
self._cache_max_age = 0
|
self._cache_expiration_time = 0
|
||||||
self._cache_path = CACHE_PATH
|
self._cache_path = CACHE_PATH
|
||||||
self._cache_class = 'dogpile.cache.null'
|
self._cache_class = 'dogpile.cache.null'
|
||||||
self._cache_arguments = {}
|
self._cache_arguments = {}
|
||||||
|
self._cache_expiration = {}
|
||||||
if 'cache' in self.cloud_config:
|
if 'cache' in self.cloud_config:
|
||||||
self._cache_max_age = self.cloud_config['cache'].get(
|
cache_settings = self._normalize_keys(self.cloud_config['cache'])
|
||||||
'max_age', self._cache_max_age)
|
|
||||||
if self._cache_max_age:
|
# expiration_time used to be 'max_age' but the dogpile setting
|
||||||
|
# is expiration_time. Support max_age for backwards compat.
|
||||||
|
self._cache_expiration_time = cache_settings.get(
|
||||||
|
'expiration_time', cache_settings.get(
|
||||||
|
'max_age', self._cache_expiration_time))
|
||||||
|
|
||||||
|
# If cache class is given, use that. If not, but if cache time
|
||||||
|
# is given, default to memory. Otherwise, default to nothing.
|
||||||
|
# to memory.
|
||||||
|
if self._cache_expiration_time:
|
||||||
self._cache_class = 'dogpile.cache.memory'
|
self._cache_class = 'dogpile.cache.memory'
|
||||||
self._cache_path = os.path.expanduser(
|
|
||||||
self.cloud_config['cache'].get('path', self._cache_path))
|
|
||||||
self._cache_class = self.cloud_config['cache'].get(
|
self._cache_class = self.cloud_config['cache'].get(
|
||||||
'class', self._cache_class)
|
'class', self._cache_class)
|
||||||
self._cache_arguments = self.cloud_config['cache'].get(
|
|
||||||
|
self._cache_path = os.path.expanduser(
|
||||||
|
cache_settings.get('path', self._cache_path))
|
||||||
|
self._cache_arguments = cache_settings.get(
|
||||||
'arguments', self._cache_arguments)
|
'arguments', self._cache_arguments)
|
||||||
|
self._cache_expiration = cache_settings.get(
|
||||||
|
'expiration', self._cache_expiration)
|
||||||
|
|
||||||
def _load_config_file(self):
|
def _load_config_file(self):
|
||||||
return self._load_yaml_file(self._config_files)
|
return self._load_yaml_file(self._config_files)
|
||||||
@@ -221,11 +234,14 @@ class OpenStackConfig(object):
|
|||||||
new_config[key] = value
|
new_config[key] = value
|
||||||
return new_config
|
return new_config
|
||||||
|
|
||||||
|
def get_cache_expiration_time(self):
|
||||||
|
return self._cache_expiration_time
|
||||||
|
|
||||||
def get_cache_interval(self):
|
def get_cache_interval(self):
|
||||||
return self._cache_max_age
|
return self._cache_expiration_time
|
||||||
|
|
||||||
def get_cache_max_age(self):
|
def get_cache_max_age(self):
|
||||||
return self._cache_max_age
|
return self._cache_expiration_time
|
||||||
|
|
||||||
def get_cache_path(self):
|
def get_cache_path(self):
|
||||||
return self._cache_path
|
return self._cache_path
|
||||||
@@ -234,7 +250,10 @@ class OpenStackConfig(object):
|
|||||||
return self._cache_class
|
return self._cache_class
|
||||||
|
|
||||||
def get_cache_arguments(self):
|
def get_cache_arguments(self):
|
||||||
return self._cache_arguments
|
return self._cache_arguments.copy()
|
||||||
|
|
||||||
|
def get_cache_expiration(self):
|
||||||
|
return self._cache_expiration.copy()
|
||||||
|
|
||||||
def _get_regions(self, cloud):
|
def _get_regions(self, cloud):
|
||||||
if cloud not in self.cloud_config['clouds']:
|
if cloud not in self.cloud_config['clouds']:
|
||||||
|
|||||||
Reference in New Issue
Block a user