summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreddie-sheffield <eddie.sheffield@rackspace.com>2013-07-31 12:21:41 -0400
committereddie-sheffield <eddie.sheffield@rackspace.com>2013-07-31 12:28:24 -0400
commite827c37a05687d4fdd9b81a4b241e199a790ef1a (patch)
tree85a465955af202acfc3c51c4ae93f70cc97607ee
parent937b65b513ae53193c0c731a6d8e89ec310f1882 (diff)
downloadpython-glanceclient-e827c37a05687d4fdd9b81a4b241e199a790ef1a.tar.gz
Changes to allow image upload with V2 api
Related to bp glance-client-v2 Change-Id: I72a1d2825dd5c1ff4890e8be477cb4447d59f136
-rw-r--r--glanceclient/v2/images.py13
-rw-r--r--tests/v2/test_images.py15
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)