diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-08-16 01:16:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-08-16 01:16:02 +0000 |
| commit | bc115f003ddf7b8a825f0303bdf290a19c39f134 (patch) | |
| tree | 3fe5061feef38f9686a244f07ffaede96a6db1bc /nova/api | |
| parent | e364c9086b3adf793d79c44062d5a9e17943e887 (diff) | |
| parent | e44751162b09c5b57557b89db27656b5bd23341c (diff) | |
| download | nova-bc115f003ddf7b8a825f0303bdf290a19c39f134.tar.gz nova-bc115f003ddf7b8a825f0303bdf290a19c39f134.tar.xz nova-bc115f003ddf7b8a825f0303bdf290a19c39f134.zip | |
Merge "Allow nova to guess device if not passed to attach"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/metadata/base.py | 51 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/volumes.py | 8 |
2 files changed, 7 insertions, 52 deletions
diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index aa18eceb0..d9710dc37 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -45,11 +45,6 @@ flags.DECLARE('dhcp_domain', 'nova.network.manager') FLAGS.register_opts(metadata_opts) -_DEFAULT_MAPPINGS = {'ami': 'sda1', - 'ephemeral0': 'sda2', - 'root': block_device.DEFAULT_ROOT_DEV_NAME, - 'swap': 'sda3'} - VERSIONS = [ '1.0', '2007-01-19', @@ -387,50 +382,8 @@ def get_metadata_by_address(address): def _format_instance_mapping(ctxt, instance): - root_device_name = instance['root_device_name'] - if root_device_name is None: - return _DEFAULT_MAPPINGS - - mappings = {} - mappings['ami'] = block_device.strip_dev(root_device_name) - mappings['root'] = root_device_name - default_ephemeral_device = instance.get('default_ephemeral_device') - if default_ephemeral_device: - mappings['ephemeral0'] = default_ephemeral_device - default_swap_device = instance.get('default_swap_device') - if default_swap_device: - mappings['swap'] = default_swap_device - ebs_devices = [] - - # 'ephemeralN', 'swap' and ebs - for bdm in db.block_device_mapping_get_all_by_instance( - ctxt, instance['uuid']): - if bdm['no_device']: - continue - - # ebs volume case - if (bdm['volume_id'] or bdm['snapshot_id']): - ebs_devices.append(bdm['device_name']) - continue - - virtual_name = bdm['virtual_name'] - if not virtual_name: - continue - - if block_device.is_swap_or_ephemeral(virtual_name): - mappings[virtual_name] = bdm['device_name'] - - # NOTE(yamahata): I'm not sure how ebs device should be numbered. - # Right now sort by device name for deterministic - # result. - if ebs_devices: - nebs = 0 - ebs_devices.sort() - for ebs in ebs_devices: - mappings['ebs%d' % nebs] = ebs - nebs += 1 - - return mappings + bdms = db.block_device_mapping_get_all_by_instance(ctxt, instance['uuid']) + return block_device.instance_block_mapping(instance, bdms) def ec2_md_print(data): diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py index e566a95f7..99d713cef 100644 --- a/nova/api/openstack/compute/contrib/volumes.py +++ b/nova/api/openstack/compute/contrib/volumes.py @@ -339,7 +339,7 @@ class VolumeAttachmentController(object): raise exc.HTTPUnprocessableEntity() volume_id = body['volumeAttachment']['volumeId'] - device = body['volumeAttachment']['device'] + device = body['volumeAttachment'].get('device') msg = _("Attach volume %(volume_id)s to instance %(server_id)s" " at %(device)s") % locals() @@ -347,15 +347,17 @@ class VolumeAttachmentController(object): try: instance = self.compute_api.get(context, server_id) - self.compute_api.attach_volume(context, instance, - volume_id, device) + device = self.compute_api.attach_volume(context, instance, + volume_id, device) except exception.NotFound: raise exc.HTTPNotFound() # The attach is async attachment = {} attachment['id'] = volume_id + attachment['serverId'] = server_id attachment['volumeId'] = volume_id + attachment['device'] = device # NOTE(justinsb): And now, we have a problem... # The attach is async, so there's a window in which we don't see |
