• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python block_device.get_device_letter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nova.block_device.get_device_letter函数的典型用法代码示例。如果您正苦于以下问题:Python get_device_letter函数的具体用法?Python get_device_letter怎么用?Python get_device_letter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_device_letter函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_device_letter

 def test_get_device_letter(self):
     self.assertEqual('', block_device.get_device_letter(''))
     self.assertEqual('a', block_device.get_device_letter('/dev/sda1'))
     self.assertEqual('b', block_device.get_device_letter('/dev/xvdb'))
     self.assertEqual('d', block_device.get_device_letter('/dev/d'))
     self.assertEqual('a', block_device.get_device_letter('a'))
     self.assertEqual('b', block_device.get_device_letter('sdb2'))
     self.assertEqual('c', block_device.get_device_letter('vdc'))
     self.assertEqual('c', block_device.get_device_letter('hdc'))
     self.assertIsNone(block_device.get_device_letter(None))
开发者ID:akashgangil,项目名称:nova,代码行数:10,代码来源:test_block_device.py


示例2: 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
开发者ID:klmitch,项目名称:nova,代码行数:60,代码来源:utils.py


示例3: test_get_device_letter

 def test_get_device_letter(self):
     self.assertEqual(block_device.get_device_letter(""), "")
     self.assertEqual(block_device.get_device_letter("/dev/sda1"), "a")
     self.assertEqual(block_device.get_device_letter("/dev/xvdb"), "b")
     self.assertEqual(block_device.get_device_letter("/dev/d"), "d")
     self.assertEqual(block_device.get_device_letter("a"), "a")
     self.assertEqual(block_device.get_device_letter("sdb2"), "b")
     self.assertEqual(block_device.get_device_letter("vdc"), "c")
     self.assertEqual(block_device.get_device_letter("hdc"), "c")
开发者ID:wenlongwljs,项目名称:nova,代码行数:9,代码来源:test_block_device.py


示例4: test_get_device_letter

 def test_get_device_letter(self):
     self.assertEqual(block_device.get_device_letter(''), '')
     self.assertEqual(block_device.get_device_letter('/dev/sda1'), 'a')
     self.assertEqual(block_device.get_device_letter('/dev/xvdb'), 'b')
     self.assertEqual(block_device.get_device_letter('/dev/d'), 'd')
     self.assertEqual(block_device.get_device_letter('a'), 'a')
     self.assertEqual(block_device.get_device_letter('sdb2'), 'b')
     self.assertEqual(block_device.get_device_letter('vdc'), 'c')
     self.assertEqual(block_device.get_device_letter('hdc'), 'c')
开发者ID:anantk,项目名称:nova,代码行数:9,代码来源:test_block_device.py


示例5: get_root_info

def get_root_info(instance, virt_type, image_meta, root_bdm,
                  disk_bus, cdrom_bus, root_device_name=None):

    # NOTE (ndipanov): This is a hack to avoid considering an image
    #                  BDM with local target, as we don't support them
    #                  yet. Only applies when passed non-driver format
    no_root_bdm = (not root_bdm or (
        root_bdm.get('source_type') == 'image' and
        root_bdm.get('destination_type') == 'local'))
    if no_root_bdm:
        # NOTE(mriedem): In case the image_meta object was constructed from
        # an empty dict, like in the case of evacuate, we have to first check
        # if disk_format is set on the ImageMeta object.
        if (image_meta.obj_attr_is_set('disk_format') and
                image_meta.disk_format == 'iso'):
            root_device_bus = cdrom_bus
            root_device_type = 'cdrom'
        else:
            root_device_bus = disk_bus
            root_device_type = 'disk'
        if root_device_name:
            root_device_bus = get_disk_bus_for_disk_dev(virt_type,
                                                        root_device_name)
        else:
            root_device_name = find_disk_dev_for_disk_bus({}, root_device_bus)

        return {'bus': root_device_bus,
                'type': root_device_type,
                'dev': block_device.strip_dev(root_device_name),
                'boot_index': '1'}

    if not get_device_name(root_bdm) and root_device_name:
        root_bdm = root_bdm.copy()
        # it can happen, eg for libvirt+Xen, that the root_device_name is
        # incompatible with the disk bus. In that case fix the root_device_name
        if virt_type == 'xen':
            dev_prefix = get_dev_prefix_for_disk_bus(disk_bus)
            if not root_device_name.startswith(dev_prefix):
                letter = block_device.get_device_letter(root_device_name)
                root_device_name = '%s%s' % (dev_prefix, letter)
        root_bdm['device_name'] = root_device_name
    return get_info_from_bdm(instance, virt_type, image_meta,
                             root_bdm, {}, disk_bus)
开发者ID:Juniper,项目名称:nova,代码行数:43,代码来源:blockinfo.py



注:本文中的nova.block_device.get_device_letter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python block_device.get_root_bdm函数代码示例发布时间:2022-05-27
下一篇:
Python availability_zones.set_availability_zones函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap