diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-07-30 22:08:19 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-07-30 22:08:19 +0000 |
commit | 937b65b513ae53193c0c731a6d8e89ec310f1882 (patch) | |
tree | 376c7b04422b76c7bc7a3bff628db55b796143ec | |
parent | 2d86c5dcdefc133dde59ac9b1ffa3b8c88e29d74 (diff) | |
parent | 92e4ee201a5b5f7a9cd210bf34f59e2efaca134b (diff) | |
download | python-glanceclient-937b65b513ae53193c0c731a6d8e89ec310f1882.tar.gz |
Merge "Enable client library V2 to create an image."
-rw-r--r-- | glanceclient/v2/images.py | 19 | ||||
-rw-r--r-- | tests/v2/test_images.py | 17 |
2 files changed, 36 insertions, 0 deletions
diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index 8e42e99..b3c5ff5 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -15,6 +15,8 @@ import urllib +import warlock + from glanceclient.common import utils from glanceclient.openstack.common import strutils @@ -90,6 +92,23 @@ class Controller(object): """Delete an image.""" self.http_client.json_request('DELETE', 'v2/images/%s' % image_id) + def create(self, **kwargs): + """Create an image.""" + url = '/v2/images' + + image = self.model() + for (key, value) in kwargs.items(): + try: + setattr(image, key, value) + except warlock.InvalidOperation, e: + raise TypeError(unicode(message)) + + resp, body = self.http_client.json_request('POST', url, body=image) + #NOTE(esheffield): remove 'self' for now until we have an elegant + # way to pass it into the model constructor without conflict + body.pop('self', None) + return self.model(**body) + def update(self, image_id, **kwargs): """ Update attributes of an image. diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py index 430c12e..0dd814d 100644 --- a/tests/v2/test_images.py +++ b/tests/v2/test_images.py @@ -88,6 +88,15 @@ fixtures = { '', ), }, + '/v2/images': { + 'POST': ( + {}, + { + 'id': '3a4560a1-e585-443e-9b39-553b46ec92d1', + 'name': 'image-1', + }, + ), + }, 'v2/images/87b634c1-f893-33c9-28a9-e5673c99239a': { 'DELETE': ( {}, @@ -329,6 +338,14 @@ class TestController(testtools.TestCase): self.assertEqual(image.id, '3a4560a1-e585-443e-9b39-553b46ec92d1') self.assertEqual(image.name, 'image-1') + def test_create_image(self): + properties = { + 'name': 'image-1' + } + image = self.controller.create(**properties) + self.assertEqual(image.id, '3a4560a1-e585-443e-9b39-553b46ec92d1') + self.assertEqual(image.name, 'image-1') + def test_delete_image(self): self.controller.delete('87b634c1-f893-33c9-28a9-e5673c99239a') expect = [ |