File: //lib/python3/dist-packages/sos/collector/clusters/__pycache__/pacemaker.cpython-310.pyc
o
i��d: � @ s@ d dl Z d dlmZ d dlmZ d dlmZ G dd� de�ZdS )� N)�Cluster)�
parse_version)�ElementTreec @ sF e Zd ZdZd gZdZdZg d�Zdd� Zdd� Z d d
� Z
dd� Zd
S )� pacemakerz+Pacemaker High Availability Cluster Manager)r T))�onlineTzCollect nodes listed as online)�offlineTzCollect nodes listed as offline)�
only-corosyncFz)Only use corosync.conf to enumerate nodesc
C s� g | _ z.| �d�s)z| �� W n ty( } z
| �d| � W Y d }~nd }~ww | j s0| �� W n tyJ } z
| �d| � W Y d }~nd }~ww dd� | j D �}|r_| �dd�|� � | j S )Nr zJFalling back to sourcing corosync.conf. Could not parse crm_mon output: %sz*Could not determine nodes from cluster: %sc S s g | ]}d |vr|�qS )�.� )�.0�nr
r
�B/usr/lib/python3/dist-packages/sos/collector/clusters/pacemaker.py�
<listcomp>/ s z'pacemaker.get_nodes.<locals>.<listcomp>z�WARNING: Node addresses '%s' 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�_shortsr
r
r
� get_nodes s4
��������zpacemaker.get_nodesc C s� d}| � d�}|d dkr%|d �� d �d�d }t|�td�ks$d }nd
S | j d| dd
�}|d dkr?| �|d � d
S d
S )zG
Try to parse crm_mon output for node list and status.
z--output-as=xmlzcrm_mon --version�statusr �output� �-z2.0.3z--as-xmlNz crm_mon --one-shot --inactive %sT)� need_root)�exec_primary_cmd�splitr �
parse_crm_xml)r �xmlopt�_ver�cver�_outr
r
r
r 9 s
���zpacemaker.get_nodes_from_crmc C sv t �|�}|�d�}|D ],}|j}| �d�r%|d dkr%| j�|d � q| �d�r8|d dkr8| j�|d � qdS )zA
Parse the xml output string provided by crm_mon
r r �true�namer �falseN)r �
fromstring�find�attribr r �append)r � xmlstring�_xmlr �node�_noder
r
r
r# M s
��zpacemaker.parse_crm_xmlc C sD | � d� | j�d�}t�d|�}|D ]}| j�|d �� � qdS )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 r. �strip)r �ccr r1 r
r
r
r Z s
�z!pacemaker.get_nodes_from_corosyncN)�__name__�
__module__�__qualname__�cluster_name�sos_plugins�packages�strict_node_list�option_listr r r# r r
r
r
r
r s
r )r6 �sos.collector.clustersr �
sos.utilitiesr � xml.etreer r r
r
r
r
�<module> s