U
    -_g
                     @   s&   d dl mZmZ G dd deeZdS )    )PluginIndependentPluginc                   @   s$   e Zd ZdZdZdZdZdd ZdS )
InfinibandzInfiniband informationZ
infiniband)Zhardware)zlibibverbs-utilsZopensmZrdmazinfiniband-diagsc                    s  |  dddg |  d | ddddd	g d
dddg}d}| |rR| |ng }|D ],}|drlqZ| || d D ]}|| d | d }z<t|ddd$}| }|dkrW 5 Q R  W q~W 5 Q R X W n tk
r   Y q~Y nX || d | d }	z@t|	ddd(}
|
 }|ds6W 5 Q R  W q~W 5 Q R X W n tk
r\   Y q~Y nX d| d|  |  fdd|D  q~qZd S )Nz/etc/ofed/openib.confz/etc/ofed/opensm.confz	/etc/rdmaz/var/log/opensm*Zibv_deviceszibv_devinfo -vZibstatZibstatusZ
ibswitchesZibhostsZ
iblinkinfoZsminfoZ	perfqueryz/sys/class/infiniband/Zhfiz/portsz/ports/z/link_layerrzUTF-8)encodingzInfiniBand
z/statez	: ACTIVE
z-C z -P c                    s   g | ]}| d   qS )  ).0cZoptsr   ?/usr/lib/python3/dist-packages/sos/report/plugins/infiniband.py
<listcomp>L   s     z$Infiniband.setup.<locals>.<listcomp>)	Zadd_copy_specZadd_cmd_outputZ
path_isdirlistdir
startswithopenreadlineIOErrorendswith)selfZ
ports_cmdsZ	ib_sysdirZib_devsZibdevZportZlfileZlink_fpZ
link_layerZsfileZstate_fpstater   r   r   setup   sT    





zInfiniband.setupN)__name__
__module____qualname__Z
short_descZplugin_nameZprofilesZpackagesr   r   r   r   r   r      s
   r   N)Zsos.report.pluginsr   r   r   r   r   r   r   <module>   s   