Allow nova to guess device if not passed to attach
partial fix for bug 1004328 Only the xen hypervisor actually respects the device name that is passed in attach_volume. For other hypervisors it makes much more sense to automatically generate a unique name. This patch generates a non-conflicting device name if one is not passed to attach_volume. It also validates the passed in volume name to make sure another device isn't already attached there. A corresponding change to novaclient and horizon will greatly improve the user experience of attaching a volume. It moves some common code out of metadata/base so that it can be used to get a list of block devices. The code was functionally tested as well and block device name generation works properly. This adds a new method to the rpcapi to validate a device name. It also adds server_id to the volumes extension, since it was omitted by mistake. The next step is to modify the libvirt driver to match the serial number of the device to the volume uuid so that the volume can always be found at /dev/disk/by-id/virtio-<uuid>. DocImpact Change-Id: I0b9454fc50a5c93b4aea38545dcee98f68d7e511
This commit is contained in:
@@ -19,6 +19,10 @@ import re
|
||||
|
||||
|
||||
DEFAULT_ROOT_DEV_NAME = '/dev/sda1'
|
||||
_DEFAULT_MAPPINGS = {'ami': 'sda1',
|
||||
'ephemeral0': 'sda2',
|
||||
'root': DEFAULT_ROOT_DEV_NAME,
|
||||
'swap': 'sda3'}
|
||||
|
||||
|
||||
def properties_root_device_name(properties):
|
||||
@@ -81,3 +85,49 @@ def strip_prefix(device_name):
|
||||
""" remove both leading /dev/ and xvd or sd or vd """
|
||||
device_name = strip_dev(device_name)
|
||||
return _pref.sub('', device_name)
|
||||
|
||||
|
||||
def instance_block_mapping(instance, bdms):
|
||||
root_device_name = instance['root_device_name']
|
||||
if root_device_name is None:
|
||||
return _DEFAULT_MAPPINGS
|
||||
|
||||
mappings = {}
|
||||
mappings['ami'] = 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 bdms:
|
||||
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 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
|
||||
|
||||
Reference in New Issue
Block a user