Skip to content

Commit 0054ede

Browse files
committed
Merge pull request #5 from rdobson/remotetool
Remotetool
2 parents 85a98c2 + 1a05bbb commit 0054ede

8 files changed

Lines changed: 278 additions & 26 deletions

File tree

hwinfo/pci/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def get_pci_id(self):
5656
self.lookup_value('pci_subdevice_id'),
5757
)
5858

59+
def get_pci_class(self):
60+
return self.lookup_value('pci_device_class')
61+
5962
def is_subdevice(self):
6063
return self.lookup_value('pci_subvendor_id') and self.lookup_value('pci_subdevice_id')
6164

@@ -65,3 +68,17 @@ def get_info(self):
6568
return "%s %s (%s %s)" % (self.get_subvendor_name(), self.get_subdevice_name(), self.get_vendor_name(), self.get_device_name())
6669
else:
6770
return "%s %s" % (self.get_vendor_name(), self.get_device_name())
71+
72+
def get_rec(self):
73+
rec = {}
74+
rec['vendor_name'] = self.get_vendor_name()
75+
rec['device_name'] = self.get_device_name()
76+
rec['vendor_id'] = self.get_vendor_id()
77+
rec['device_id'] = self.get_device_id()
78+
rec['class'] = self.get_pci_class()
79+
rec['subvendor_name'] = self.get_subvendor_name()
80+
rec['subdevice_name'] = self.get_subdevice_name()
81+
rec['subvendor_id'] = self.get_subvendor_id()
82+
rec['subdevice_id'] = self.get_subdevice_id()
83+
84+
return rec

hwinfo/pci/lspci.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LspciVVParser(CommandParser):
99
"""Parser object for the output of lspci -vv"""
1010

1111
ITEM_REGEXS = [
12-
r'(?P<pci_device_bus_id>([0-9][0-9]:[0-9][0-9]\.[0-9]))\ (?P<pci_device_type>[\w\ ]*):\ (?P<pci_device_string>(.*))\n',
12+
r'(?P<pci_device_bus_id>([0-9][0-9]:[0-9][0-9]\.[0-9]))\ (?P<pci_device_class_name>[\w\ ]*):\ (?P<pci_device_string>(.*))\n',
1313
r'Product\ Name:\ (?P<pci_device_vpd_product_name>(.)*)\n',
1414
r'Subsystem:\ (?P<pci_device_sub_string>(.)*)\n',
1515
]
@@ -18,7 +18,7 @@ class LspciVVParser(CommandParser):
1818

1919
MUST_HAVE_FIELDS = [
2020
'pci_device_bus_id',
21-
'pci_device_type',
21+
'pci_device_class_name',
2222
'pci_device_string',
2323
]
2424

@@ -27,7 +27,7 @@ class LspciNParser(CommandParser):
2727

2828
#ff:0d.1 0880: 8086:0ee3 (rev 04)
2929
ITEM_REGEXS = [
30-
r'(?P<pci_device_bus_id>([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]\.[0-9a-f]))\ (?P<pci_device_type_id>[0-9a-f]{4}):\ (?P<pci_vendor_id>[0-9a-f]{4}):(?P<pci_device_id>[0-9a-f]{4})',
30+
r'(?P<pci_device_bus_id>([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]\.[0-9a-f]))\ (?P<pci_device_class>[0-9a-f]{4}):\ (?P<pci_vendor_id>[0-9a-f]{4}):(?P<pci_device_id>[0-9a-f]{4})',
3131
]
3232

3333
ITEM_SEPERATOR = "\n"
@@ -36,11 +36,11 @@ class LspciNParser(CommandParser):
3636
'pci_device_bus_id',
3737
'pci_device_id',
3838
'pci_vendor_id',
39-
'pci_device_type_id',
39+
'pci_device_class',
4040
]
4141

4242

43-
LABEL_REGEX = r'[\w+\ \.\-\/]+'
43+
LABEL_REGEX = r'[\w+\ \.\-\/\[\]\(\)]+'
4444
CODE_REGEX = r'[0-9a-fA-F]{4}'
4545

4646
class LspciNNMMParser(CommandParser):
@@ -49,9 +49,9 @@ class LspciNNMMParser(CommandParser):
4949
#02:00.1 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"
5050

5151
ITEM_REGEXS = [
52-
r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_type_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_type_id>' + CODE_REGEX + r')\]"' \
52+
r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_class_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_class>' + CODE_REGEX + r')\]"' \
5353
+ r'\ "(?P<pci_vendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_vendor_id>' + CODE_REGEX + r')\]"\ "(?P<pci_device_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_id>' + CODE_REGEX + r')\]"' \
54-
+ r'\ .*\ "((?P<pci_subvendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_subvendor_id>' + CODE_REGEX + r')\])*"\ "((?P<pci_subdevice_name>' + LABEL_REGEX + r')\ \[(?P<pci_subdevice_id>' + CODE_REGEX + r')\])*',
54+
+ r'\ .*\"((?P<pci_subvendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_subvendor_id>' + CODE_REGEX + r')\])*"\ "((?P<pci_subdevice_name>' + LABEL_REGEX + r')\ \[(?P<pci_subdevice_id>' + CODE_REGEX + r')\])*',
5555
]
5656

5757
ITEM_SEPERATOR = "\n"

hwinfo/pci/tests/test_lspci.py

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class TestSingleDeviceVVParse(unittest.TestCase):
1212

1313
DEVICE_REC = {
1414
'pci_device_string': 'Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)',
15-
'pci_device_type': 'Ethernet controller',
15+
'pci_device_class': '0200',
16+
'pci_device_class_name': 'Ethernet controller',
1617
'pci_device_bus_id': '02:00.0',
1718
'pci_device_sub_string': 'Dell Device 0488',
1819
'pci_device_vpd_product_name': 'Broadcom NetXtreme II Ethernet Controller',
@@ -36,9 +37,9 @@ def test_pci_device_bus_id(self):
3637
rec = self.parser.parse_items().pop()
3738
self._assert_rec_key(rec, 'pci_device_bus_id')
3839

39-
def test_pci_device_type(self):
40+
def test_pci_device_class_name(self):
4041
rec = self.parser.parse_items().pop()
41-
self._assert_rec_key(rec, 'pci_device_type')
42+
self._assert_rec_key(rec, 'pci_device_class_name')
4243

4344
def test_pci_device_sub_string(self):
4445
rec = self.parser.parse_items().pop()
@@ -70,7 +71,7 @@ class TestSingleDeviceNParse(unittest.TestCase):
7071
'pci_device_bus_id': 'ff:10.5',
7172
'pci_vendor_id': '8086',
7273
'pci_device_id': '0eb5',
73-
'pci_device_type_id': '0880',
74+
'pci_device_class': '0880',
7475
}
7576

7677
def setUp(self):
@@ -89,8 +90,8 @@ def test_pci_vendor_id(self):
8990
def test_pci_device_id(self):
9091
self._assert_rec_key('pci_device_id')
9192

92-
def test_pci_device_type_id(self):
93-
self._assert_rec_key('pci_device_type_id')
93+
def test_pci_device_class(self):
94+
self._assert_rec_key('pci_device_class')
9495

9596
class TestMultiDeviceNParse(unittest.TestCase):
9697

@@ -113,8 +114,8 @@ class TestSingleDeviceNNMMParse(unittest.TestCase):
113114

114115
DEVICE_REC = {
115116
'pci_device_bus_id': '02:00.0',
116-
'pci_device_type_id': '0200',
117-
'pci_device_type_name': 'Ethernet controller',
117+
'pci_device_class': '0200',
118+
'pci_device_class_name': 'Ethernet controller',
118119
'pci_vendor_name': 'Broadcom Corporation',
119120
'pci_vendor_id': '14e4',
120121
'pci_device_id': '163b',
@@ -135,11 +136,11 @@ def _assert_rec_key(self, key):
135136
def test_pci_device_bus_id(self):
136137
self._assert_rec_key('pci_device_bus_id')
137138

138-
def test_pci_device_type_id(self):
139-
self._assert_rec_key('pci_device_type_id')
139+
def test_pci_device_class(self):
140+
self._assert_rec_key('pci_device_class')
140141

141-
def test_pci_device_type_name(self):
142-
self._assert_rec_key('pci_device_type_name')
142+
def test_pci_device_class_name(self):
143+
self._assert_rec_key('pci_device_class_name')
143144

144145
def test_pci_vendor_name(self):
145146
self._assert_rec_key('pci_vendor_name')
@@ -168,8 +169,8 @@ class LsiDeviceParse(TestSingleDeviceNNMMParse):
168169

169170
DEVICE_REC = {
170171
'pci_device_bus_id': '03:00.0',
171-
'pci_device_type_id': '0100',
172-
'pci_device_type_name': 'SCSI storage controller',
172+
'pci_device_class': '0100',
173+
'pci_device_class_name': 'SCSI storage controller',
173174
'pci_vendor_name': 'LSI Logic / Symbios Logic',
174175
'pci_vendor_id': '1000',
175176
'pci_device_id': '0058',
@@ -187,8 +188,8 @@ class IntelUSBControllerDeviceParse(TestSingleDeviceNNMMParse):
187188

188189
DEVICE_REC = {
189190
'pci_device_bus_id': '00:1d.0',
190-
'pci_device_type_id': '0c03',
191-
'pci_device_type_name': 'USB controller',
191+
'pci_device_class': '0c03',
192+
'pci_device_class_name': 'USB controller',
192193
'pci_vendor_name': 'Intel Corporation',
193194
'pci_vendor_id': '8086',
194195
'pci_device_id': '3b34',
@@ -199,6 +200,61 @@ class IntelUSBControllerDeviceParse(TestSingleDeviceNNMMParse):
199200
'pci_subdevice_id': '02a3',
200201
}
201202

203+
class EmulexNicDeviceParse(TestSingleDeviceNNMMParse):
204+
205+
SAMPLE_DATA = '0c:00.0 "Ethernet controller [0200]" "Emulex Corporation [19a2]" "OneConnect 10Gb NIC (be3) [0710]" -r02 "Emulex Corporation [10df]" "Device [e70b]"'
206+
207+
DEVICE_REC = {
208+
'pci_device_bus_id': '0c:00.0',
209+
'pci_device_class': '0200',
210+
'pci_device_class_name': 'Ethernet controller',
211+
'pci_vendor_name': 'Emulex Corporation',
212+
'pci_vendor_id': '19a2',
213+
'pci_device_id': '0710',
214+
'pci_device_name': 'OneConnect 10Gb NIC (be3)',
215+
'pci_subvendor_name': 'Emulex Corporation',
216+
'pci_subvendor_id': '10df',
217+
'pci_subdevice_name': 'Device',
218+
'pci_subdevice_id': 'e70b',
219+
}
220+
221+
class LsiSASDeviceParse(TestSingleDeviceNNMMParse):
222+
223+
SAMPLE_DATA = '06:00.0 "Serial Attached SCSI controller [0107]" "LSI Logic / Symbios Logic [1000]" "SAS2004 PCI-Express Fusion-MPT SAS-2 [Spitfire] [0070]" -r03 "IBM [1014]" "Device [03f8]"'
224+
225+
DEVICE_REC = {
226+
'pci_device_bus_id': '06:00.0',
227+
'pci_device_class': '0107',
228+
'pci_device_class_name': 'Serial Attached SCSI controller',
229+
'pci_vendor_name': 'LSI Logic / Symbios Logic',
230+
'pci_vendor_id': '1000',
231+
'pci_device_id': '0070',
232+
'pci_device_name': 'SAS2004 PCI-Express Fusion-MPT SAS-2 [Spitfire]',
233+
'pci_subvendor_name': 'IBM',
234+
'pci_subvendor_id': '1014',
235+
'pci_subdevice_name': 'Device',
236+
'pci_subdevice_id': '03f8',
237+
}
238+
239+
class BroadcomNetDeviceParse(TestSingleDeviceNNMMParse):
240+
241+
SAMPLE_DATA = '01:00.0 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme BCM5720 Gigabit Ethernet PCIe [165f]" "Dell [1028]" "Device [1f5b]"'
242+
243+
DEVICE_REC = {
244+
'pci_device_bus_id': '01:00.0',
245+
'pci_device_class': '0200',
246+
'pci_device_class_name': 'Ethernet controller',
247+
'pci_vendor_name': 'Broadcom Corporation',
248+
'pci_vendor_id': '14e4',
249+
'pci_device_id': '165f',
250+
'pci_device_name': 'NetXtreme BCM5720 Gigabit Ethernet PCIe',
251+
'pci_subvendor_name': 'Dell',
252+
'pci_subvendor_id': '1028',
253+
'pci_subdevice_name': 'Device',
254+
'pci_subdevice_id': '1f5b',
255+
}
256+
257+
202258
class TestMultiDeviceNNMMParse(unittest.TestCase):
203259

204260
SAMPLE_FILE = '%s/lspci-nnmm' % DATA_DIR

hwinfo/pci/tests/test_pci.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class TestPCIDeviceObject(unittest.TestCase):
77

88
DEVICE_REC = {
99
'pci_device_bus_id': '02:00.0',
10-
'pci_device_type_id': '0200',
11-
'pci_device_type_name': 'Ethernet controller',
10+
'pci_device_class': '0200',
11+
'pci_device_class_name': 'Ethernet controller',
1212
'pci_vendor_name': 'Broadcom Corporation',
1313
'pci_vendor_id': '14e4',
1414
'pci_device_id': '163b',
@@ -64,3 +64,7 @@ def test_is_subdevice(self):
6464
def test_get_device_info(self):
6565
info = self.device.get_info()
6666
self.assertEqual(info, 'Dell [Device 02a3] (Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet)')
67+
68+
def test_get_device_class(self):
69+
pci_class = self.device.get_pci_class()
70+
self.assertEqual(pci_class, '0200')

hwinfo/tools/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)