當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。