Merge pull request #14030 from matburt/add_rax_inventory_custom_cache_timeout
Add a config option for rackspace inventory cache
This commit is contained in:
commit
3bda79ca96
2 changed files with 13 additions and 1 deletions
|
@ -55,3 +55,12 @@
|
||||||
# will be ignored, and 4 will be used. Accepts a comma separated list,
|
# will be ignored, and 4 will be used. Accepts a comma separated list,
|
||||||
# the first found wins.
|
# the first found wins.
|
||||||
# access_ip_version = 4
|
# access_ip_version = 4
|
||||||
|
|
||||||
|
# Environment Variable: RAX_CACHE_MAX_AGE
|
||||||
|
# Default: 600
|
||||||
|
#
|
||||||
|
# A configuration the changes the behavior or the inventory cache.
|
||||||
|
# Inventory listing performed before this value will be returned from
|
||||||
|
# the cache instead of making a full request for all inventory. Setting
|
||||||
|
# this value to 0 will force a full request.
|
||||||
|
# cache_max_age = 600
|
|
@ -355,9 +355,12 @@ def get_cache_file_path(regions):
|
||||||
|
|
||||||
|
|
||||||
def _list(regions, refresh_cache=True):
|
def _list(regions, refresh_cache=True):
|
||||||
|
cache_max_age = int(get_config(p, 'rax', 'cache_max_age',
|
||||||
|
'RAX_CACHE_MAX_AGE', 600))
|
||||||
|
|
||||||
if (not os.path.exists(get_cache_file_path(regions)) or
|
if (not os.path.exists(get_cache_file_path(regions)) or
|
||||||
refresh_cache or
|
refresh_cache or
|
||||||
(time() - os.stat(get_cache_file_path(regions))[-1]) > 600):
|
(time() - os.stat(get_cache_file_path(regions))[-1]) > cache_max_age):
|
||||||
# Cache file doesn't exist or older than 10m or refresh cache requested
|
# Cache file doesn't exist or older than 10m or refresh cache requested
|
||||||
_list_into_cache(regions)
|
_list_into_cache(regions)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue