%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/runners/ |
Current File : //lib/python2.7/site-packages/salt/runners/survey.pyo |
� ���^c @@ s} d Z d d l m Z m Z m Z d d l Z d d l m Z d d l m Z d d l m Z d � Z d � Z d � Z d S( u A general map/reduce style salt runner for aggregating results returned by several different minions. .. versionadded:: 2014.7.0 Aggregated results are sorted by the size of the minion pools which returned matching results. Useful for playing the game: *"some of these things are not like the others..."* when identifying discrepancies in a large infrastructure managed by salt. i ( t absolute_importt print_functiont unicode_literalsN( t SaltClientError( t six( t rangec O@ s t | | � S( u� Return the MATCHING minion pools from the aggregated and sorted results of a salt command .. versionadded:: 2014.7.0 This command is submitted via a salt runner using the general form:: salt-run survey.hash [survey_sort=up/down] <target> <salt-execution-module> <salt-execution-module parameters> Optionally accept a ``survey_sort=`` parameter. Default: ``survey_sort=down`` CLI Example #1: (functionally equivalent to ``salt-run manage.up``) .. code-block:: bash salt-run survey.hash "*" test.ping CLI Example #2: (find an "outlier" minion config file) .. code-block:: bash salt-run survey.hash "*" file.get_hash /etc/salt/minion survey_sort=up ( t _get_pool_results( t argst kwargs( ( s7 /usr/lib/python2.7/site-packages/salt/runners/survey.pyt hash s c O@ s� d d l } t | | � } t } x�| D]�} t d � t | d � t d � t d t j t | d � � � | r� t } t d � t d | d d � t � q( n d j | d d d � } t | � t d t | � d � | d d j � } x- t d t | � � D] } | | c d 7<qW| d j � } x- t d t | � � D] } | | c d 7<qQWd } | d j | j | | d | d d d d | d d d d �� 7} t | � t � q( W| S( u& Return the DIFFERENCE of the result sets returned by each matching minion pool .. versionadded:: 2014.7.0 These pools are determined from the aggregated and sorted results of a salt command. This command displays the "diffs" as a series of 2-way differences -- namely the difference between the FIRST displayed minion pool (according to sort order) and EACH SUBSEQUENT minion pool result set. Differences are displayed according to the Python ``difflib.unified_diff()`` as in the case of the salt execution module ``file.get_diff``. This command is submitted via a salt runner using the general form:: salt-run survey.diff [survey_sort=up/down] <target> <salt-execution-module> <salt-execution-module parameters> Optionally accept a ``survey_sort=`` parameter. Default: ``survey_sort=down`` CLI Example #1: (Example to display the "differences of files") .. code-block:: bash salt-run survey.diff survey_sort=up "*" cp.get_file_str file:///etc/hosts i Nu minion pool : ------------u poolu pool size : ----------u u pool result : ------------u resultu differences from "{0}" results :u -i u u t fromfilet tofilet n( t difflibR t Truet printR t text_typet lent Falset formatt splitlinesR t joint unified_diff( R R R t bulk_rett is_first_timet kt outst from_resultt it to_result( ( s7 /usr/lib/python2.7/site-packages/salt/runners/survey.pyt diff: sB # ! c @ s� d d l } | d } | d } i � � j d d � } | d k } � j d d � } | d k rk d } n t � f d � t j � � D� � } t j j t d � } y3 | j | | | d d t d d | d | �} Wn t k r� } t | � � SXx� t | � D]� } | j t j | | � j t � � j � } | � k rzi � | <g � | d <t j | | � � | d <n � | d j | � qWg } x: t � d � f d � d | �D] } | j � | � q�W| S( u� A helper function which returns a dictionary of minion pools along with their matching result sets. Useful for developing other "survey style" functions. Optionally accepts a "survey_sort=up" or "survey_sort=down" kwargs for specifying sort order. Because the kwargs namespace of the "salt" and "survey" command are shared, the name "survey_sort" was chosen to help avoid option conflicts. i Ni u survey_sortu downu upu tgt_typeu compoundu pcrec 3@ s. | ]$ } | j d � s | � | f Vq d S( u _N( t startswith( t .0R ( R ( s7 /usr/lib/python2.7/site-packages/salt/runners/survey.pys <genexpr>� s u conf_filei t timeoutu timeoutt tgt_typet kwargu poolu resultt keyc @ s t � | d � S( Nu pool( R ( R ( t ret( s7 /usr/lib/python2.7/site-packages/salt/runners/survey.pyt <lambda>� s t reverse( u compoundu pcre( t hashlibt popt dictR t iterkeyst saltt clientt get_local_clientt __opts__t cmdR R t sortedt sha256R t encodet __salt_system_encoding__t hexdigestt append( R R R( t tgtR0 t sortt directionR"