Name cache file by relevant regions - they might change between calls.

Also, use old school string interpolation so that the plugin is compatible with
Python < 2.7.
pull/11923/head
Tom Berger 10 years ago committed by Abhijit Menon-Sen
parent cd1125aac2
commit 07a4076d12

@ -339,23 +339,25 @@ def _list_into_cache(regions):
if hostvars:
groups['_meta'] = {'hostvars': hostvars}
with open(get_cache_file_path(), 'w') as cache_file:
with open(get_cache_file_path(regions), 'w') as cache_file:
json.dump(groups, cache_file)
def get_cache_file_path():
def get_cache_file_path(regions):
regions_str = '.'.join([reg.strip().lower() for reg in regions])
return os.path.join(gettempdir(),
'ansible-rax-{}.cache'.format(pyrax.identity.username))
'ansible-rax-%s-%s.cache' % (
pyrax.identity.username, regions_str))
def _list(regions, refresh_cache=True):
if (not os.path.exists(get_cache_file_path()) or
if (not os.path.exists(get_cache_file_path(regions)) or
refresh_cache or
(time() - os.stat(get_cache_file_path())[-1]) > 600):
(time() - os.stat(get_cache_file_path(regions))[-1]) > 600):
# Cache file doesn't exist or older than 10m or refresh cache requested
_list_into_cache(regions)
with open(get_cache_file_path(), 'r') as cache_file:
with open(get_cache_file_path(regions), 'r') as cache_file:
groups = json.load(cache_file)
print(json.dumps(groups, sort_keys=True, indent=4))

Loading…
Cancel
Save