~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/api/v1/volumes.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
        d['volume_type'] = str(vol['volume_type_id'])
99
99
 
100
100
    d['snapshot_id'] = vol['snapshot_id']
 
101
    d['source_volid'] = vol['source_volid']
101
102
 
102
103
    if image_id:
103
104
        d['image_id'] = image_id
138
139
    elem.set('display_description')
139
140
    elem.set('volume_type')
140
141
    elem.set('snapshot_id')
 
142
    elem.set('source_volid')
141
143
 
142
144
    attachments = xmlutil.SubTemplateElement(elem, 'attachments')
143
145
    attachment = xmlutil.SubTemplateElement(attachments, 'attachment',
260
262
        remove_invalid_options(context,
261
263
                               search_opts, self._get_volume_search_options())
262
264
 
263
 
        volumes = self.volume_api.get_all(context, search_opts=search_opts)
 
265
        volumes = self.volume_api.get_all(context, marker=None, limit=None,
 
266
                                          sort_key='created_at',
 
267
                                          sort_dir='desc', filters=search_opts)
264
268
        limited_list = common.limited(volumes, req)
265
269
        res = [entity_maker(context, vol) for vol in limited_list]
266
270
        return {'volumes': res}
294
298
 
295
299
        req_volume_type = volume.get('volume_type', None)
296
300
        if req_volume_type:
297
 
            try:
298
 
                kwargs['volume_type'] = volume_types.get_volume_type_by_name(
 
301
            if not uuidutils.is_uuid_like(req_volume_type):
 
302
                try:
 
303
                    kwargs['volume_type'] = \
 
304
                        volume_types.get_volume_type_by_name(
 
305
                            context, req_volume_type)
 
306
                except exception.VolumeTypeNotFound:
 
307
                    explanation = 'Volume type not found.'
 
308
                    raise exc.HTTPNotFound(explanation=explanation)
 
309
            else:
 
310
                try:
 
311
                    kwargs['volume_type'] = volume_types.get_volume_type(
299
312
                        context, req_volume_type)
300
 
            except exception.VolumeTypeNotFound:
301
 
                explanation = 'Volume type not found.'
302
 
                raise exc.HTTPNotFound(explanation=explanation)
 
313
                except exception.VolumeTypeNotFound:
 
314
                    explanation = 'Volume type not found.'
 
315
                    raise exc.HTTPNotFound(explanation=explanation)
303
316
 
304
317
        kwargs['metadata'] = volume.get('metadata', None)
305
318
 
310
323
        else:
311
324
            kwargs['snapshot'] = None
312
325
 
 
326
        source_volid = volume.get('source_volid')
 
327
        if source_volid is not None:
 
328
            kwargs['source_volume'] = self.volume_api.get_volume(context,
 
329
                                                                 source_volid)
 
330
        else:
 
331
            kwargs['source_volume'] = None
 
332
 
313
333
        size = volume.get('size', None)
314
334
        if size is None and kwargs['snapshot'] is not None:
315
335
            size = kwargs['snapshot']['volume_size']
 
336
        elif size is None and kwargs['source_volume'] is not None:
 
337
            size = kwargs['source_volume']['size']
316
338
 
317
339
        LOG.audit(_("Create volume of %s GB"), size, context=context)
318
340
 
394
416
        return
395
417
    # Otherwise, strip out all unknown options
396
418
    unknown_options = [opt for opt in search_options
397
 
            if opt not in allowed_search_options]
 
419
                       if opt not in allowed_search_options]
398
420
    bad_options = ", ".join(unknown_options)
399
421
    log_msg = _("Removing options '%(bad_options)s' from query") % locals()
400
422
    LOG.debug(log_msg)