summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-03-03 11:18:20 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-04-20 14:07:41 +0000
commitdabac83a6a5e5deaa34922e13e137129c1660fe8 (patch)
tree022dc982ff3009e04b85d6d9ab548d533c4354d1
parenta97d8b313d931bfc6d8c1341af91fc48a8250f33 (diff)
downloadmorph-dabac83a6a5e5deaa34922e13e137129c1660fe8.tar.gz
RemoteArtifactCache: Support multiple cache methods
This commit updates RemoteArtifactCache to enable it to interact with a remote OSTree artifact cache. Change-Id: Icdb2d3071adb6532e54ab7f203c391b3a30a1c63
-rw-r--r--morphlib/remoteartifactcache.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/morphlib/remoteartifactcache.py b/morphlib/remoteartifactcache.py
index 427e4cbb..f5115cd6 100644
--- a/morphlib/remoteartifactcache.py
+++ b/morphlib/remoteartifactcache.py
@@ -57,6 +57,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())
@@ -112,5 +124,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