本文整理汇总了Python中nova.block_device.prepend_dev函数的典型用法代码示例。如果您正苦于以下问题:Python prepend_dev函数的具体用法?Python prepend_dev怎么用?Python prepend_dev使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prepend_dev函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_next_device_name
def get_next_device_name(instance, device_name_list,
root_device_name=None, device=None):
"""Validates (or generates) a device name for instance.
If device is not set, it will generate a unique device appropriate
for the instance. It uses the root_device_name (if provided) and
the list of used devices to find valid device names. If the device
name is valid but applicable to a different backend (for example
/dev/vdc is specified but the backend uses /dev/xvdc), the device
name will be converted to the appropriate format.
"""
req_prefix = None
req_letter = None
if device:
try:
req_prefix, req_letter = block_device.match_device(device)
except (TypeError, AttributeError, ValueError):
raise exception.InvalidDevicePath(path=device)
if not root_device_name:
root_device_name = block_device.DEFAULT_ROOT_DEV_NAME
try:
prefix = block_device.match_device(
block_device.prepend_dev(root_device_name))[0]
except (TypeError, AttributeError, ValueError):
raise exception.InvalidDevicePath(path=root_device_name)
# NOTE(vish): remove this when xenapi is setting default_root_device
if driver.is_xenapi():
prefix = '/dev/xvd'
if req_prefix != prefix:
LOG.debug("Using %(prefix)s instead of %(req_prefix)s",
{'prefix': prefix, 'req_prefix': req_prefix})
used_letters = set()
for device_path in device_name_list:
letter = block_device.get_device_letter(device_path)
used_letters.add(letter)
# NOTE(vish): remove this when xenapi is properly setting
# default_ephemeral_device and default_swap_device
if driver.is_xenapi():
flavor = instance.get_flavor()
if flavor.ephemeral_gb:
used_letters.add('b')
if flavor.swap:
used_letters.add('c')
if not req_letter:
req_letter = _get_unused_letter(used_letters)
if req_letter in used_letters:
raise exception.DevicePathInUse(path=device)
return prefix + req_letter
示例2: update_bdm
def update_bdm(bdm, info):
device_name_field = ('device_name'
if 'device_name' in bdm
else 'mount_device')
# Do not update the device name if it was already present
bdm.update(dict(zip((device_name_field,
'disk_bus', 'device_type'),
((bdm.get(device_name_field) or
block_device.prepend_dev(info['dev'])),
info['bus'], info['type']))))
示例3: __init__
def __init__(self, instance_id, mountpoint, dev):
"""
Setup critical information for attaching/detaching volumes from
instance_id.
:param instance_id:
:param mountpoint: connection_info['data']['mount_device']
:param dev:
"""
#TODO(imsplitbit): Need to make this happen while supporting block
# devices and externally mounted filesystems at the same time.
# Currently it does not.
self.instance_id = instance_id
self.mountpoint = block_device.prepend_dev(mountpoint)
self.device = dev
示例4: _get_guest_storage_config
def _get_guest_storage_config(self, context, block_device_info,
reboot=False):
devices = []
block_device_mapping = driver.block_device_info_get_mapping(
block_device_info)
LOG.info(_LI('block_device_mapping %s'), block_device_mapping)
for vol in block_device.get_bdms_to_connect(block_device_mapping):
connection_info = vol['connection_info']
vol_dev = block_device.prepend_dev(vol['mount_device'])
info = {'dev': vol['mount_device']}
self._connect_volume(connection_info, info)
device_path = connection_info['data'].get('device_path')
if device_path:
real_path = os.path.realpath(device_path)
devices.append(real_path + ':' + vol['mount_device'])
bdm = objects.BlockDeviceMapping.get_by_volume_id(
context, connection_info['data']['volume_id'])
driver_bdm = driver_block_device.DriverVolumeBlockDevice(bdm)
driver_bdm['connection_info'] = connection_info
driver_bdm.save()
return devices
示例5: get_disk_mapping
def get_disk_mapping(virt_type, instance,
disk_bus, cdrom_bus,
block_device_info=None,
image_meta=None, rescue=False):
"""Determine how to map default disks to the virtual machine.
This is about figuring out whether the default 'disk',
'disk.local', 'disk.swap' and 'disk.config' images have
been overridden by the block device mapping.
Returns the guest disk mapping for the devices.
"""
inst_type = flavors.extract_flavor(instance)
mapping = {}
pre_assigned_device_names = \
[block_device.strip_dev(get_device_name(bdm)) for bdm in itertools.chain(
driver.block_device_info_get_ephemerals(block_device_info),
[driver.block_device_info_get_swap(block_device_info)],
driver.block_device_info_get_mapping(block_device_info))
if get_device_name(bdm)]
if rescue:
rescue_info = get_next_disk_info(mapping,
disk_bus, boot_index=1)
mapping['disk.rescue'] = rescue_info
mapping['root'] = rescue_info
os_info = get_next_disk_info(mapping,
disk_bus)
mapping['disk'] = os_info
return mapping
# NOTE (ndipanov): root_bdm can be None when we boot from image
# as there is no driver represenation of local targeted images
# and they will not be in block_device_info list.
root_bdm = block_device.get_root_bdm(
driver.block_device_info_get_mapping(block_device_info))
root_device_name = block_device.strip_dev(
driver.block_device_info_get_root(block_device_info))
root_info = get_root_info(virt_type, image_meta, root_bdm,
disk_bus, cdrom_bus, root_device_name)
mapping['root'] = root_info
# NOTE (ndipanov): This implicitly relies on image->local BDMs not
# being considered in the driver layer - so missing
# bdm with boot_index 0 means - use image, unless it was
# overridden. This can happen when using legacy syntax and
# no root_device_name is set on the instance.
if not root_bdm and not block_device.volume_in_mapping(root_info['dev'],
block_device_info):
mapping['disk'] = root_info
default_eph = has_default_ephemeral(instance, disk_bus, block_device_info,
mapping)
if default_eph:
mapping['disk.local'] = default_eph
for idx, eph in enumerate(driver.block_device_info_get_ephemerals(
block_device_info)):
eph_info = get_info_from_bdm(
virt_type, eph, mapping, disk_bus,
assigned_devices=pre_assigned_device_names)
mapping[get_eph_disk(idx)] = eph_info
update_bdm(eph, eph_info)
swap = driver.block_device_info_get_swap(block_device_info)
if swap and swap.get('swap_size', 0) > 0:
swap_info = get_info_from_bdm(virt_type, swap, mapping, disk_bus)
mapping['disk.swap'] = swap_info
update_bdm(swap, swap_info)
elif inst_type['swap'] > 0:
swap_info = get_next_disk_info(mapping,
disk_bus)
if not block_device.volume_in_mapping(swap_info['dev'],
block_device_info):
mapping['disk.swap'] = swap_info
block_device_mapping = driver.block_device_info_get_mapping(
block_device_info)
for vol in block_device_mapping:
vol_info = get_info_from_bdm(
virt_type, vol, mapping,
assigned_devices=pre_assigned_device_names)
mapping[block_device.prepend_dev(vol_info['dev'])] = vol_info
update_bdm(vol, vol_info)
if configdrive.required_by(instance):
device_type = get_config_drive_type()
disk_bus = get_disk_bus_for_device_type(virt_type,
image_meta,
device_type)
config_info = get_next_disk_info(mapping,
disk_bus,
device_type,
#.........这里部分代码省略.........