当前位置: 首页>>代码示例>>Python>>正文


Python Device.from_device_file方法代码示例

本文整理汇总了Python中pyudev.Device.from_device_file方法的典型用法代码示例。如果您正苦于以下问题:Python Device.from_device_file方法的具体用法?Python Device.from_device_file怎么用?Python Device.from_device_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyudev.Device的用法示例。


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

示例1: test_from_device_file_no_device_file

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_file [as 别名]
 def test_from_device_file_no_device_file(self, context, tmpdir):
     filename = tmpdir.join("test")
     filename.ensure(file=True)
     with pytest.raises(ValueError) as excinfo:
         Device.from_device_file(context, str(filename))
     message = "not a device file: {0!r}".format(str(filename))
     assert str(excinfo.value) == message
开发者ID:bjornarg,项目名称:pyudev,代码行数:9,代码来源:test_device.py

示例2: _hp_ld_to_lsm_vol

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_file [as 别名]
    def _hp_ld_to_lsm_vol(hp_ld, pool_id, sys_id, ctrl_num, array_num, hp_ld_name):
        """
        raises DeviceNotFoundError
        """
        ld_num = hp_ld_name[len("Logical Drive: ") :]
        vpd83 = hp_ld["Unique Identifier"].lower()
        # No document or command output indicate block size
        # of volume. So we try to read from linux kernel, if failed
        # try 512 and roughly calculate the sector count.
        device = Device.from_device_file(_CONTEXT, hp_ld["Disk Name"])
        vol_name = "%s: /dev/%s" % (hp_ld_name, device.sys_name)
        attributes = device.attributes
        try:
            block_size = attributes.asint("queue/logical_block_size")
            num_of_blocks = attributes.asint("size")
        except (KeyError, UnicodeDecodeError, ValueError):
            block_size = 512
            num_of_blocks = int(_hp_size_to_lsm(hp_ld["Size"]) / block_size)

        if "Failed" in hp_ld["Status"]:
            admin_status = Volume.ADMIN_STATE_DISABLED
        else:
            admin_status = Volume.ADMIN_STATE_ENABLED
        plugin_data = "%s:%s:%s" % (ctrl_num, array_num, ld_num)

        # HP SmartArray does not allow disabling volume.
        return Volume(vpd83, vol_name, vpd83, block_size, num_of_blocks, admin_status, sys_id, pool_id, plugin_data)
开发者ID:yakirgb,项目名称:libstoragemgmt,代码行数:29,代码来源:hpsa.py

示例3: test_from_device_file_links

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_file [as 别名]
 def test_from_device_file_links(self, context, device_data):
     if not device_data.device_links:
         pytest.skip("no device links")
     for link in device_data.device_links:
         link = os.path.join(context.device_path, link)
         device = Device.from_device_file(context, link)
         assert device.device_path == device_data.device_path
         assert link in device.device_links
开发者ID:bjornarg,项目名称:pyudev,代码行数:10,代码来源:test_device.py

示例4: _hp_ld_to_lsm_vol

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_file [as 别名]
    def _hp_ld_to_lsm_vol(hp_ld, pool_id, sys_id, ctrl_num, array_num,
                          hp_ld_name):
        """
        raises DeviceNotFoundError
        """
        ld_num = hp_ld_name[len("Logical Drive: "):]
        vpd83 = hp_ld['Unique Identifier'].lower()
        # No document or command output indicate block size
        # of volume. So we try to read from linux kernel, if failed
        # try 512 and roughly calculate the sector count.
        block_size = 512
        num_of_blocks = int(_hp_size_to_lsm(hp_ld['Size']) / block_size)
        vol_name = hp_ld_name

        if len(vpd83) > 0:
            blk_paths = LocalDisk.vpd83_search(vpd83)
            if len(blk_paths) > 0:
                blk_path = blk_paths[0]
                vol_name += ": %s" % " ".join(blk_paths)
                device = Device.from_device_file(_CONTEXT, blk_path)
                attributes = device.attributes
                try:
                    block_size = attributes.asint("queue/logical_block_size")
                    num_of_blocks = attributes.asint("size")
                except (KeyError, UnicodeDecodeError, ValueError):
                    pass

        if 'Failed' in hp_ld['Status']:
            admin_status = Volume.ADMIN_STATE_DISABLED
        else:
            admin_status = Volume.ADMIN_STATE_ENABLED
        plugin_data = "%s:%s:%s" % (ctrl_num, array_num, ld_num)

        # HP SmartArray does not allow disabling volume.
        return Volume(
            vpd83, vol_name, vpd83, block_size, num_of_blocks,
            admin_status, sys_id, pool_id, plugin_data)
开发者ID:cvedel,项目名称:libstoragemgmt,代码行数:39,代码来源:hpsa.py

示例5: test_from_device_file_non_existing

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_file [as 别名]
 def test_from_device_file_non_existing(self, context, tmpdir):
     filename = tmpdir.join("test")
     assert not tmpdir.check(file=True)
     with pytest.raises(EnvironmentError) as excinfo:
         Device.from_device_file(context, str(filename))
     pytest.assert_env_error(excinfo.value, errno.ENOENT, str(filename))
开发者ID:bjornarg,项目名称:pyudev,代码行数:8,代码来源:test_device.py

示例6: test_from_device_file

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_file [as 别名]
 def test_from_device_file(self, context, device_data):
     if not device_data.device_node:
         pytest.skip("no device file")
     device = Device.from_device_file(context, device_data.device_node)
     assert device.device_node == device_data.device_node
     assert device.device_path == device_data.device_path
开发者ID:bjornarg,项目名称:pyudev,代码行数:8,代码来源:test_device.py


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