%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/pydsl.pyc

�
���^c@@sdZddlmZmZmZddlmZddlm	Z	ddl
mZddlm
Z
edj��Zdefd	��YZd
efd��YZdadefd
��YZdefd��YZdefd��YZd�Zdefd��YZdS(u�
:maintainer: Jack Kuan <kjkuan@gmail.com>
:maturity: new
:platform: all

A Python DSL for generating Salt's highstate data structure.

This module is intended to be used with the `pydsl` renderer,
but can also be used on its own. Here's what you can do with
Salt PyDSL::

    # Example translated from the online salt tutorial

    apache = state('apache')
    apache.pkg.installed()
    apache.service.running() \
                  .watch(pkg='apache',
                         file='/etc/httpd/conf/httpd.conf',
                         user='apache')

    if __grains__['os'] == 'RedHat':
        apache.pkg.installed(name='httpd')
        apache.service.running(name='httpd')

    apache.group.present(gid=87).require(apache.pkg)
    apache.user.present(uid=87, gid=87,
                        home='/var/www/html',
                        shell='/bin/nologin') \
               .require(apache.group)

    state('/etc/httpd/conf/httpd.conf').file.managed(
        source='salt://apache/httpd.conf',
        user='root',
        group='root',
        mode=644)


Example with ``include`` and ``extend``, translated from
the online salt tutorial::

    include('http', 'ssh')
    extend(
        state('apache').file(
            name='/etc/httpd/conf/httpd.conf',
            source='salt://http/httpd2.conf'
        ),
        state('ssh-server').service.watch(file='/etc/ssh/banner')
    )
    state('/etc/ssh/banner').file.managed(source='salt://ssh/banner')


Example of a ``cmd`` state calling a python function::

    def hello(s):
        s = "hello world, %s" % s
        return dict(result=True, changes=dict(changed=True, output=s))

    state('hello').cmd.call(hello, 'pydsl!')

i(tabsolute_importtprint_functiontunicode_literals(tuuid4(tOrderedDict(t	HighState(tsixu_listen require watch prereq use listen_in require_in watch_in prereq_in use_in onchanges onfailt
PyDslErrorcB@seZRS((t__name__t
__module__(((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRestOptionscB@seZd�ZRS(cC@s
|j|�S(N(tget(tselftname((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt__getattr__js(RR	R(((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyR
istSlscB@szeZd�Zed��Zed��Zd�Zd�Zd�Zdd�Z
d�Zd�Zd	�Z
d
�ZRS(cC@s|||_||_g|_tj�j|_g|_g|_t	�|_
g|_||_tj�sxt
d��ndS(Nu+PyDSL only works with a running high state!(R
tsaltenvtincludesRt
get_activetbuilding_highstatetincluded_highstatetextendstdeclsR
toptionstfuncstrendered_slsR(RtslsRR((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt__init__ss							cC@s
tj�jS(N(RRt_pydsl_all_decls(tcls((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt
get_all_decls�scC@s
tj�jS(N(RRt_pydsl_render_stack(R((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytget_render_stack�scK@s|jj|�dS(N(Rtupdate(RR((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytset�scO@s�d|kr|jd�n|jd|j�}|jdt�rnx$|D]}|jj||f�qJWdStj�}tdkr�|j
|j��an|j}g}x!|D]}dj
||�}	|	|jkrM|jj|�|j|||jt�\}
}|j||
|�|r=tdj|���n|j|�ndj
|�}||krx|jd�q�xR||dD]B}
t|
t�r�tt|
��dkr�|j|
d�Pq�q�Wq�W|s�dSt|�d	kr�|d
S|S(Nuenvusaltenvudelayedu{0}:{1}u
u_slsmod_{0}u	stateconfuslsmodii(tpopRRtFalseRtappendRRtSLS_MATCHEStNonettop_matchestget_topRtformatRtaddtrender_statetmerge_included_statesRtjointclean_duplicate_extendst
isinstancetdicttnexttitertlen(Rt	sls_namestkwsRtinclt	HIGHSTATEt	highstatetslsmodsRtr_envthistatesterrorststate_idtarg((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytinclude�s@
	
'cG@s�|jjs|j�r'td��nx�|D]�}|jj}|jj|j�j	|��t
|j�}x>t|j�D]-}|d8}|j
|kr~|j|=Pq~q~Wq.WdS(Nu7Cannot extend() after the ordered option was turned on!i(Rtorderedt	last_funcRtmodt	_state_idRR%RR#R4Rtreversedt_id(Rtstate_funcstfR>titdecl((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytextend�s


cC@sp|sdjt��}ny|j�|SWn<tk
rkt|�|j�|<}|jj|�|SXdS(Nu.{0}(R*t_uuidRtKeyErrortStateDeclarationRR%(Rtidts((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytstate�s
cC@s|jr|jdSdS(Ni����(RR'(R((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRB�scC@s|jj|�dS(N(RR%(Rt	statefunc((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt
track_func�sc	C@s;d|j}|j|�jjd|�|j�|=t�}|jrzg|jD]}i|d|d6^qR|d<n|jr�t�|d<}x-|jD]}|jdd�||j	<q�Wnx$|j
D]}|j�||j	<q�W|jr7g}tj
�j||j|�|r7tdj|���q7n|S(	Nu_slsmod_tslsmodiiuincludeuextendtcontextu
(R
RQt	stateconfR"RRRRt_reprRFRRRRR-RR.(	RRTt	slsmod_idR9ttRKtextRJR=((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytto_highstate�s&

		2	 	c
C@sxtj|�D]�\}}|j|�}x�tj|�D]�\}}d|krn|jdd�\}}n#td�|D��}|j|�t||�}i}	xE|D]=}
t|
t�r�ttj|
��\}}||	|<q�q�W|||	�q;WqWdS(Nu.ics@s'|]}t|tj�r|VqdS(N(R0Rtstring_types(t.0tx((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pys	<genexpr>�s(	Rt	iteritemsRQtrsplitR2tremovetgetattrR0R1(
RR9tsidRJRPtmodnametargstfuncnameRCt
named_argsR^tktv((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytload_highstate�s

N(RR	RtclassmethodRR R"R@RKR'RQRBRSR[Rj(((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRqs			-				RNcB@sJeZd�Zd�ZeZd�Zd�Zdd�Ze	d�Z
RS(cC@s||_g|_dS(N(RFt_mods(RRO((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRs	cC@sMx$|jD]}|j|kr
|Sq
Wt||j�}|jj|�|S(N(Rlt_nametStateModuleRFR%(RR
tm((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRscC@s|jS(N(RF(R((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt__str__scC@s
t|j�S(N(R3Rl(R((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt__iter__sc@st�fd�|D��S(Nc3@s|]}|j��VqdS(N(RW(R]Ro(RU(s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pys	<genexpr>!s(R(RRU((RUs4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRW sc	C@s�tj�d}|j|j�kr|j�}|r�|jdj|k	r�tdj|jdj	|j|j
|j
j���n|j�j|j�|j
j|�|jdjj�x?|jD]1}y|jj|j�Wq�tk
r�q�Xq�Wntj�jjdi|j�|j6�}t|t�s\tdjdj|����nttj|�dd��}|r�xU|D]J\}}|d	s�ddl}td
j|ji||6����q�q�Wn|S(Ni����uZCannot run state({0}: {1}) that is required by a runtime state({2}: {3}), at compile time.iu
state.highu.An error occurred while running highstate: {0}u; tkeycS@s|ddS(Niu__run_num__((RY((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt<lambda>Dsuresultu/Failed executing low state at compile time:
{0}(RR RFRRBRlt_funcRR*RmRCRDR#RRat_remove_auto_requireRt
ValueErrorRRRQt	functionsRWR0R1R.tsortedRR_tpprinttpformat(	RtcheckRRBRotresultRhRiRy((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt__call__#s>

&N(RR	RRt__getitem__RpRqR'RWtTrueR}(((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRN
s				RncB@s8eZd�Zd�Zd�Zd�Zdd�ZRS(cC@s||_||_d|_dS(N(RDRmR'Rt(RR
tparent_decl((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRRs		cC@s�|jr~||jjkr"|jS|tkrk|jjrXtdj||j���n||j_|jSt|j|�Sn|tkr�td|�|_}t||�St||�|_}|SdS(NuAMultiple state functions({0}) not allowed in a state module({1})!(	RtR
t
REQUISITESRR*RmRbt
StateFunctionR'(RR
RH((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRWs 	
cO@st||�j||�S(N(Rbt	configure(Rt_fnameReR6((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyR}lscC@s|jS(N(Rm(R((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRposcC@s|j|jj|�fS(N(RmRtRW(RRU((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRWrsN(RR	RRR}RpR'RW(((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRnPs
				c@s�fd�}|S(Nc@sRx!|D]}|j�|d�qWx'tj|�D]}|j�|�q4W|S(N(t	referenceR'RR_(RReR6RCtmod_ref(RY(s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pytreqws

((RYR�((RYs4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt_generate_requsite_methodvsR�cB@sqeZd�Zd�Zd�Zdd�Zd�Zd�Ze	�Z
xeD]Ze
e�e
e<qOW[
[RS(cC@s�||_||_g|_d|_tj�d}|jjr�|j	�}|r{|j
|j�t|j�d|_n|j|�ndS(Ni����i(
RCR
ReR't
require_indexRR RRARBtrequireR4RS(RR
t
parent_modRtlast_f((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyR�s				cC@s,|jdk	r(|j|j=d|_ndS(N(R�R'Re(R((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRu�s
cO@s|j||�|S(N(R�(RReR6((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyR}�scC@sb|jr4|dkr4tdj|jj���n|jrQ|dkrQ|jS|jg|jS(Nuextendu+No state function specified for module: {0}(R
RR*RCRmRe(RRU((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyRW�s	c	C@s�t|�}|r�|d}|jjdkr|jd
krt|�r|j|d<td|d|dd|�}|d3ntd	|d�|d<nx1tj|�D] \}}|j	i||6�q�W|j
j|�|S(Niucmducallu	wait_calltfuncReiR6R
(ucallu	wait_call(tlistRCRmR
tcallableRR1RR_R%ReRK(RReR6tfirstRhRi((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyR��s


cC@syt|t�r|j}n'|o$|sBtdj||���n|jjiitj|�tj|�6g|6�dS(Nu3Invalid a requisite reference declaration! {0}: {1}(	R0RnRDRR*ReR%Rt	text_type(Rtreq_typeRCtref((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyR��sN(RR	RRuR}R'RWR�R�tlocalstnsR�R�R�(((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyR��s						
N(t__doc__t
__future__RRRtuuidRRLtsalt.utils.odictRt
salt.stateRtsalt.extRR"tsplitR�t	ExceptionRR1R
R'R&tobjectRRNRnR�R�(((s4/usr/lib/python2.7/site-packages/salt/utils/pydsl.pyt<module>=s�F&	

Zerion Mini Shell 1.0