File: //lib/python3/dist-packages/sos/collector/clusters/__pycache__/pacemaker.cpython-38.pyc
U
i��d: � @ s@ d dl Z d dlmZ d dlmZ d dlmZ G dd� de�ZdS )� N)�Cluster)�
parse_version)�ElementTreec @ sH e Zd ZdZd gZdZdZdddgZdd� Zd d
� Z dd� Z
d
d� ZdS )� 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 | _ zZ| �d�sPz| �� W n0 tk
rN } z| �d| � W 5 d }~X Y nX | j s^| �� W n0 tk
r� } z| �d| � W 5 d }~X Y nX 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 |kr|�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_corosyncZ log_error�join)�self�errZ_shortsr
r
r
� get_nodes s*
� ��zpacemaker.get_nodesc C s~ d}| � d�}|d dkrJ|d �� d �d�d }t|�td�ksNd }nd
S | j d| dd
�}|d dkrz| �|d � d
S )zG
Try to parse crm_mon output for node list and status.
z--output-as=xmlzcrm_mon --versionZstatusr �output� �-z2.0.3z--as-xmlNz crm_mon --one-shot --inactive %sT)Z need_root)Zexec_primary_cmd�splitr �
parse_crm_xml)r ZxmloptZ_verZcverZ_outr
r
r
r 9 s
�zpacemaker.get_nodes_from_crmc C sv t �|�}|�d�}|D ]X}|j}| �d�rJ|d dkrJ| j�|d � q| �d�r|d dkr| j�|d � qdS )zA
Parse the xml output string provided by crm_mon
r r �true�namer ZfalseN)r Z
fromstring�findZattribr r �append)r Z xmlstringZ_xmlr �nodeZ_noder
r
r
r M s
zpacemaker.parse_crm_xmlc C sD | � d� | j�d�}t�d|�}|D ]}| j�|d �� � q&dS )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 ZprimaryZ read_file�re�findallr r"