Skip to content

Commit c2794b8

Browse files
committed
libnvme/tests: add example discovery script
Add an example script on how to do a nvme discovery via the python bindings. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 563092f commit c2794b8

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

libnvme/tests/discovery.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: LGPL-2.1-or-later
3+
import sys
4+
import pprint
5+
from libnvme import nvme
6+
7+
root = nvme.root()
8+
root.log_level('debug')
9+
10+
host = nvme.host(root)
11+
subsysnqn = nvme.NVME_DISC_SUBSYS_NAME
12+
transport = 'tcp'
13+
traddr = '127.0.0.1'
14+
trsvcid = '4420'
15+
16+
17+
ctrl = nvme.ctrl(root, subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid)
18+
19+
try:
20+
ctrl.connect(host)
21+
except Exception as e:
22+
sys.exit(f'Failed to connect: {e}')
23+
24+
print(f'connected to {ctrl.name}')
25+
26+
try:
27+
disc_log = ctrl.discover();
28+
except Exception as e:
29+
print(f'Failed to retrieve discovery log: {e}')
30+
disc_log = []
31+
pass
32+
33+
for dlpe in disc_log:
34+
print(f'log entry {dlpe["portid"]}: {dlpe["subtype"]} {dlpe["subnqn"]}')
35+
36+
try:
37+
ctrl.disconnect()
38+
except Exception as e:
39+
sys.exit(f'Failed to disconnect: {e}')
40+
41+
for s in host.subsystems():
42+
for c in s.controllers():
43+
print(f'{s}: {c.name}')

0 commit comments

Comments
 (0)