Revision 3a9b3cde

b/snf-app/synnefo/api/servers.py
230 230
        except AssertionError:
231 231
            raise faults.BadRequest("Malformed personality in request")
232 232
    
233
    image = util.get_image(image_id, owner)
233
    image = {}
234
    try:
235
        img = util.get_image(image_id, owner)
236
        image['backend_id'] = img.backend_id
237
        image['format'] = img.format
238
        image['metadata'] = dict((m.meta_key, m.meta_value)
239
                for m in img.metadata.all())
240
    except faults.ItemNotFound:
241
        img = util.get_backend_image(image_id, owner)
242
        image['backend_id'] = img['location']
243
        image['format'] = img['disk_format']
244
        image['metadata'] = img.get('properties', {})
245
    
234 246
    flavor = util.get_flavor(flavor_id)
235 247
    password = util.random_password()
236 248
    
......
242 254
    vm = VirtualMachine.objects.create(
243 255
        name=name,
244 256
        owner=owner,
245
        imageid=image.id,
257
        imageid=image_id,
246 258
        flavor=flavor)
247 259
    
248 260
    try:
b/snf-app/synnefo/api/util.py
54 54

  
55 55
from synnefo.api.faults import (Fault, BadRequest, BuildInProgress,
56 56
                                ItemNotFound, ServiceUnavailable, Unauthorized)
57
from synnefo.db.models import (SynnefoUser, Flavor, Image, ImageMetadata,
57
from synnefo.db.models import (Flavor, Image, ImageMetadata,
58 58
                                VirtualMachine, VirtualMachineMetadata,
59 59
                                Network, NetworkInterface)
60
from synnefo.plankton.backend import ImageBackend
60 61
from synnefo.util.log import getLogger
61 62

  
62 63

  
......
149 150
            raise ItemNotFound('Image not found.')
150 151
        return image
151 152
    except ValueError:
152
        raise BadRequest('Invalid image ID.')
153
        raise ItemNotFound('Image not found.')
153 154
    except Image.DoesNotExist:
154 155
        raise ItemNotFound('Image not found.')
155 156

  
157
def get_backend_image(image_id, owner):
158
    backend = ImageBackend(owner.uniq)
159
    try:
160
        image = backend.get_meta(image_id)
161
        if not image:
162
            raise ItemNotFound('Image not found.')
163
        return image
164
    finally:
165
        backend.close()
166

  
156 167
def get_image_meta(image, key):
157 168
    """Return a ImageMetadata instance or raise ItemNotFound."""
158 169

  
b/snf-app/synnefo/logic/backend.py
218 218

  
219 219

  
220 220
def create_instance(vm, flavor, image, password, personality):
221

  
221
    """`image` is a dictionary which should contain the keys:
222
            'backend_id', 'format' and 'metadata'
223
        
224
        metadata value should be a dictionary.
225
    """
222 226
    nic = {'ip': 'pool', 'mode': 'routed', 'link': settings.GANETI_PUBLIC_LINK}
223 227

  
224 228
    if settings.IGNORE_FLAVOR_DISK_SIZES:
225
        if image.backend_id.find("windows") >= 0:
229
        if image['backend_id'].find("windows") >= 0:
226 230
            sz = 14000
227 231
        else:
228 232
            sz = 4000
......
258 262
        'memory': flavor.ram}
259 263

  
260 264
    kw['osparams'] = {
261
        'img_id': image.backend_id,
265
        'img_id': image['backend_id'],
262 266
        'img_passwd': password,
263
        'img_format': image.format}
267
        'img_format': image['format']}
264 268
    if personality:
265 269
        kw['osparams']['img_personality'] = json.dumps(personality)
266 270
    
267
    image_meta = dict((m.meta_key, m.meta_value) for m in image.metadata.all())
268
    kw['osparams']['img_properties'] = json.dumps(image_meta)
271
    kw['osparams']['img_properties'] = json.dumps(image['metadata'])
269 272
    
270 273
    # Defined in settings.GANETI_CREATEINSTANCE_KWARGS
271 274
    # kw['hvparams'] = dict(serial_console=False)

Also available in: Unified diff