summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-03-03 11:18:20 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2015-03-03 18:41:49 +0000
commit1ca5c972f8ba20fafe252391fca5646831ae404e (patch)
tree12dce93d363c0a3e1d3661945575105a17c2da6f
parent4ef36b3a82b310392cbd6a19c48591e0b3129505 (diff)
downloadmorph-1ca5c972f8ba20fafe252391fca5646831ae404e.tar.gz
RemoteArtifactCache: Support multiple cache methods
This commit updates RemoteArtifactCache to enable it to interact with a remote OSTree artifact cache.
-rw-r--r--morphlib/remoteartifactcache.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/morphlib/remoteartifactcache.py b/morphlib/remoteartifactcache.py
index 4e09ce34..2f82aaec 100644
--- a/morphlib/remoteartifactcache.py
+++ b/morphlib/remoteartifactcache.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2014 Codethink Limited
+# Copyright (C) 2012-2015 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -58,6 +58,18 @@ class RemoteArtifactCache(object):
def __init__(self, server_url):
self.server_url = server_url
+ self.name = urlparse.urlparse(server_url).hostname
+ try:
+ self.method = self._get_method()
+ except urllib2.URLError:
+ self.method = 'tarball'
+ except Exception as e: # pragma: no cover
+ logging.debug('Failed to determine cache method: %s' % e)
+ raise cliapp.AppException('Failed to determine method used by '
+ 'remote cache.')
+ if self.method == 'ostree': # pragma: no cover
+ self.ostree_url = 'http://%s:%s/' % (self.name,
+ self._get_ostree_info())
def has(self, artifact):
return self._has_file(artifact.basename())
@@ -113,5 +125,18 @@ class RemoteArtifactCache(object):
server_url, '/1.0/artifacts?filename=%s' %
urllib.quote(filename))
+ def _get_method(self): # pragma: no cover
+ logging.debug('Getting cache method of %s' % self.server_url)
+ request_url = urlparse.urljoin(self.server_url, '/1.0/method')
+ req = urllib2.urlopen(request_url)
+ return req.read()
+
+ def _get_ostree_info(self): # pragma: no cover
+ logging.debug('Getting OSTree repo info.')
+ request_url = urlparse.urljoin(self.server_url, '/1.0/ostreeinfo')
+ logging.debug('sending %s' % request_url)
+ req = urllib2.urlopen(request_url)
+ return req.read()
+
def __str__(self): # pragma: no cover
return self.server_url