diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-07-31 19:10:12 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-07-31 19:10:12 +0000 |
commit | 43e71e399372102f8ef4a3b7ad836fe16ace63a3 (patch) | |
tree | 4e9e7d946020f1f8431c325647036f0d5d38401a | |
parent | 5c4fb2f7a1a8943018dcad21ae6f8a0ed310d4cc (diff) | |
parent | e827c37a05687d4fdd9b81a4b241e199a790ef1a (diff) | |
download | python-glanceclient-43e71e399372102f8ef4a3b7ad836fe16ace63a3.tar.gz |
Merge "Changes to allow image upload with V2 api"
-rw-r--r-- | glanceclient/v2/images.py | 13 | ||||
-rw-r--r-- | tests/v2/test_images.py | 15 |
2 files changed, 28 insertions, 0 deletions
diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index b3c5ff5..fe24b0a 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -88,6 +88,19 @@ class Controller(object): else: return body + def upload(self, image_id, image_data): + """ + Upload the data for an image. + + :param image_id: ID of the image to upload data for. + :param image_data: File-like object supplying the data to upload. + """ + url = '/v2/images/%s/file' % image_id + hdrs = {'Content-Type': 'application/octet-stream'} + self.http_client.raw_request('PUT', url, + headers=hdrs, + body=image_data) + def delete(self, image_id): """Delete an image.""" self.http_client.json_request('DELETE', 'v2/images/%s' % image_id) diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py index 0dd814d..df68ac6 100644 --- a/tests/v2/test_images.py +++ b/tests/v2/test_images.py @@ -105,6 +105,12 @@ fixtures = { }, ), }, + '/v2/images/606b0e88-7c5a-4d54-b5bb-046105d4de6f/file': { + 'PUT': ( + {}, + '', + ), + }, '/v2/images/5cc4bebc-db27-11e1-a1eb-080027cbe205/file': { 'GET': ( {}, @@ -355,6 +361,15 @@ class TestController(testtools.TestCase): None)] self.assertEqual(self.api.calls, expect) + def test_data_upload(self): + image_data = 'CCC' + image_id = '606b0e88-7c5a-4d54-b5bb-046105d4de6f' + self.controller.upload(image_id, image_data) + expect = [('PUT', '/v2/images/%s/file' % image_id, + {'Content-Type': 'application/octet-stream'}, + image_data)] + self.assertEqual(self.api.calls, expect) + def test_data_without_checksum(self): body = self.controller.data('5cc4bebc-db27-11e1-a1eb-080027cbe205', do_checksum=False) |