~jaypipes/glance/bug759018

« back to all changes in this revision

Viewing changes to glance/store/__init__.py

  • Committer: Tarmac
  • Author(s): jaypipes at gmail
  • Date: 2011-03-25 19:17:35 UTC
  • mfrom: (75.3.13 checksum)
  • Revision ID: tarmac-20110325191735-rk1wy065cloviubu
Adds checksumming to Glance.

When adding an image (or uploading an image during PUT operations),
you may now supply an optional X-Image-Meta-Checksum header. When
storing the uploaded image, the backend image stores now are required
to return a checksum of the data they just stored. The optional
X-Image-Meta-Checksum header is compared against this generated checksum
and returns a 409 Bad Request if there is a mismatch.

The ETag header is now properly set to the image's checksum now
for all GET /images/<ID>, HEAD /images/<ID>, POST /images and
PUT /images/<ID> operations.

Adds unit tests verifying the checksumming behaviour in the API, and
in the Swift and Filesystem backend stores.

Includes migration script.

NOTE: This does not include the DB migration script. Separate bug will be filed for that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
    authurl = "https://%s" % '/'.join(path_parts)
142
142
 
143
143
    return user, key, authurl, container, obj
144
 
 
145
 
 
146
 
def add_options(parser):
147
 
    """
148
 
    Adds any configuration options that each store might
149
 
    have.
150
 
 
151
 
    :param parser: An optparse.OptionParser object
152
 
    :retval None
153
 
    """
154
 
    # TODO(jaypipes): Remove these imports...
155
 
    from glance.store.http import HTTPBackend
156
 
    from glance.store.s3 import S3Backend
157
 
    from glance.store.swift import SwiftBackend
158
 
    from glance.store.filesystem import FilesystemBackend
159
 
 
160
 
    help_text = "The following configuration options are specific to the "\
161
 
                "Glance image store."
162
 
 
163
 
    DEFAULT_STORE_CHOICES = ['file', 'swift', 's3']
164
 
    group = optparse.OptionGroup(parser, "Image Store Options", help_text)
165
 
    group.add_option('--default-store', metavar="STORE",
166
 
                     default="file",
167
 
                     choices=DEFAULT_STORE_CHOICES,
168
 
                     help="The backend store that Glance will use to store "
169
 
                     "virtual machine images to. Choices: ('%s') "
170
 
                     "Default: %%default" % "','".join(DEFAULT_STORE_CHOICES))
171
 
 
172
 
    backend_classes = [FilesystemBackend,
173
 
                       HTTPBackend,
174
 
                       SwiftBackend,
175
 
                       S3Backend]
176
 
    for backend_class in backend_classes:
177
 
        if hasattr(backend_class, 'add_options'):
178
 
            backend_class.add_options(group)
179
 
 
180
 
    parser.add_option_group(group)