Merge "Enable client library V2 to create an image."
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user