~jaypipes/glance/bug759018

« back to all changes in this revision

Viewing changes to glance/registry/server.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:
14
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
15
#    License for the specific language governing permissions and limitations
16
16
#    under the License.
 
17
 
17
18
"""
18
 
Parllax Image controller
 
19
Reference implementation registry server WSGI controller
19
20
"""
20
21
 
21
22
import json
31
32
 
32
33
logger = logging.getLogger('glance.registry.server')
33
34
 
 
35
DISPLAY_FIELDS_IN_INDEX = ['id', 'name', 'size',
 
36
                           'disk_format', 'container_format',
 
37
                           'checksum']
 
38
 
34
39
 
35
40
class Controller(wsgi.Controller):
36
41
    """Controller for the reference implementation registry server"""
49
54
 
50
55
        Where image_list is a sequence of mappings::
51
56
 
52
 
            {'id': image_id, 'name': image_name}
 
57
            {
 
58
            'id': <ID>,
 
59
            'name': <NAME>,
 
60
            'size': <SIZE>,
 
61
            'disk_format': <DISK_FORMAT>,
 
62
            'container_format': <CONTAINER_FORMAT>,
 
63
            'checksum': <CHECKSUM>
 
64
            }
53
65
 
54
66
        """
55
67
        images = db_api.image_get_all_public(None)
56
 
        image_dicts = [dict(id=i['id'],
57
 
                            name=i['name'],
58
 
                            disk_format=i['disk_format'],
59
 
                            container_format=i['container_format'],
60
 
                            size=i['size']) for i in images]
61
 
        return dict(images=image_dicts)
 
68
        results = []
 
69
        for image in images:
 
70
            result = {}
 
71
            for field in DISPLAY_FIELDS_IN_INDEX:
 
72
                result[field] = image[field]
 
73
            results.append(result)
 
74
        return dict(images=results)
62
75
 
63
76
    def detail(self, req):
64
77
        """Return detailed information for all public, non-deleted images