From 91e423a36928ee5ea52de0b6836d0c34cc20fdd2 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 2 Mar 2010 14:10:55 -0500 Subject: purge cache in cloud-init so it doesn't end up persisting across instances The cache file location is not instance specific. As such, if it is not cleaned from the image, a re-bundle would get the old data. To avoid that, clear the cache in cloud-init. --- cloud-init.py | 3 +++ cloudinit/__init__.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/cloud-init.py b/cloud-init.py index 1db2ea60..c92f07cd 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -26,6 +26,9 @@ def warn(str): sys.stderr.write(str) def main(): + # cache is not instance specific, so it has to be purged + cloudinit.purge_cache() + cloud = cloudinit.CloudInit() try: diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 8d6ec59e..1d8a1898 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -318,3 +318,13 @@ class CloudInit: def device_name_to_device(self,name): return(self.datasource.device_name_to_device(name)) + + +def purge_cache(): + try: + os.unlink(data_source_cache) + except OSError as e: + if e.errno != errno.ENOENT: return(False) + except: + return(False) + return(True) -- cgit v1.2.3