move cache to instance specific dir
This commit is contained in:
parent
606fdd15b2
commit
30b97a8001
@ -19,6 +19,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
varlibdir = '/var/lib/cloud'
|
varlibdir = '/var/lib/cloud'
|
||||||
|
cur_instance_link = varlibdir + "/instance"
|
||||||
datadir = '/var/lib/cloud/data'
|
datadir = '/var/lib/cloud/data'
|
||||||
semdir = '/var/lib/cloud/sem'
|
semdir = '/var/lib/cloud/sem'
|
||||||
cachedir = datadir + '/cache'
|
cachedir = datadir + '/cache'
|
||||||
@ -115,6 +116,7 @@ class CloudInit:
|
|||||||
"boothooks" : "/boothooks",
|
"boothooks" : "/boothooks",
|
||||||
"userdata_raw" : "/user-data.txt",
|
"userdata_raw" : "/user-data.txt",
|
||||||
"userdata" : "/user-data-raw.txt.i",
|
"userdata" : "/user-data-raw.txt.i",
|
||||||
|
"obj_pkl" : "/obj.pkl",
|
||||||
None : "",
|
None : "",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +157,11 @@ class CloudInit:
|
|||||||
|
|
||||||
def restore_from_cache(self):
|
def restore_from_cache(self):
|
||||||
try:
|
try:
|
||||||
f=open(data_source_cache, "rb")
|
# we try to restore from a current link and static path
|
||||||
|
# by using the instance link, if purge_cache was called
|
||||||
|
# the file wont exist
|
||||||
|
cache = "%s/%s" % (cur_instance_link, self.pathmap['obj_pkl'])
|
||||||
|
f=open(cache, "rb")
|
||||||
data = cPickle.load(f)
|
data = cPickle.load(f)
|
||||||
self.datasource = data
|
self.datasource = data
|
||||||
return True
|
return True
|
||||||
@ -163,16 +169,17 @@ class CloudInit:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def write_to_cache(self):
|
def write_to_cache(self):
|
||||||
|
cache = self.get_ipath("obj_pkl")
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(data_source_cache))
|
os.makedirs(os.path.dirname(cache))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EEXIST:
|
if e.errno != errno.EEXIST:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f=open(data_source_cache, "wb")
|
f=open(cache, "wb")
|
||||||
data = cPickle.dump(self.datasource,f)
|
data = cPickle.dump(self.datasource,f)
|
||||||
os.chmod(data_source_cache,0400)
|
os.chmod(cache,0400)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
@ -195,6 +202,7 @@ class CloudInit:
|
|||||||
for ds in cfglist.split(','):
|
for ds in cfglist.split(','):
|
||||||
dslist.append(strip(ds).tolower())
|
dslist.append(strip(ds).tolower())
|
||||||
|
|
||||||
|
log.debug("searching for data source in [%s]" % str(dslist))
|
||||||
for ds in dslist:
|
for ds in dslist:
|
||||||
if ds not in self.datasource_map:
|
if ds not in self.datasource_map:
|
||||||
log.warn("data source %s not found in map" % ds)
|
log.warn("data source %s not found in map" % ds)
|
||||||
@ -214,13 +222,12 @@ class CloudInit:
|
|||||||
raise DataSourceNotFoundException("Could not find data source")
|
raise DataSourceNotFoundException("Could not find data source")
|
||||||
|
|
||||||
def set_cur_instance(self):
|
def set_cur_instance(self):
|
||||||
lname = "%s/instance" % varlibdir
|
|
||||||
try:
|
try:
|
||||||
os.unlink(lname)
|
os.unlink(cur_instance_link)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno != errno.ENOENT: raise
|
if e.errno != errno.ENOENT: raise
|
||||||
|
|
||||||
os.symlink("./instances/%s" % self.get_instance_id(), lname)
|
os.symlink("./instances/%s" % self.get_instance_id(), cur_instance_link)
|
||||||
idir = self.get_ipath()
|
idir = self.get_ipath()
|
||||||
dlist = []
|
dlist = []
|
||||||
for d in [ "handlers", "scripts", "sem" ]:
|
for d in [ "handlers", "scripts", "sem" ]:
|
||||||
@ -495,7 +502,7 @@ def initfs():
|
|||||||
|
|
||||||
def purge_cache():
|
def purge_cache():
|
||||||
try:
|
try:
|
||||||
os.unlink(data_source_cache)
|
os.unlink(cur_instance_link)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT: return(False)
|
if e.errno != errno.ENOENT: return(False)
|
||||||
except:
|
except:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user