22# SPDX-License-Identifier: Apache-2.0
33'''
44Example script for nvme discovery
5-
6- Copyright (c) 2021 Hannes Reinecke, SUSE Software Solutions
7- Licensed under the Apache License, Version 2.0 (the "License"); you may
8- not use this file except in compliance with the License. You may obtain
9- a copy of the License at
10-
11- http://www.apache.org/licenses/LICENSE-2.0
12-
13- Unless required by applicable law or agreed to in writing, software
14- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16- License for the specific language governing permissions and limitations
17- under the License.
185'''
196
207import sys
@@ -29,17 +16,24 @@ def disc_supp_str(dlp_supp_opts):
2916 }
3017 return [txt for msk , txt in d .items () if dlp_supp_opts & msk ]
3118
32- r = nvme .root ()
33- h = nvme .host (r )
34- c = nvme .ctrl (r , nvme .NVME_DISC_SUBSYS_NAME , 'loop' )
19+ root = nvme .root ()
20+ host = nvme .host (root )
21+
22+ subsysnqn = nvme .NVME_DISC_SUBSYS_NAME
23+ transport = 'tcp'
24+ traddr = '127.0.0.1'
25+ trsvcid = '4420'
26+
27+ ctrl = nvme .ctrl (root , subsysnqn = subsysnqn , transport = transport , traddr = traddr , trsvcid = trsvcid )
28+
3529try :
36- c .connect (h )
30+ ctrl .connect (host )
3731except Exception as e :
3832 sys .exit (f'Failed to connect: { e } ' )
3933
40- print (" connected to %s subsys %s" % ( c . name , c . subsystem . name ) )
34+ print (f' { ctrl . name } connected to subsys { ctrl . subsystem } ' )
4135
42- slp = c .supported_log_pages ()
36+ slp = ctrl .supported_log_pages ()
4337
4438try :
4539 dlp_supp_opts = slp [nvme .NVME_LOG_LID_DISCOVER ] >> 16
@@ -50,16 +44,20 @@ def disc_supp_str(dlp_supp_opts):
5044
5145try :
5246 lsp = nvme .NVMF_LOG_DISC_LSP_PLEO if dlp_supp_opts & nvme .NVMF_LOG_DISC_LID_PLEOS else 0
53- d = c .discover (lsp = lsp )
54- print (pprint .pformat (d ))
47+ disc_log = ctrl .discover (lsp = lsp )
5548except Exception as e :
5649 sys .exit (f'Failed to discover: { e } ' )
50+ disc_log = []
51+ pass
52+
53+ for dlpe in disc_log :
54+ print (f'log entry { dlpe ["portid" ]} : { dlpe ["subtype" ]} { dlpe ["subnqn" ]} ' )
5755
5856try :
59- c .disconnect ()
57+ ctrl .disconnect ()
6058except Exception as e :
6159 sys .exit (f'Failed to disconnect: { e } ' )
6260
63- c = None
64- h = None
65- r = None
61+ for s in host . subsystems ():
62+ for c in s . controllers ():
63+ print ( f' { s } : { c . name } ' )
0 commit comments