U
    -_g                     @   sB   d dl Z d dlZd dlZd dlmZmZmZ G dd deeZdS )    N)PluginRedHatPlugin	PluginOptc                   @   sL   e Zd ZdZdZdZdZdZdZe	ddd	d
gZ
dd Zdd Zdd ZdS )GlusterzGlusterFS storageZgluster)ZstorageZvirtz/run/gluster)Z	glusterfszglusterfs-core)z/etc/glusterdz/var/lib/glusterddumpFzenable glusterdump support)defaultZdescc           	   
      s|   d} fdd  |D }|D ]V}|d } ||}d}|dkr t|ddd}| d }|d	}W 5 Q R X q<q d
S )z Wait until state dump is done r   c                    s   g | ]}  |r|qS  )Zpath_isfile).0fselfr   </usr/lib/python3/dist-packages/sos/report/plugins/gluster.py
<listcomp>!   s    
 z.Gluster.wait_for_statedump.<locals>.<listcomp>   rzUTF-8)encodingZDUMP_END_TIMEN)listdirZ	path_joinopen	readlinescount)	r   Zname_dirZstatedumps_presentZstatedump_entriesZstatedump_fileZ_spathZretZsfile	last_liner   r   r   wait_for_statedump   s    
zGluster.wait_for_statedumpc              
   C   s   |  dr| | jsd S z>t| jd }|t| jd  |D ]}t| qFW n2 tk
r } z| d|  W 5 d }~X Y nX d S )Nr   z/*.dump.[0-9]*z/glusterd_state_[0-9]*_[0-9]*z"Could not remove statedump files: )	
get_optionpath_existsstatedump_dirglobextendosremoveOSErrorZ
_log_error)r   Zremove_filesnameerrr   r   r   postproc-   s    
zGluster.postprocc                 C   s  |  d |  d | jddd | d | jddd | d	d
dddddgtd  | dsx| dddg n
| d | dr$| | jrd}| |d dkrt	d | 
| j | | j q| jd n| jd| j | d}|d dkr$|d  d }| | | jd d!d}|d dkr|d  D ]}|d"s`qL|d#d  }| d$| d%d&| d'd(| d)d(| d*d+| d,d-| d.| d/d0| d'd1| d2| g
 qLd S )3Nz,/var/lib/glusterd/geo-replication/secret.pemz6/var/lib/glusterd/glusterfind/glusterfind_*_secret.pemzgluster peer statusZgluster_peer_status)Ztagszgluster pool listzgluster volume statusZgluster_v_statusz/etc/redhat-storage-releasez/etc/swift/z/etc/glusterd.rpmsavez/etc/glusterfsz/var/lib/glusterd/z(/run/gluster/shared_storage/nfs-ganesha/z$/var/lib/glusterd/glusterfind/.keys/z/run/gluster/*tier-dht/*Zall_logsz/var/log/glusterfs/*logz/var/log/glusterfs/*/*logz)/var/log/glusterfs/geo-replication/*/*logz/var/log/glusterfsr   z+killall -USR1 glusterfs glusterfsd glusterdZstatusr   r   z6could not send SIGUSR1 to glusterfs/glusterd processesz4Unable to generate statedumps, no such directory: %szgluster get-stateoutputr   zgluster volume infoZgluster_v_infozVolume Name:   zgluster volume get z allzgluster volume geo-replication z statuszgluster volume heal z infoz info split-brainzgluster volume status z clientszgluster snapshot list zgluster volume quota z listzgluster volume rebalance zgluster snapshot info zgluster snapshot status )Zadd_forbidden_pathZadd_cmd_outputZadd_copy_specr   r   r   r   Zexec_cmdtimesleepr   ZsosloginfoZwarningsplitZcollect_cmd_output
splitlines
startswith)r   Zstatedump_cmdstateZ
state_fileZ
volume_cmdlineZvolnamer   r   r   setup:   s|    













zGluster.setupN)__name__
__module____qualname__Z
short_descZplugin_nameZprofilesr   Zpackagesfilesr   Zoption_listr   r#   r.   r   r   r   r   r      s   r   )r   r   r&   Zsos.report.pluginsr   r   r   r   r   r   r   r   <module>	   s   