~ubuntu-branches/ubuntu/raring/glance/raring-proposed

« back to all changes in this revision

Viewing changes to glance/db/__init__.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-03-20 07:42:22 UTC
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: package-import@ubuntu.com-20130320074222-ty2todj0yxtnq3lb
Tags: upstream-2013.1~rc1
ImportĀ upstreamĀ versionĀ 2013.1~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from oslo.config import cfg
21
21
 
22
 
from glance.api import authorization
 
22
from glance.common import crypt
23
23
from glance.common import exception
24
24
import glance.domain
 
25
import glance.domain.proxy
25
26
from glance.openstack.common import importutils
26
27
 
27
28
sql_connection_opt = cfg.StrOpt('sql_connection',
34
35
 
35
36
CONF = cfg.CONF
36
37
CONF.register_opt(sql_connection_opt)
 
38
CONF.import_opt('metadata_encryption_key', 'glance.common.config')
37
39
 
38
40
 
39
41
def add_cli_options():
58
60
IMAGE_ATTRS = BASE_MODEL_ATTRS | set(['name', 'status', 'size',
59
61
                                      'disk_format', 'container_format',
60
62
                                      'min_disk', 'min_ram', 'is_public',
61
 
                                      'location', 'checksum', 'owner',
 
63
                                      'locations', 'checksum', 'owner',
62
64
                                      'protected'])
63
65
 
64
66
 
99
101
            # NOTE(markwash) db api requires us to filter deleted
100
102
            if not prop['deleted']:
101
103
                properties[prop['name']] = prop['value']
 
104
        locations = db_image['locations']
 
105
        if CONF.metadata_encryption_key:
 
106
            key = CONF.metadata_encryption_key
 
107
            locations = [crypt.urlsafe_decrypt(key, l) for l in locations]
102
108
        return glance.domain.Image(
103
109
            image_id=db_image['id'],
104
110
            name=db_image['name'],
109
115
            min_disk=db_image['min_disk'],
110
116
            min_ram=db_image['min_ram'],
111
117
            protected=db_image['protected'],
112
 
            location=db_image['location'],
 
118
            locations=locations,
113
119
            checksum=db_image['checksum'],
114
120
            owner=db_image['owner'],
115
121
            disk_format=db_image['disk_format'],
120
126
        )
121
127
 
122
128
    def _format_image_to_db(self, image):
 
129
        locations = image.locations
 
130
        if CONF.metadata_encryption_key:
 
131
            key = CONF.metadata_encryption_key
 
132
            locations = [crypt.urlsafe_encrypt(key, l) for l in locations]
123
133
        return {
124
134
            'id': image.image_id,
125
135
            'name': image.name,
128
138
            'min_disk': image.min_disk,
129
139
            'min_ram': image.min_ram,
130
140
            'protected': image.protected,
131
 
            'location': image.location,
 
141
            'locations': locations,
132
142
            'checksum': image.checksum,
133
143
            'owner': image.owner,
134
144
            'disk_format': image.disk_format,
174
184
        image.updated_at = new_values['updated_at']
175
185
 
176
186
 
177
 
class ImageProxy(glance.domain.ImageProxy):
 
187
class ImageProxy(glance.domain.proxy.Image):
178
188
 
179
189
    def __init__(self, image, context, db_api):
180
190
        self.context = context
230
240
        return self._format_image_member_from_db(new_values)
231
241
 
232
242
    def remove(self, image_member):
233
 
        image_member_values = self._format_image_member_to_db(image_member)
234
243
        try:
235
244
            self.db_api.image_member_delete(self.context, image_member.id)
236
245
        except (exception.NotFound, exception.Forbidden):