%PDF- %PDF-
| Direktori : /proc/self/root/proc/self/root/proc/self/root/lib/python2.7/site-packages/salt/roster/ |
| Current File : //proc/self/root/proc/self/root/proc/self/root/lib/python2.7/site-packages/salt/roster/cache.pyc |
�
���^c @@ s� d Z d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l
Z d d l Z d d l m
Z
d d l m Z e j e � Z d d � Z d � Z d � Z d
� Z d S( 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 ( t absolute_importt print_functiont unicode_literalsN( t ipaddress( t sixu globc K@ sz t j j j t � } | j | | � } | d } i } | sA | St j j t � } t j d i d d 6� } i } x� | D]� } y t | | � } Wn t
k
r� qy n Xt j t j d i � � }
xr | j
� D]d \ } } t | t t f � s� | g } n x4 | D], }
t | |
| � } | r| |
| <PqqWq� Wd |
k rR|
| | <qy t j d | � qy Wt j d
| � | 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``.
u minionsu roster_orderu ipv6-privateu ipv6-globalu ipv4-privateu ipv4-publicu hostu roster_defaultsu2 Could not determine host information for minion %su Roster lookup result: %s( u ipv6-privateu ipv6-globalu ipv4-privateu ipv4-public( t saltt utilst minionst CkMinionst __opts__t
check_minionst cachet Cachet gett _load_miniont LookupErrort copyt deepcopyt itemst
isinstancet listt tuplet _minion_lookupt logt warningt debug( t tgtt tgt_typet kwargsR t _rest retR t roster_ordert minion_idt miniont
minion_rest paramt ordert keyt kres( ( s5 /usr/lib/python2.7/site-packages/salt/roster/cache.pyt targetsq s:
c C@ s" t j j j | t � \ } } } | | k rI t j d | | � t � n | sh t j d | � i } n | s� t j d | � i } n i t g | j
d g � D] } t j | � ^ q� � d 6t g | j
d g � D] } t j
| � ^ q� � d 6} | j d j | � d � } | | | | f S(
Nu Asked for minion %s, got %su No grain data for minion id %su No pillar data for minion id %su ipv4i u ipv6i u minions/{0}u mine( R R R t get_minion_dataR R t errorR R t sortedR
R t IPv4Addresst IPv6Addresst fetcht format( R R t data_miniont grainst pillart addrt addrst mine( ( s5 /usr/lib/python2.7/site-packages/salt/roster/cache.pyR � s ! 58c C@ sj t | t j � r | g } n g } x? | D]7 } t j j j | | d � } | r+ | j | � q+ q+ W| S( N( R R t string_typesR R t datat traverse_dict_and_listt Nonet append( t reft lookupt rest data_keyR6 ( ( s5 /usr/lib/python2.7/site-packages/salt/roster/cache.pyt _data_lookup� s
c C@ s | \ } } } } | d k r"