a >h>@s@ddlZddlmZddlmZddlmZGdddeZdS)N) ElementTree)Cluster)sos_parse_versionc@sFeZdZdZdgZdZdZgdZddZddZ d d Z d d Z d S) pacemakerz+Pacemaker High Availability Cluster Manager)rT))onlineTzCollect nodes listed as online)offlineTzCollect nodes listed as offline) only-corosyncFz)Only use corosync.conf to enumerate nodesc Csg|_z^|dsTz |Wn4tyR}z|d|WYd}~n d}~00|jsb|Wn4ty}z|d|WYd}~n d}~00dd|jD}|r|dd|d|jS) NrzHFalling back to sourcing corosync.conf. Could not parse crm_mon output: z(Could not determine nodes from cluster: cSsg|]}d|vr|qS).).0nr r D/usr/lib/python3.9/site-packages/sos/collector/clusters/pacemaker.py /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_nodess&   &zpacemaker.get_nodescCsd}|d}|ddkrJ|dddd}t|tdkrNd }nd S|jd |d d }|ddkr|||dd S)zG Try to parse crm_mon output for node list and status. z--output-as=xmlzcrm_mon --versionstatusroutput-z2.0.3z--as-xmlNzcrm_mon --one-shot --inactive T)Z need_root)Zexec_primary_cmdsplitr parse_crm_xml)rZxmloptZ_verZcverZ_outr r r r9s   zpacemaker.get_nodes_from_crmcCsvt|}|d}|D]X}|j}|drJ|ddkrJ|j|dq|dr|ddkr|j|dqdS)zA Parse the xml output string provided by crm_mon rrtruenamerZfalseN)rZ fromstringfindZattribrrappend)rZ xmlstringZ_xmlrnodeZ_noder r r r Ms  zpacemaker.parse_crm_xmlcCsD|d|jd}td|}|D]}|j|dq&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)rZprimaryZ read_filerefindallrr$strip)rZccrr%r r r rZs    z!pacemaker.get_nodes_from_corosyncN) __name__ __module__ __qualname__Z cluster_nameZ sos_pluginsZpackagesZstrict_node_listZ option_listrrr rr r r r rs r)r'Z xml.etreerZsos.collector.clustersrZ sos.utilitiesrrr r r r  s