Make directory for filesystem backend

This commit is contained in:
Rick Harris 2010-12-20 23:30:04 -06:00
parent cff6301bc1
commit d4bb114194
4 changed files with 30 additions and 10 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['size'])
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,10 +111,18 @@ 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['size'])
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)
###################

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!"