File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/pydsl.cpython-310.pyc
Back
o ;j�6 � @ s� d Z ddlmZ ddlmZ ddlmZ ed� � �Z G dd� de�ZG dd � d e �Zd aG dd� d�ZG d d� d�ZG dd� d�Zdd� ZG dd� d�Zd S )a� :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!') � ��OrderedDict)�uuid4)� HighStatez_listen require watch prereq use listen_in require_in watch_in prereq_in use_in onchanges onfailc @ s e Zd ZdS )� PyDslErrorN)�__name__� __module__�__qualname__� r r �D/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/pydsl.pyr a s r c @ s e Zd Zdd� ZdS )�Optionsc C s | � |�S �N)�get)�self�namer r r �__getattr__f � zOptions.__getattr__N)r r r r r r r r r e s r Nc @ sn e Zd Zdd� Zedd� �Zedd� �Zdd� Zd d � Zdd� Z ddd�Z dd� Zdd� Zdd� Z dd� Zd S )�Slsc C sR || _ || _g | _t�� j| _g | _g | _t � | _ g | _|| _t�� s't d��d S )Nz+PyDSL only works with a running high state!)r �saltenv�includesr � get_activeZbuilding_highstate�included_highstate�extends�declsr �options�funcs�rendered_slsr )r �slsr r r r r �__init__n s �zSls.__init__c C � t �� jS r )r r Z_pydsl_all_decls��clsr r r � get_all_decls| � zSls.get_all_declsc C r r )r r Z_pydsl_render_stackr r r r �get_render_stack� r# zSls.get_render_stackc K � | j �|� d S r )r �update)r r r r r �set� � zSls.setc O s\ d|v r |� d� |�d| j�}|�dd�r%|D ] }| j�||f� qd S t�� }td u r4|�|� � �a| j }g }|D ]b}|� d|� �} | | jvro| j�|� |� ||| jt�\} }|�|| |� |rjtd�|���|�|� d|� �}||vr~|�d � q;|| d D ]} t| t�r�tt| ��d kr�|�| d � nq�q;|s�d S t|�d kr�|d S |S )N�envr ZdelayedF�:� �_slsmod_� stateconf�slsmod� r )�popr r r �appendr r �SLS_MATCHESZtop_matchesZget_topr r �addZrender_state�merge_included_statesr �joinZclean_duplicate_extends� isinstance�dict�next�iter�len)r Z sls_names�kwsr ZinclZ HIGHSTATE� highstateZslsmodsr Zr_envZhistates�errors�state_id�argr r r �include� sH � � �zSls.includec G s| | j js| �� rtd��|D ]-}|jj}| j�| �� � |�� t | j�}t| j�D ]}|d8 }|j |kr:| j|= nq)qd S )Nz7Cannot extend() after the ordered option was turned on!r/ )r �ordered� last_funcr �mod� _state_idr r1 r"