summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-07 10:14:27 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-07 13:44:19 +0100
commit465e830d1d6d2c51425e2418b8e802a95145b6ee (patch)
treecd440355635a8a540de38e86bb12f056af2706b9
parent9c3279221262057c7eb8ebdcb29f366dc4de66d5 (diff)
downloadmorph-465e830d1d6d2c51425e2418b8e802a95145b6ee.tar.gz
Add a /list method
When --enable-writes is set, we provide a /list target which produces a JSON dictionary of information about the state of the artifact cache. The dictionary is of the form: { "freespace": NBYTES_OF_SPACE, "files": { "artifact-filename": { "atime": ATIME_AS_NUMBER, "size": NBYTES_SIZE_OF_FILE, "used": NBYTES_USED_ON_DISK }, ... } } This allows a controller to decide which artifacts have not been requested in some time and also how big artifacts are, not only in terms of their 'byte' size, but also the space they consume on disk. System images in particular may differ in this respect since they should be sparsely stored.
-rwxr-xr-xmorph-cache-server22
1 files changed, 22 insertions, 0 deletions
diff --git a/morph-cache-server b/morph-cache-server
index ba5f0b2a..b726c1e5 100755
--- a/morph-cache-server
+++ b/morph-cache-server
@@ -83,6 +83,28 @@ class MorphCacheServer(cliapp.Application):
return app.get(prefix)
return lambda fn: fn
+ @writable('/list')
+ def list():
+ response.set_header('Cache-Control', 'no-cache')
+ results = {}
+ files = {}
+ results["files"] = files
+ for artifactdir, __, filenames in \
+ os.walk(self.settings['artifact-dir']):
+ fsstinfo = os.statvfs(artifactdir)
+ results["freespace"] = fsstinfo.f_bsize * fsstinfo.f_bavail
+ for fname in filenames:
+ try:
+ stinfo = os.stat("%s/%s" % (artifactdir, fname))
+ files[fname] = {
+ "atime": stinfo.st_atime,
+ "size": stinfo.st_size,
+ "used": stinfo.st_blocks * 512,
+ }
+ except Exception, e:
+ print(e)
+ return results
+
@app.get('/sha1s')
def sha1():
repo = self._unescape_parameter(request.query.repo)