
    ~ g>                     F    S SK r S SKJr  S SKJr  S SKJr   " S S\5      rg)    N)ElementTree)Cluster)sos_parse_versionc                   F    \ rS rSrSrS /rSrSr/ SQrS r	S r
S rS	 rS
rg)	pacemaker   z+Pacemaker High Availability Cluster Manager)r   T))onlineTzCollect nodes listed as online)offlineTzCollect nodes listed as offline)only-corosyncFz)Only use corosync.conf to enumerate nodesc                    / U l          U R                  S5      (       d   U R                  5         U R                   (       d  U R                  5         U R                    Vs/ s H  nSU;  d  M  UPM     nnU(       a$  U R	                  SSR                  U5       S35        U R                   $ ! [         a  nU R	                  SU 35         S nANS nAff = f! [         a  nU R                  SU 35         S nANS nAff = fs  snf )Nr   zHFalling back to sourcing corosync.conf. Could not parse crm_mon output: z(Could not determine nodes from cluster: .zWARNING: Node addresses ',z' may not resolve locally if you are not running on a node in the cluster. Try using option '-c pacemaker.only-corosync' if these connections fail.)nodes
get_optionget_nodes_from_crm	Exceptionlog_warnget_nodes_from_corosync	log_errorjoin)selferrn_shortss       B/usr/lib/python3/dist-packages/sos/collector/clusters/pacemaker.py	get_nodespacemaker.get_nodes   s   
	M???33L++- :: ,,. #jj9jCqL1j9MM+CHHW,=+> ?* * zz% ! LMM #EEHE#K L LL  	MNNEcUKLL	M :sK   C B, !C 
D-D,
C6C
C CC 
C?!C::C?c                 &   SnU R                  S5      nUS   S:X  aC  US   R                  5       S   R                  S5      S   n[        U5      [        S5      ::  a  S	nOg
U R                  SU 3SS9nUS   S:X  a  U R                  US   5        g
g
)z7
Try to parse crm_mon output for node list and status.
z--output-as=xmlzcrm_mon --versionstatusr   output   -z2.0.3z--as-xmlNzcrm_mon --one-shot --inactive T)	need_root)exec_primary_cmdsplitr   parse_crm_xml)r   xmlopt_vercver_outs        r   r   pacemaker.get_nodes_from_crm9   s     #$$%89>Q>'')!,2237:D &*;G*DD#$$,VH5 % 
 >QtH~.     c                 |   [         R                  " U5      nUR                  S5      nU H  nUR                  nU R	                  S5      (       a)  US   S:X  a   U R
                  R                  US   5        MN  U R	                  S5      (       d  Mf  US   S:X  d  Mq  U R
                  R                  US   5        M     g)z1
Parse the xml output string provided by crm_mon
r   r	   truenamer
   falseN)r   
fromstringfindattribr   r   append)r   	xmlstring_xmlr   node_nodes         r   r&   pacemaker.parse_crm_xmlM   s     %%i0		'"DKKEx((U8_-F

!!%-0++h70J

!!%-0 r,   c                     U R                  S5        U R                  R                  S5      n[        R                  " SU5      nU H/  nU R
                  R                  US   R                  5       5        M1     g)z
As a fallback measure, read corosync.conf to get the node list. Note
that this prevents us from separating online nodes from offline nodes.
z_WARNING: unable to distinguish online nodes from offline nodes when sourcing from corosync.confz/etc/corosync/corosync.confz((\sring0_addr:)(.*))N)r   primary	read_filerefindallr   r4   strip)r   ccr   r7   s       r   r   !pacemaker.get_nodes_from_corosyncZ   sd    
 	 G 	H\\##$AB

3R8DJJd2hnn./ r,   )r   N)__name__
__module____qualname____firstlineno__cluster_namesos_pluginspackagesstrict_node_listoption_listr   r   r&   r   __static_attributes__ r,   r   r   r      s4    @L-KHK6/(1
0r,   r   )r>   	xml.etreer   sos.collector.clustersr   sos.utilitiesr   r   rM   r,   r   <module>rQ      s!    
 ! * +R0 R0r,   