# py-lspci
[![Actions Status](https://github.com/YADRO-KNS/py-lspci/workflows/Python%20application/badge.svg)](https://github.com/YADRO-KNS/py-lspci/actions)
![PyPI - Status](https://img.shields.io/pypi/status/py-lspci.svg)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/py-lspci.svg)
![PyPI](https://img.shields.io/pypi/v/py-lspci.svg)
![PyPI - License](https://img.shields.io/pypi/l/py-lspci.svg)
----
py-lspci – parser for lspci output on remote or local UNIX machines.
This package provides convenient interface to interact with lspci output in form of Python objects.
## Getting Started
### Prerequisites
py-lspci requires python 3.6 or newer versions to run.
Also targets that you could interact with py-lspci must have [pciutils](http://mj.ucw.cz/sw/pciutils/) installed
on them.
### Installing
Cloning project from git repository
```bash
git clone https://github.com/YADRO-KNS/py-lspci.git
```
Installing from PyPi
```bash
pip3 install py-lspci
```
## Examples
### Connection
First we have to establish connection to our target as user with sudo privileges:
```python
import pylspci
scanner = pylspci.ScannerPCI(ip='192.168.1.1', username='admin', password='pa$$w0rd')
```
In cases if we targeting local machine we need to provide user password if user isn't root:
```python
import pylspci
scanner = pylspci.ScannerPCI(ip='127.0.0.1', password='pa$$w0rd')
```
### Select
With *ScannerPCI* object now we can write requests to get data from lspci output, main tool to do that is
**select** method, that will return *PCISelect* iterator object.
```
>>> scanner.select()
<pylspci.pci_scanner.PCISelect object at 0x7fa1dcda3940>
```
Select will return all PCI devices that matches select request.
```
>>> scanner.select().count()
22
>>> scanner.select(pci_address='0000:00:00.0').count()
1
```
For broad select requests you could use asterisk:
```
>>> scanner.select(type='Bridge').count()
0
>>> scanner.select(type='*Bridge').count()
10
```
Use multiple keyword arguments to specify search.
You could search by any attributes or properties of *PCIDevice* class.:
```
>>> scanner.select(type='*Bridge', is_upstream=True).count()
1
```
With *PCISelect* object you could loop over PCI devices that matches search parameters:
```
>>> for device in scanner.select(is_downstream=True):
... print(device)
...
0000:08:00.0 PCI bridge Intel Corporation JHL6240 Thunderbolt 3 Bridge [x4/x4][2.5GT/s/2.5GT/s]
0000:08:01.0 PCI bridge Intel Corporation JHL6240 Thunderbolt 3 Bridge [x4/x4][2.5GT/s/2.5GT/s]
0000:08:02.0 PCI bridge Intel Corporation JHL6240 Thunderbolt 3 Bridge [x4/x4][2.5GT/s/2.5GT/s]
```
Also you can chain your select requests:
```
>>> scanner.select(type='PCI bridge').count()
8
>>> scanner.select(type='PCI bridge').select(is_upstream=True).count()
1
```
### Get
Another search method is **get**. Basically it is the same select that will return first matching object
instead of list of objects or will raise exception in case if there was no matches.
```
>>> print(scanner.get(type='*Host'))
0000:07:00.0 PCI bridge Intel Corporation [x2/x2][8GT/s/8GT/s]
>>> print(scanner.get(type='*Host', is_upstream=True))
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/sergey/PycharmProjects/py-lspci/pylspci/pci_scanner.py", line 98, in get
if parent.is_host_bridge:
pylspci.pci_scanner.DoesNotExist: Unable to find PCI Device matching: {'type': '*Host', 'is_upstream': True}
```
### Get Connected
Another tool is **get_connected** method of Scanner, that returns *PCISelect* with all devices connected to passed device.
For Host Bridge it will return all devices in Root Complex. For Upstream of PCI Bridge - all Downstreams.
For Downstream or Root Ports - all connected Upstreams or Endpoints. End for Endpoints it will return empty list.
```
>>> scanner.get_connected(scanner.get(type='*Host')).count()
14
```
py-lspci uses cached value of lspci output, in case if you need to refresh that data, use *force_rescan* argument,
for any of mentioned methods.
```
>>> scanner.select(force_rescan=True)
```
### PCI rescan procedure
Last but not least method of *ScannerPCI* is **pci_rescan** that causes full rescan of PCI bus on target machine.
Be careful with this one, because not all distros support proper PCI rescan.
## Versioning
We use [SemVer](http://semver.org/) for versioning.
## Authors
* **[Sergey Parshin](https://github.com/shooshp)**
See also the list of [contributors](https://github.com/YADRO-KNS/py-lspci/graphs/contributors) who participated in this project.
## License
The code is available as open source under the terms of the [MIT License](LICENSE).
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共16个文件
py:8个
txt:4个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:py-lspci-0.0.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
py-lspci-0.0.3.tar.gz (16个子文件)
py-lspci-0.0.3
PKG-INFO 6KB
pylspci
pci_parser.py 8KB
__init__.py 122B
consoles
local_console.py 2KB
remote_console.py 5KB
__init__.py 127B
console.py 754B
pci_scanner.py 5KB
py_lspci.egg-info
PKG-INFO 6KB
requires.txt 16B
SOURCES.txt 368B
top_level.txt 8B
dependency_links.txt 1B
setup.cfg 38B
setup.py 887B
README.md 5KB
共 16 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功