Enable client library V2 to create an image.

Adds support for creating an image to the client library only, not the CLI.
Replaced reference to deprecated BaseException.message

Related to bp glance-client-v2

Change-Id: I8e3d09d89493368d22f7b1f69f79ebd2518e289d
This commit is contained in:
eddie-sheffield
2013-07-02 16:34:00 -04:00
parent 49a1207266
commit 92e4ee201a
2 changed files with 36 additions and 0 deletions
+19
View File
@@ -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.