本文整理汇总了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
示例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)
示例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
示例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)
示例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))
示例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