]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
examples/discover-loop.py: python example for nvme discovery
authorHannes Reinecke <hare@suse.de>
Tue, 11 May 2021 15:27:58 +0000 (17:27 +0200)
committerHannes Reinecke <hare@suse.de>
Sat, 19 Jun 2021 11:36:59 +0000 (13:36 +0200)
Add an example script on how nvme discovery can be done with
the libnvme python binding.

Signed-off-by: Hannes Reinecke <hare@suse.de>
examples/discover-loop.py [new file with mode: 0644]

diff --git a/examples/discover-loop.py b/examples/discover-loop.py
new file mode 100644 (file)
index 0000000..4582e6a
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+'''
+Example script for nvme discovery
+
+Copyright (c) 2021 Hannes Reinecke, SUSE Software Solutions
+Licensed under the Apache License, Version 2.0 (the "License"); you may
+not use this file except in compliance with the License. You may obtain
+a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations
+under the License.
+'''
+
+import libnvme
+r = libnvme.nvme_root()
+h = libnvme.nvme_host(r)
+c = libnvme.nvme_ctrl('nqn.2014-08.org.nvmexpress.discovery','loop')
+try:
+    c.connect(h)
+except:
+    sys.exit("Failed to connect!")
+
+print("connected to %s subsys %s" % (c.name, c.subsystem.name))
+try:
+    d = c.discover()
+    print (d)
+except:
+    print("Failed to discover!")
+    pass
+c.disconnect()