Merge Rick's additions branch and make tiny fixups

This commit is contained in:
jaypipes@gmail.com 2010-12-21 10:07:16 -05:00
commit b1430797ec
4 changed files with 35 additions and 17 deletions

View File

@ -137,18 +137,17 @@ class BaseClient(object):
if status_code == httplib.OK:
return res
elif status_code == httplib.UNAUTHORIZED:
raise exception.NotAuthorized(res.body)
raise exception.NotAuthorized
elif status_code == httplib.FORBIDDEN:
raise exception.NotAuthorized(res.body)
raise exception.NotAuthorized
elif status_code == httplib.NOT_FOUND:
raise exception.NotFound(res.body)
raise exception.NotFound
elif status_code == httplib.CONFLICT:
raise exception.Duplicate(res.body)
raise exception.Duplicate
elif status_code == httplib.BAD_REQUEST:
raise exception.BadInputError(res.body)
raise exception.BadInputError
else:
raise Exception("Unknown error occurred! %d (%s)"
% (status_code, res.body))
raise Exception("Unknown error occurred! %d" % status_code)
except (socket.error, IOError), e:
raise ClientConnectionError("Unable to connect to "

View File

@ -52,10 +52,19 @@ def _deleted(context):
def image_create(_context, values):
values['size'] = int(values['size'])
values['is_public'] = bool(values.get('is_public', False))
properties = values.pop('properties', {})
image_ref = models.Image()
image_ref.update(values)
image_ref.save()
return image_ref
for key, value in properties.iteritems():
prop_values = {'image_id': image_ref.id, 'key': key, 'value': value}
image_property_create(_context, prop_values)
return image_get(_context, image_ref.id)
def image_destroy(_context, image_id):
@ -102,18 +111,25 @@ def image_get_by_str(context, str_id):
def image_update(_context, image_id, values):
session = get_session()
with session.begin():
values['size'] = int(values['size'])
values['is_public'] = bool(values.get('is_public', False))
properties = values.pop('properties', {})
image_ref = models.Image.find(image_id, session=session)
image_ref.update(values)
image_ref.save(session=session)
for key, value in properties.iteritems():
prop_values = {'image_id': image_ref.id, 'key': key, 'value': value}
image_property_create(_context, prop_values)
###################
def image_file_create(_context, values):
image_file_ref = models.ImageFile()
for (key, value) in values.iteritems():
image_file_ref[key] = value
image_file_ref.update(values)
image_file_ref.save()
return image_file_ref
@ -122,8 +138,7 @@ def image_file_create(_context, values):
def image_property_create(_context, values):
image_properties_ref = models.ImageProperty()
for (key, value) in values.iteritems():
image_properties_ref[key] = value
image_properties_ref.save()
return image_properties_ref
image_property_ref = models.ImageProperty()
image_property_ref.update(values)
image_property_ref.save()
return image_property_ref

View File

@ -218,7 +218,6 @@ class Controller(wsgi.Controller):
image_meta['status'] = image_status
image_meta['store'] = image_store
try:
image_meta = registry.add_image_metadata(image_meta)

View File

@ -115,7 +115,12 @@ class FilesystemBackend(glance.store.Backend):
:retval The location that was written, with file:// scheme prepended
"""
filepath = os.path.join(FLAGS.filesystem_store_datadir, str(id))
datadir = FLAGS.filesystem_store_datadir
if not os.path.exists(datadir):
os.makedirs(datadir)
filepath = os.path.join(datadir, str(id))
if os.path.exists(filepath):
raise exception.Duplicate("Image file %s already exists!"