3 ܓi>@s>ddlZddlmZddlmZddlmZGdddZdS)N)Lock) ClusterOption)boldc@seZdZdZgZd;ZgZiZiZdZ dZ dZ ddZ e ddZe d d Ze d d Zd dZddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zdosz'Cluster.display_help..F)newlinezUses the following sos preset: css"|]\}}d|d|VqdS)z-- Nr)rkvrrrr!{sz Sets the following sos options: zEnables the following plugins: css|] }|VqdS)Nr)rZplugrrrr!scss |]\}}|d|VqdS)=Nr)rr$r%rrrr!sz#Sets the following plugin options: zAvailable cluster optionsz/These options may be toggled or changed using 'z-c z.$option=$value' r#z<4z Option Namez<20ZDefaultz<30 DescriptionzTrue/Onz False/Offr)rdisplay_self_help set_titler__doc__add_text__mro__packagesjoin sos_preset sos_optionsitems sos_pluginssos_plugin_options option_listZ add_sectionrr isinstancebool)rsectionZ_optsr ZoptsecoptvalZ_lnrrr display_help]s^      $zCluster.display_helpcCs|jd|jd|jdddlm}ddl}|j|j|d}|jd|jdd d d d d ddxD|D]<}td|d}|jdd |d |djd ddqtWdS)Nz*SoS Collect Cluster Profiles Detailed Helpz Cluster profiles are used to represent different clustering technologies or platforms. Profiles define how cluster nodes are discovered, and optionally filtered, for default executions of collector.zCluster profiles are enabled similarly to SoS report plugins; usually by package, command, or configuration file presence. Clusters may also define default transports for SoS collect.r) SoSCollectorclustersz6The following cluster profiles are locally available: r#z>8Namez<40r)z<30F)r"zcollect.clusters.r) r,r.Z sos.collectorr>inspectZ _load_modulesZ getmodulerr)rr:r>rAr?clusterZ_secrrrr+s&    zCluster.display_self_helpcCsFx@|jD]6}t|d|dj|d|j|dd}|jj|qWdS)zALoads the options defined by a cluster and sets the default valuerrr*)rZopt_typevaluerB descriptionN)r7rr r rr)rr;optionrrrrs    zCluster._get_optionscCsd|jdd|S)N[rz] )r )rmsgrrr_fmt_msgszCluster._fmt_msgcCs|jj|j|dS)zUsed to print info messagesN)rinforH)rrGrrrlog_infoszCluster.log_infocCs|jj|dS)zUsed to print error messagesN)rerror)rrGrrr log_errorszCluster.log_errorcCs|jj|j|dS)zUsed to print debug messagesN)rdebugrH)rrGrrr log_debugszCluster.log_debugcCs|jj|j|dS)zUsed to print warning messagesN)rZwarningrH)rrGrrrlog_warnszCluster.log_warncCsRx,|jjD] }|j|kr |j|jkr |jSq Wx|jD]}|j|kr6|jSq6WdS)a This is used to by clusters to check if a cluster option was supplied to sos collect :param option: The name of the option to fetch :type option: ``str`` :returns: The value of the requested option if it exists, or ``False`` F)r Zcluster_optionsrrBr rCr)rrEr;rrr get_options     zCluster.get_optioncCs ||_dS)aSome clusters generate and/or deploy well-known and consistent SSH keys across environments. If this is the case, the cluster profile may call this command so that subsequent node connections will use that key rather than prompting the user for one or a password. Note this will only function if collector is being run locally on the primary node. N)r )rkeyrrradd_default_ssh_keys zCluster.add_default_ssh_keycCsdS)a If there is a need to set specific options on ONLY the non-primary nodes in a collection, override this method in the cluster profile and do that here. :param node: The non-primary node :type node: ``SoSNode`` Nr)rnoderrrset_node_optionsszCluster.set_node_optionscCsdS)a`The default connection type used by sos collect is to leverage the local system's SSH installation using ControlPersist, however certain cluster types may want to use something else. Override this in a specific cluster profile to set the ``transport`` option according to what type of transport should be used. Zcontrol_persistr)rrrrset_transport_typeszCluster.set_transport_typecCsdS)aIf there is a need to set specific options in the sos command being run on the cluster's primary nodes, override this method in the cluster profile and do that here. :param node: The primary node :type node: ``SoSNode`` Nr)rrSrrrset_primary_optionsszCluster.set_primary_optionscCs|j|jjkS)aIn the event there are multiple primaries, or if the collect command is being run from a system that is technically capable of enumerating nodes but the cluster profiles needs to specify primary-specific options for other nodes, override this method in the cluster profile :param node: The node for the cluster to check :type node: ``SoSNode`` )Zaddressr)rrSrrrcheck_node_is_primarys zCluster.check_node_is_primaryautocCs4|jj||||d}|dr0|djdd|d<|S)a(Used to retrieve command output from a (primary) node in a cluster :param cmd: The command to run :type cmd: ``str`` :param need_root: Does the command require root privileges :type need_root: ``bool`` :param timeout: Amount of time to allow cmd to run in seconds :type timeout: ``int`` :param use_shell: Does the command required execution within a shell? :type use_shell: ``auto`` or ``bool`` :returns: The output and status of `cmd` :rtype: ``dict`` ) need_root use_shelltimeoutoutputz Password:r)rZ run_commandreplace)rcmdrZr\r[resrrrexec_primary_cmd&s   zCluster.exec_primary_cmdcCsdS)z This MAY be used by a cluster to do prep work in case there are extra commands to be run even if a node list is given by the user, and thus get_nodes() would not be called Nr)rrrrsetup?sz Cluster.setupcCs$x|jD]}|jj|rdSqWdS)a This may be overridden by clusters This is called by sos collect on each cluster type that exists, and is meant to return True when the cluster type matches a criteria that indicates that is the cluster type is in use. Only the first cluster type to determine a match is run :returns: ``True`` if the cluster profile should be used, or ``False`` :rtype: ``bool`` TF)r0rZ is_installed)rZpkgrrr check_enabledFs  zCluster.check_enabledcCsdS)z This may be overridden by clusters Perform any necessary cleanup steps required by the cluster profile. This helps ensure that sos does make lasting changes to the environment in which we are running Nr)rrrrcleanupXszCluster.cleanupcCstdS)aB This MUST be overridden by a cluster profile subclassing this class A cluster should use this method to return a list or string that contains all the nodes that a report should be collected from :returns: A list of node FQDNs or IP addresses :rtype: ``list`` or ``None`` N)NotImplementedError)rrrr get_nodesas zCluster.get_nodescCs>y|jStk r8}z|jd|gSd}~XnXdS)NzFailed to get node list: )format_node_list ExceptionrN)rerrr _get_nodesms zCluster._get_nodescCs|j|}|jjd||S)aE Used by ``SosNode()`` to retrieve the appropriate label from the cluster as set by ``set_node_label()`` in the cluster profile. :param node: The name of the node to get a label for :type node: ``str`` :returns: The label to use for the node's report :rtype: ``str`` label)set_node_labelZmanifestZ add_field)rrSrkrrrget_node_labelts zCluster.get_node_labelcCsdS)zThis may be overridden by clusters profiles subclassing this class If there is a distinction between primaries and nodes, or types of nodes, then this can be used to label the sos report archives as needed rr)rrSrrrrlszCluster.set_node_labelcCsy |j}Wn2tk r>}ztd||WYdd}~XnXt|trZdd|D}n(t|trtdd|D}ntd|tt|}x |D]}|jdr|j|qW|S)z Format the returned list of nodes from a cluster into a known format. This being a list that contains no duplicates :returns: A list of nodes, without extraneous entries from cmd output :rtype: ``list`` z#Cluster failed to enumerate nodes: NcSsg|]}|r|jqSr)strip)rnrrr sz,Cluster.format_node_list..cSsg|]}|jdjqS),)splitrn)rrorrrrpsz'Cluster returned unexpected node list: -_()rF]/\)rsrtrurvrFrwrxry)rfrhr8liststrset startswithremove)rZnodeserrrrSrrrrgs       zCluster.format_node_listc Cstg}yV|j}|rXt|ts"|g}x4|D],}|j}|j|d|kr(|j|dq(WWntk rnYnX|S)a) Ensures that any files returned by a cluster's run_extra_cmd() method are properly typed as a list for iterative collection. If any of the files are an additional sos report (e.g. the ovirt db dump) then the md5 sum file is automatically added to the list Z sosreportz.md5)Z run_extra_cmdr8rzrnrAttributeError)rfilesr`Z extra_filerrr_run_extra_cmds   zCluster._run_extra_cmd)r)FrXrY)'r __module__ __qualname__r-r7r0r5r3r6r2rZstrict_node_listr classmethodrr=r+rrHrJrLrNrOrPrRrTrUrVrWrarbrcrdrfrjrmrlrgrrrrrrsH%  F "        r)rZ threadingrZ sos.optionsrZ sos.utilitiesrrrrrr s