summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-31 20:50:07 +0000
committerGerrit Code Review <review@openstack.org>2013-01-31 20:50:07 +0000
commitc2e4630f08cef843aade19be237c4c31ff7fccf1 (patch)
treee947d2d527202f4c28cd78a8be5d4b239e78a585 /nova/virt
parentd7ad6c1471bcb5ce128eff474d6e48546799c617 (diff)
parent8705f49a4ad9c6f3a93f33e333475285a8f70a30 (diff)
Merge "Fix rebuild with volumes attached"
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/xenapi/vm_utils.py76
-rw-r--r--nova/virt/xenapi/vmops.py17
2 files changed, 62 insertions, 31 deletions
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index ccddedd1f..ec6450d9f 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -460,50 +460,66 @@ def create_vdi(session, sr_ref, instance, name_label, disk_type, virtual_size,
return vdi_ref
-def get_vdis_for_boot_from_vol(session, dev_params):
- vdis = {}
- sr_uuid, label, sr_params = volume_utils.parse_sr_info(dev_params)
+def get_vdi_uuid_for_volume(session, connection_data):
+ sr_uuid, label, sr_params = volume_utils.parse_sr_info(connection_data)
sr_ref = volume_utils.find_sr_by_uuid(session, sr_uuid)
- # Try introducing SR if it is not present
+
if not sr_ref:
sr_ref = volume_utils.introduce_sr(session, sr_uuid, label, sr_params)
if sr_ref is None:
raise exception.NovaException(_('SR not present and could not be '
'introduced'))
+
+ vdi_uuid = None
+
+ if 'vdi_uuid' in connection_data:
+ session.call_xenapi("SR.scan", sr_ref)
+ vdi_uuid = connection_data['vdi_uuid']
else:
- if 'vdi_uuid' in dev_params:
- session.call_xenapi("SR.scan", sr_ref)
- vdis = {'root': dict(uuid=dev_params['vdi_uuid'],
- file=None, osvol=True)}
- else:
- try:
- vdi_ref = volume_utils.introduce_vdi(session, sr_ref)
- vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
- vdis = {'root': dict(uuid=vdi_rec['uuid'],
- file=None, osvol=True)}
- except volume_utils.StorageError, exc:
- LOG.exception(exc)
- volume_utils.forget_sr(session, sr_uuid)
- return vdis
+ try:
+ vdi_ref = volume_utils.introduce_vdi(session, sr_ref)
+ vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
+ vdi_uuid = vdi_rec['uuid']
+ except volume_utils.StorageError, exc:
+ LOG.exception(exc)
+ volume_utils.forget_sr(session, sr_uuid)
+
+ return vdi_uuid
def get_vdis_for_instance(context, session, instance, name_label, image,
image_type, block_device_info=None):
+ vdis = {}
+
if block_device_info:
LOG.debug(_("block device info: %s"), block_device_info)
- rootdev = block_device_info['root_device_name']
- if block_device.volume_in_mapping(rootdev, block_device_info,
- strip=block_device.strip_prefix):
- # call function to return the vdi in connection info of block
- # device.
- # make it a point to return from here.
- bdm_root_dev = block_device_info['block_device_mapping'][0]
- dev_params = bdm_root_dev['connection_info']['data']
- LOG.debug(dev_params)
- return get_vdis_for_boot_from_vol(session, dev_params)
- return _create_image(context, session, instance, name_label, image,
- image_type)
+ root_device_name = block_device_info['root_device_name']
+
+ for bdm in block_device_info['block_device_mapping']:
+ if (block_device.strip_prefix(bdm['mount_device']) ==
+ block_device.strip_prefix(root_device_name)):
+ # If we're a root-device, record that fact so we don't download
+ # a root image via Glance
+ type_ = 'root'
+ else:
+ # Otherwise, use mount_device as `type_` so that we have easy
+ # access to it in _attach_disks to create the VBD
+ type_ = bdm['mount_device']
+
+ connection_data = bdm['connection_info']['data']
+ vdi_uuid = get_vdi_uuid_for_volume(session, connection_data)
+ if vdi_uuid:
+ vdis[type_] = dict(uuid=vdi_uuid, file=None, osvol=True)
+
+ # If we didn't get a root VDI from volumes, then use the Glance image as
+ # the root device
+ if 'root' not in vdis:
+ create_image_vdis = _create_image(
+ context, session, instance, name_label, image, image_type)
+ vdis.update(create_image_vdis)
+
+ return vdis
@contextlib.contextmanager
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index acc6de2bc..8a76f3368 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -26,6 +26,7 @@ import time
from eventlet import greenthread
import netaddr
+from nova import block_device
from nova.compute import api as compute
from nova.compute import power_state
from nova.compute import task_states
@@ -511,8 +512,9 @@ class VMOps(object):
ctx = nova_context.get_admin_context()
instance_type = instance['instance_type']
- # DISK_ISO needs two VBDs: the ISO disk and a blank RW disk
+ # Attach (required) root disk
if disk_image_type == vm_utils.ImageType.DISK_ISO:
+ # DISK_ISO needs two VBDs: the ISO disk and a blank RW disk
LOG.debug(_("Detected ISO image type, creating blank VM "
"for install"), instance=instance)
@@ -540,6 +542,19 @@ class VMOps(object):
DEVICE_ROOT, bootable=True,
osvol=root_vdi.get('osvol'))
+ # Attach (optional) additional block-devices
+ for type_, vdi_info in vdis.items():
+ # Additional block-devices for boot use their device-name as the
+ # type.
+ if not type_.startswith('/dev'):
+ continue
+
+ # Convert device name to userdevice number, e.g. /dev/xvdb -> 1
+ userdevice = ord(block_device.strip_prefix(type_)) - ord('a')
+ vm_utils.create_vbd(self._session, vm_ref, vdi_info['ref'],
+ userdevice, bootable=False,
+ osvol=vdi_info.get('osvol'))
+
# Attach (optional) swap disk
swap_mb = instance_type['swap']
if swap_mb: