summaryrefslogtreecommitdiff
path: root/ick2/client.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-03-30 10:03:56 +0300
committerLars Wirzenius <liw@liw.fi>2018-03-30 10:32:54 +0300
commit974631edc803b66e4487431c596664371bf0400a (patch)
tree18d003e2e607a1619b1204f6d4529f5240649518 /ick2/client.py
parent3e98768fc55aedadc7362a58f50134db9eb4fc63 (diff)
downloadick2-974631edc803b66e4487431c596664371bf0400a.tar.gz
Add: BlobClient class to use artifact store API
Diffstat (limited to 'ick2/client.py')
-rw-r--r--ick2/client.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/ick2/client.py b/ick2/client.py
index 28d4c1e..c26b298 100644
--- a/ick2/client.py
+++ b/ick2/client.py
@@ -133,6 +133,13 @@ class ControllerClient:
version = self._api.get_dict(url)
return version.get('blob_service')
+ def get_blob_client(self):
+ url = self.get_blob_service_url()
+ blobs = BlobClient()
+ blobs.set_url(blobs)
+ blobs.set_http_api(self._api)
+ return blobs
+
def register(self):
assert self._url is not None
url = self.url('/workers')
@@ -159,3 +166,30 @@ class ControllerClient:
}
body = json.dumps(work)
self._api.post(url, headers=headers, body=body)
+
+
+class BlobClient:
+
+ def __init__(self):
+ self._url = None
+ self._api = None
+
+ def set_url(self, url):
+ self._url = url
+
+ def set_http_api(self, api):
+ self._api = api
+
+ def url(self, blob_name):
+ assert self._url is not None
+ return '{}/blobs/{}'.format(self._url, blob_name)
+
+ def download(self, blob_name):
+ logging.info('Download blob %s', blob_name)
+ url = self.url(blob_name)
+ return self._api.get_blob(url)
+
+ def upload(self, blob_name, blob):
+ logging.info('Upload blob %s', blob_name)
+ url = self.url(blob_name)
+ return self._api.put(url, body=blob)