~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to nova/image/glance.py

  • Committer: Tarmac
  • Author(s): Vishvananda Ishaya
  • Date: 2011-03-10 05:44:31 UTC
  • mfrom: (758.3.16 kill-objectstore)
  • Revision ID: tarmac-20110310054431-dbfw33b2v9dop4nf
Modifies S3ImageService to wrap LocalImageService or GlanceImageService.  It now pulls the parts out of s3, decrypts them locally, and sends them to the underlying service.  It includes various fixes for image/glance.py, image/local.py and the tests.

I also uncovered a bug in glance so for the glance backend to work properly, it requires the patch to glance here lp:~vishvananda/glance/fix-update or Glance's Cactus trunk r80.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Implementation of an image service that uses Glance as the backend"""
18
18
 
19
19
from __future__ import absolute_import
20
 
import httplib
21
 
import json
22
 
import urlparse
 
20
 
 
21
from glance.common import exception as glance_exception
23
22
 
24
23
from nova import exception
25
24
from nova import flags
53
52
        """
54
53
        return self.client.get_images_detailed()
55
54
 
56
 
    def show(self, context, id):
 
55
    def show(self, context, image_id):
57
56
        """
58
57
        Returns a dict containing image data for the given opaque image id.
59
58
        """
60
 
        image = self.client.get_image_meta(id)
61
 
        if image:
62
 
            return image
63
 
        raise exception.NotFound
64
 
 
65
 
    def create(self, context, data):
 
59
        try:
 
60
            image = self.client.get_image_meta(image_id)
 
61
        except glance_exception.NotFound:
 
62
            raise exception.NotFound
 
63
        return image
 
64
 
 
65
    def show_by_name(self, context, name):
 
66
        """
 
67
        Returns a dict containing image data for the given name.
 
68
        """
 
69
        # TODO(vish): replace this with more efficient call when glance
 
70
        #             supports it.
 
71
        images = self.detail(context)
 
72
        image = None
 
73
        for cantidate in images:
 
74
            if name == cantidate.get('name'):
 
75
                image = cantidate
 
76
                break
 
77
        if image is None:
 
78
            raise exception.NotFound
 
79
        return image
 
80
 
 
81
    def get(self, context, image_id, data):
 
82
        """
 
83
        Calls out to Glance for metadata and data and writes data.
 
84
        """
 
85
        try:
 
86
            metadata, image_chunks = self.client.get_image(image_id)
 
87
        except glance_exception.NotFound:
 
88
            raise exception.NotFound
 
89
        for chunk in image_chunks:
 
90
            data.write(chunk)
 
91
        return metadata
 
92
 
 
93
    def create(self, context, metadata, data=None):
66
94
        """
67
95
        Store the image data and return the new image id.
68
96
 
69
97
        :raises AlreadyExists if the image already exist.
70
98
 
71
99
        """
72
 
        return self.client.add_image(image_meta=data)
 
100
        return self.client.add_image(metadata, data)
73
101
 
74
 
    def update(self, context, image_id, data):
 
102
    def update(self, context, image_id, metadata, data=None):
75
103
        """Replace the contents of the given image with the new data.
76
104
 
77
105
        :raises NotFound if the image does not exist.
78
106
 
79
107
        """
80
 
        return self.client.update_image(image_id, data)
 
108
        try:
 
109
            result = self.client.update_image(image_id, metadata, data)
 
110
        except glance_exception.NotFound:
 
111
            raise exception.NotFound
 
112
        return result
81
113
 
82
114
    def delete(self, context, image_id):
83
115
        """
86
118
        :raises NotFound if the image does not exist.
87
119
 
88
120
        """
89
 
        return self.client.delete_image(image_id)
 
121
        try:
 
122
            result = self.client.delete_image(image_id)
 
123
        except glance_exception.NotFound:
 
124
            raise exception.NotFound
 
125
        return result
90
126
 
91
127
    def delete_all(self):
92
128
        """