From 974631edc803b66e4487431c596664371bf0400a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 30 Mar 2018 10:03:56 +0300 Subject: Add: BlobClient class to use artifact store API --- ick2/client.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'ick2/client.py') 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) -- cgit v1.2.1