From: Hannes Reinecke Date: Tue, 11 May 2021 15:27:58 +0000 (+0200) Subject: examples/discover-loop.py: python example for nvme discovery X-Git-Tag: v1.0-rc0~124^2~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fe948f082f61db7e697901dc0af8ec4304bedb5d;p=users%2Fsagi%2Flibnvme.git examples/discover-loop.py: python example for nvme discovery Add an example script on how nvme discovery can be done with the libnvme python binding. Signed-off-by: Hannes Reinecke --- diff --git a/examples/discover-loop.py b/examples/discover-loop.py new file mode 100644 index 00000000..4582e6a9 --- /dev/null +++ b/examples/discover-loop.py @@ -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()