3
ܓi> @ s@ d dl Z d dlmZ d dlmZ d dlmZ G dd deZdS ) N)ElementTree)Cluster)sos_parse_versionc @ sH e Zd ZdZd gZdZdZdddgZd
d Zdd
Z dd Z
dd ZdS ) pacemakerz+Pacemaker High Availability Cluster ManagerTonlineCollect nodes listed as onlineofflineCollect nodes listed as offline
only-corosyncF)Only use corosync.conf to enumerate nodesc C s g | _ y\| jdsRy| j W n2 tk
rP } z| jd| W Y d d }~X nX | j s`| j W n2 tk
r } z| jd| W Y d d }~X nX dd | j D }|r| jddj| d | j S ) Nz
only-corosynczHFalling back to sourcing corosync.conf. Could not parse crm_mon output: z(Could not determine nodes from cluster: c S s g | ]}d |kr|qS ). ).0nr
r
/usr/lib/python3.6/pacemaker.py
/ s z'pacemaker.get_nodes..zWARNING: 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_optionget_nodes_from_crm Exceptionlog_warnget_nodes_from_corosyncZ log_errorjoin)selferrZ_shortsr
r
r get_nodes s
""zpacemaker.get_nodesc C s d}| j d}|d dkrJ|d j d jdd }t|tdkrNd }nd
S | j d| dd
}|d dkr|| j|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-xmlNzcrm_mon --one-shot --inactive T)Z need_root)Zexec_primary_cmdsplitr
parse_crm_xml)r ZxmloptZ_verZcverZ_outr
r
r r 9 s
zpacemaker.get_nodes_from_crmc C sz t j|}|jd}x`|D ]X}|j}| jdrL|d dkrL| jj|d q| jdr|d dkr| jj|d qW dS )zA
Parse the xml output string provided by crm_mon
r r truenamer ZfalseN)r Z
fromstringfindZattribr r append)r Z xmlstringZ_xmlr nodeZ_noder
r
r r! M s
zpacemaker.parse_crm_xmlc C sH | j d | jjd}tjd|}x |D ]}| jj|d j q(W 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:)(.*))r N)r ZprimaryZ read_filerefindallr r% strip)r Zccr r&