%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/beacons/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/beacons/avahi_announce.pyc

�
���^c@@s|dZddlmZmZddlZddlZddlZddlm	Z	yddl
Z
eZWne
k
reZnXy�ddlZddlmZej�Zejeje
je
j�e
j�Zejeje
jej��e
j�ZeZWn3e
efk
r"eZnek
r8eZnXeje�Z dZ!ia"d�Z#d�Z$d	�Z%d
�Z&dS(u�
Beacon to announce via avahi (zeroconf)

.. versionadded:: 2016.11.0

Dependencies
============

- python-avahi
- dbus-python

i(tabsolute_importtunicode_literalsN(tmap(t
DBusExceptionuavahi_announcecC@s6tr#trtStdjt�fStdjt�fS(NuIThe {0} beacon cannot be loaded. The 'python-dbus' dependency is missing.uJThe {0} beacon cannot be loaded. The 'python-avahi' dependency is missing.(tHAS_PYAVAHItHAS_DBUSt__virtualname__tFalsetformat(((s?/usr/lib/python2.7/site-packages/salt/beacons/avahi_announce.pyt__virtual__2s	
	c@sei�tt�j|��t|t�s5tdfSt�fd�dD��s[tdfStdfS(	u+
    Validate the beacon configuration
    u7Configuration for avahi_announce beacon must be a list.c3@s|]}|�kVqdS(N((t.0tx(t_config(s?/usr/lib/python2.7/site-packages/salt/beacons/avahi_announce.pys	<genexpr>GsuservicetypeuportutxtuUConfiguration for avahi_announce beacon must contain servicetype, port and txt items.uValid beacon configuration.(uservicetypeuportutxt(tlistRtupdatet
isinstanceRtalltTrue(tconfig((Rs?/usr/lib/python2.7/site-packages/salt/beacons/avahi_announce.pytvalidate<s


cC@s:t|�t|�ddkr6|dt|� dS|S(u�
    Enforces the TXT record maximum length of 255 characters.
    TXT record length includes key, value, and '='.

    :param str key: Key of the TXT record
    :param str value: Value of the TXT record

    :rtype: str
    :return: The value of the TXT record. It may be truncated if it exceeds
             the maximum permitted length. In case of truncation, '...' is
             appended to indicate that the entire value is not present.
    ii�i�u...(tlen(tkeytvalue((s?/usr/lib/python2.7/site-packages/salt/beacons/avahi_announce.pyt_enforce_txt_record_maxlenOs c
C@srg}i}i}i}tt|j|��d|krG|d}n-td}trttd|krt||d<ntr	|jdt�r	tjdg�tjdg�kr�tjdg�|d<ntjdg�tjdg�kr	tjdg�|d<q	nxx|dD]l}dtjj	j
|�}|d|jd�rN|d|d	}d}	|j
d
�}
|
dkr�|ddkr�t||
d
d!�}	||
 }ntj|d�}t|t�r�|	dk	r�||	}q�dj|�}nt||�||<tritj|d�tj|d�kri||||<qint||d|�||<ts||||<qqW|rGts=||d<|d|d<|d|d<tjdg�|d<tjdg�|d<tjtjtjtjd�||dddtj|d�tj|��	tj�n�|jdt�s[d|kr�tj�|jdd�}|dkr�tj|�ntjtjtjtjd�||dddtj|d�tj|��	tj�n;tjtjtjtjd�||ddtj|��|j idd6|d6�n|jdt�rhtj!�anta|S(u	
    Broadcast values via zeroconf

    If the announced values are static, it is advised to set run_once: True
    (do not poll) on the beacon configuration.

    The following are required configuration settings:

    - ``servicetype`` - The service type to announce
    - ``port`` - The port of the service to announce
    - ``txt`` - The TXT record of the service being announced as a dict. Grains
      can be used to define TXT values using one of following two formats:

      - ``grains.<grain_name>``
      - ``grains.<grain_name>[i]`` where i is an integer representing the
        index of the grain to use. If the grain is not a list, the index is
        ignored.

    The following are optional configuration settings:

    - ``servicename`` - Set the name of the service. Will use the hostname from
      the minion's ``host`` grain if this value is not set.
    - ``reset_on_change`` - If ``True`` and there is a change in TXT records
      detected, it will stop announcing the service and then restart announcing
      the service. This interruption in service announcement may be desirable
      if the client relies on changes in the browse records to update its cache
      of TXT records. Defaults to ``False``.
    - ``reset_wait`` - The number of seconds to wait after announcement stops
      announcing and before it restarts announcing in the case where there is a
      change in TXT records detected and ``reset_on_change`` is ``True``.
      Defaults to ``0``.
    - ``copy_grains`` - If ``True``, Salt will copy the grains passed into the
      beacon when it backs them up to check for changes on the next iteration.
      Normally, instead of copy, it would use straight value assignment. This
      will allow detection of changes to grains where the grains are modified
      in-place instead of completely replaced.  In-place grains changes are not
      currently done in the main Salt code but may be done due to a custom
      plug-in. Defaults to ``False``.

    Example Config

    .. code-block:: yaml

       beacons:
         avahi_announce:
           - run_once: True
           - servicetype: _demo._tcp
           - port: 1234
           - txt:
               ProdName: grains.productname
               SerialNo: grains.serialnumber
               Comments: 'this is a test'
    uservicenameuhostureset_on_changeuipv4uipv6utxtutxt.ugrains.iu[i����u]iuu,uservicetypeuportiu
reset_waituresultutaguchangesucopy_grainsN("R
RRt
__grains__tLAST_GRAINStgetRtsalttutilststringutilst
to_unicodet
startswithtNonetfindtintRtjoinRtGROUPt
AddServicetavahit	IF_UNSPECtPROTO_UNSPECtdbustUInt32tUInt16tdict_to_txt_arraytCommittResetttimetsleeptUpdateServiceTxttappendtcopy(
RtrettchangesttxtRtservicenametitemtchanges_keytgraintgrain_indextsquare_brackettgrain_valuet
reset_wait((s?/usr/lib/python2.7/site-packages/salt/beacons/avahi_announce.pytbeaconcs~6


$$

*
 

 

('t__doc__t
__future__RRtloggingR/tsalt.utils.stringutilsRtsalt.ext.six.movesRR&RRtImportErrorRR)Rt	SystemBustBUSt	Interfacet
get_objectt	DBUS_NAMEtDBUS_PATH_SERVERtDBUS_INTERFACE_SERVERtSERVERt
EntryGroupNewtDBUS_INTERFACE_ENTRY_GROUPR$Rt	NameErrort	getLoggert__name__tlogRRR	RRR?(((s?/usr/lib/python2.7/site-packages/salt/beacons/avahi_announce.pyt<module>
s<



	

	
		

Zerion Mini Shell 1.0