%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/roster/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/roster/cache.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlm
Z
ddlmZeje�Zdd�Zd�Zd	�Zd
�ZdS(u�

The ``cache`` roster provides a flexible interface to the Salt Masters' minion cache
to access regular minions over ``salt-ssh``.

.. versionadded:: 2017.7.0

    - grains, pillar, mine data matching
    - SDB URLs
    - IPv6 support
    - roster_order per config key
    - default order changed to industry-wide best practices
    - CIDR range selection


Targeting
---------

This roster supports all matching and targeting of the Salt Master.
The matching will be done using only the Salt Master's cache.


The Roster Order
----------------

The roster's composition can be configured using ``roster_order``.
In the ``roster_order`` you can define *any* roster key and fill it with a parameter
overriding the one in ``roster_defaults``:

.. code-block:: yaml

    roster_order:
        host: id          # use the minion id as hostname


You can define lists of parameters as well, the first result from the list will become the value.


Selecting a host
================

.. code-block:: yaml

    # default
    roster_order:
        host:
          - ipv6-private  # IPv6 addresses in private ranges
          - ipv6-global   # IPv6 addresses in global ranges
          - ipv4-private  # IPv4 addresses in private ranges
          - ipv4-public   # IPv4 addresses in public ranges
          - ipv4-local    # loopback addresses


This is the default ``roster_order``.
It prefers IPv6 over IPv4 addresses and private addresses over public ones.
The relevant data will be fetched from the cache in-order, and the first match will fill the ``host`` key.

Other address selection parameters are also possible:

.. code-block:: yaml

    roster_order:
      host:
        - global|public|private|local    # Both IPv6 and IPv4 addresses in that range
        - 2000::/3                       # CIDR networks, both IPv4 and IPv6 are supported


Using cached data
=================

Several cached libraries can be selected using the ``library: `` prefix, followed by the library key.
This can be referenced using the same ``:`` syntax as e.g. :py:func:`pillar.get <salt.modules.pillar.get>`.
Lists of references are also supported during the lookup, as are Salt SDB URLs.

This should be especially useful for the other roster keys:

.. code-block:: yaml

    roster_order:
      host:
        - grain: fqdn_ip4                # Lookup this grain
        - mine: network.ip_addrs         # Mine data lookup works the same

      password: sdb://vault/ssh_pass     # Salt SDB URLs are also supported

      user:
        - pillar: ssh:auth:user          # Lookup this pillar key
        - sdb://osenv/USER               # Lookup this env var through sdb

      priv:
        - pillar:                        # Lists are also supported
            - salt:ssh:private_key
            - ssh:auth:private_key

i(tabsolute_importtprint_functiontunicode_literalsN(t	ipaddress(tsixuglobcK@sztjjjt�}|j||�}|d}i}|sA|Stjjt�}tjdidd6�}i}x�|D]�}yt	||�}	Wnt
k
r�qynXtjtjdi��}
xr|j
�D]d\}}t|ttf�s�|g}nx4|D],}
t||
|	�}|r||
|<PqqWq�Wd|
krR|
||<qytjd	|�qyWtjd
|�|S(u�
    Return the targets from the Salt Masters' minion cache.
    All targets and matchers are supported.

    The resulting roster can be configured using ``roster_order`` and ``roster_default``.
    uminionsuroster_orderuipv6-privateuipv6-globaluipv4-privateuipv4-publicuhosturoster_defaultsu2Could not determine host information for minion %suRoster lookup result: %s(uipv6-privateuipv6-globaluipv4-privateuipv4-public(tsalttutilstminionst	CkMinionst__opts__t
check_minionstcachetCachetgett_load_miniontLookupErrortcopytdeepcopytitemst
isinstancetlistttuplet_minion_lookuptlogtwarningtdebug(ttgtttgt_typetkwargsRt_restretRtroster_ordert	minion_idtminiont
minion_restparamtordertkeytkres((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyttargetsqs:






cC@s"tjjj|t�\}}}||krItjd||�t�n|shtjd|�i}n|s�tjd|�i}nit	g|j
dg�D]}tj|�^q��d6t	g|j
dg�D]}tj
|�^q��d6}|jdj|�d	�}||||fS(
NuAsked for minion %s, got %suNo grain data for minion id %suNo pillar data for minion id %suipv4iuipv6iuminions/{0}umine(RRRtget_minion_dataR	RterrorRRtsortedR
RtIPv4AddresstIPv6Addresstfetchtformat(R Rtdata_miniontgrainstpillartaddrtaddrstmine((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyR�s!			58cC@sjt|tj�r|g}ng}x?|D]7}tjjj||d�}|r+|j|�q+q+W|S(N(	RRtstring_typesRRtdatattraverse_dict_and_listtNonetappend(treftlookuptrestdata_keyR6((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyt_data_lookup�s
cC@s|\}}}}|dkr"|St|t�r�x�|j�D]P\}}i|d6|d6|d6|}	x!t|	|�D]}
|
ry|
SqyWdSWnz|jd�r�td|�Stjd|�r6yt	j
|dt�}Wn"tk
rt
jd	|�dSXx
||jD]}||krtj|�SqWn�id
�d6d�d
6d�d6d�d6}
ddg}|jd�r�t|d�g}|d}nxm|D]e}y6x/||D]#}|
||�r�tj|�Sq�WWq�tk
r
tdj|���q�Xq�WdS(Nuidupillarugrainumineusdb://usdb.getu^[0-9a-fA-F:./]+$tstrictu%s is an invalid CIDR networkcS@s|jdkr|jS|jS(Ni(tversiont	is_globalt
is_private(R2((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyt<lambda>�suglobalcS@s|jS(N(RB(R2((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyRC�supubliccS@s|jo|jo|jS(N(RBtis_loopbackt
is_link_local(R2((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyRC�suprivatecS@s|jS(N(RD(R2((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyRC�sulocaliiuipviiu,Invalid filter {0} specified in roster_order(RtdictRR>R8t
startswithRtretmatchRt
ip_networktTruet
ValueErrorRR)R@Rt	text_typetinttKeyErrorR.(R R%R!R0R1R3R4tdata_idR;R:tktnetR2tfilterstip_verstip_ver((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyR�sR







(t__doc__t
__future__RRRtloggingRHRtsalt.utils.dataRtsalt.utils.minionst
salt.cachetsalt._compatRtsalt.extRt	getLoggert__name__RR'RR>R(((s5/usr/lib/python2.7/site-packages/salt/roster/cache.pyt<module>_s1		

Zerion Mini Shell 1.0