3 ܓi>@s@ddlZddlmZddlmZddlmZGdddeZdS)N) ElementTree)Cluster)sos_parse_versionc@sHeZdZdZdgZdZdZdddgZd d Zd d Z ddZ ddZ dS) pacemakerz+Pacemaker High Availability Cluster ManagerTonlineCollect nodes listed as onlineofflineCollect nodes listed as offline only-corosyncF)Only use corosync.conf to enumerate nodescCsg|_y\|jdsRy |jWn2tk rP}z|jd|WYdd}~XnX|js`|jWn2tk r}z|jd|WYdd}~XnXdd|jD}|r|jddj|d|jS) Nz only-corosynczHFalling back to sourcing corosync.conf. Could not parse crm_mon output: z(Could not determine nodes from cluster: cSsg|]}d|kr|qS).).0nr r /usr/lib/python3.6/pacemaker.py /sz'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}|jd}|ddkrJ|djdjdd}t|tdkrNd }nd S|jd |d d }|ddkr||j|dd S)zG Try to parse crm_mon output for node list and status. z--output-as=xmlzcrm_mon --versionZstatusroutput-z2.0.3z--as-xmlNzcrm_mon --one-shot --inactive T)Z need_root)Zexec_primary_cmdsplitr parse_crm_xml)rZxmloptZ_verZcverZ_outr r rr9s   zpacemaker.get_nodes_from_crmcCsztj|}|jd}x`|D]X}|j}|jdrL|ddkrL|jj|dq|jdr|ddkr|jj|dqWdS)zA Parse the xml output string provided by crm_mon rrtruenamerZfalseN)rZ fromstringfindZattribrrappend)rZ xmlstringZ_xmlrnodeZ_noder r rr!Ms   zpacemaker.parse_crm_xmlcCsH|jd|jjd}tjd|}x |D]}|jj|djq(WdS)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:)(.*))rN)rZprimaryZ read_filerefindallrr%strip)rZccrr&r r rrZs     z!pacemaker.get_nodes_from_corosyncN)r)rTr)rTr )r Fr ) __name__ __module__ __qualname__Z cluster_nameZ sos_pluginsZpackagesZstrict_node_listZ option_listrrr!rr r r rrs r)r(Z xml.etreerZsos.collector.clustersrZ sos.utilitiesrrr r r r s