o id:@s@ddlZddlmZddlmZddlmZGdddeZdS)N)Cluster) parse_version) ElementTreec@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.|ds)z|Wnty(}z |d|WYd}~nd}~ww|js0|WntyJ}z |d|WYd}~nd}~wwdd|jD}|r_|dd||jS)NrzJFalling back to sourcing corosync.conf. Could not parse crm_mon output: %sz*Could not determine nodes from cluster: %scSsg|]}d|vr|qS).).0nr r B/usr/lib/python3/dist-packages/sos/collector/clusters/pacemaker.py /sz'pacemaker.get_nodes..zWARNING: 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_optionget_nodes_from_crm Exceptionlog_warnget_nodes_from_corosync log_errorjoin)selferr_shortsr r r get_nodess4  zpacemaker.get_nodescCsd}|d}|ddkr%|dddd}t|tdks$d }nd S|jd |d d }|ddkr?||dd Sd S)zG Try to parse crm_mon output for node list and status. z--output-as=xmlzcrm_mon --versionstatusroutput-z2.0.3z--as-xmlNz crm_mon --one-shot --inactive %sT) need_root)exec_primary_cmdsplitr parse_crm_xml)rxmlopt_vercver_outr r r r9s   zpacemaker.get_nodes_from_crmcCsvt|}|d}|D],}|j}|dr%|ddkr%|j|dq |dr8|ddkr8|j|dq dS)zA Parse the xml output string provided by crm_mon rrtruenamerfalseN)r fromstringfindattribrrappend)r xmlstring_xmlrnode_noder r r r#Ms  zpacemaker.parse_crm_xmlcCsD|d|jd}td|}|D] }|j|dqdS)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)rprimary read_filerefindallrr.strip)rccrr1r r r rZs   z!pacemaker.get_nodes_from_corosyncN) __name__ __module__ __qualname__ cluster_name sos_pluginspackagesstrict_node_list option_listrrr#rr r r r rs r)r6sos.collector.clustersr sos.utilitiesr xml.etreerrr r r r s