~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/api/openstack/compute/contrib/volumes.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from webob import exc
20
20
 
21
21
from nova.api.openstack import common
22
 
from nova.api.openstack.compute import servers
23
22
from nova.api.openstack import extensions
24
23
from nova.api.openstack import wsgi
25
24
from nova.api.openstack import xmlutil
220
219
        #             trying to lazy load, but for now we turn it into
221
220
        #             a dict to avoid an error.
222
221
        retval = _translate_volume_detail_view(context, dict(new_volume))
223
 
 
224
 
        return {'volume': retval}
 
222
        result = {'volume': retval}
 
223
 
 
224
        location = '%s/%s' % (req.url, new_volume['id'])
 
225
 
 
226
        return wsgi.ResponseObject(result, headers=dict(location=location))
225
227
 
226
228
 
227
229
def _translate_attachment_detail_view(volume_id, instance_uuid, mountpoint):
337
339
            raise exc.HTTPUnprocessableEntity()
338
340
 
339
341
        volume_id = body['volumeAttachment']['volumeId']
340
 
        device = body['volumeAttachment']['device']
 
342
        device = body['volumeAttachment'].get('device')
341
343
 
342
344
        msg = _("Attach volume %(volume_id)s to instance %(server_id)s"
343
345
                " at %(device)s") % locals()
345
347
 
346
348
        try:
347
349
            instance = self.compute_api.get(context, server_id)
348
 
            self.compute_api.attach_volume(context, instance,
349
 
                                           volume_id, device)
 
350
            device = self.compute_api.attach_volume(context, instance,
 
351
                                                    volume_id, device)
350
352
        except exception.NotFound:
351
353
            raise exc.HTTPNotFound()
352
354
 
353
355
        # The attach is async
354
356
        attachment = {}
355
357
        attachment['id'] = volume_id
 
358
        attachment['serverId'] = server_id
356
359
        attachment['volumeId'] = volume_id
 
360
        attachment['device'] = device
357
361
 
358
362
        # NOTE(justinsb): And now, we have a problem...
359
363
        # The attach is async, so there's a window in which we don't see
425
429
        return {'volumeAttachments': results}
426
430
 
427
431
 
428
 
class BootFromVolumeController(servers.Controller):
429
 
    """The boot from volume API controller for the OpenStack API."""
430
 
 
431
 
    def _get_block_device_mapping(self, data):
432
 
        return data.get('block_device_mapping')
433
 
 
434
 
 
435
432
def _translate_snapshot_detail_view(context, vol):
436
433
    """Maps keys for snapshots details view."""
437
434
 
595
592
        resources.append(res)
596
593
 
597
594
        res = extensions.ResourceExtension('os-volumes_boot',
598
 
                                           BootFromVolumeController())
 
595
                                           inherits='servers')
599
596
        resources.append(res)
600
597
 
601
598
        res = extensions.ResourceExtension('os-snapshots',