From 69564763960cddc249138469811a0a771db16e19 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 25 Sep 2012 11:15:14 -0700 Subject: Fix issues with device autoassignment in xenapi This is a workaround for two issues in xenapi. The first is that does not set the instance default_root_device to /dev/xvda so it defaults to /dev/sda. The proper fix for this involves setting the default_root_device in xenapi and a db migration to set the proper default_root_device for existing instances. This patch works around this issue by explicitly setting the prefix to /dev/xvd if the compute driver is xenapi. The second issue is that xenapi never updates the instance record to include default_swap_device and default_ephemeral device. The fix for this involes adding the appropriate update to the instance record and a migration that sets the proper values for all existing instances. This patch works around this issue by explicily checking the instance_type and removing the devices from the list if the compute driver is xenapi. Fixes bug 1055715 and bug 1055712 Change-Id: I61aa15e69eb0a22430bb22ea5149b1f0735b3328 --- nova/compute/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'nova/compute') diff --git a/nova/compute/utils.py b/nova/compute/utils.py index 1f46d8019..a8a0a6544 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -21,6 +21,7 @@ import string import traceback from nova import block_device +from nova.compute import instance_types from nova import db from nova import exception from nova import flags @@ -79,6 +80,10 @@ def get_device_name_for_instance(context, instance, device): prefix = block_device.match_device(mappings['root'])[0] except (TypeError, AttributeError, ValueError): raise exception.InvalidDevicePath(path=mappings['root']) + # NOTE(vish): remove this when xenapi is setting default_root_device + if (FLAGS.connection_type == 'xenapi' or + FLAGS.compute_driver.endswith('xenapi.XenAPIDriver')): + prefix = '/dev/xvd' if req_prefix != prefix: LOG.debug(_("Using %(prefix)s instead of %(req_prefix)s") % locals()) letters_list = [] @@ -89,6 +94,18 @@ def get_device_name_for_instance(context, instance, device): letter = re.sub("\d+", "", letter) letters_list.append(letter) used_letters = set(letters_list) + + # NOTE(vish): remove this when xenapi is properly setting + # default_ephemeral_device and default_swap_device + if (FLAGS.connection_type == 'xenapi' or + FLAGS.compute_driver.endswith('xenapi.XenAPIDriver')): + instance_type_id = instance['instance_type_id'] + instance_type = instance_types.get_instance_type(instance_type_id) + if instance_type['ephemeral_gb']: + used_letters.update('b') + if instance_type['swap']: + used_letters.update('c') + if not req_letters: req_letters = _get_unused_letters(used_letters) if req_letters in used_letters: -- cgit