File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/__pycache__/runner.cpython-310.pyc
o
�N�g�0 � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddl Zddl
ZddlmZ ddl
mZ ddlmZ e�e�ZG dd� dejej�ZG dd � d e�ZdS )
z#
Execute salt convenience routines
� N)�mixins)�display_output)�
verify_func sZ e Zd ZdZdZdZedd� �Zdd� Zdd � Z ddd
�Z
d� fdd� Z� ZS )�RunnerClienta7
The interface used by the :command:`salt-run` CLI tool on the Salt Master
It executes :ref:`runner modules <all-salt.runners>` which run on the Salt
Master.
Importing and using ``RunnerClient`` must be done on the same machine as
the Salt Master and it must be done using the same user that the Salt
Master is running as.
Salt's :conf_master:`external_auth` can be used to authenticate calls. The
eauth user must be authorized to execute runner modules: (``@runner``).
Only the :py:meth:`master_call` below supports eauth.
�runner�runc C sz t | d�s:t | d�stj�| j�| _ztjj| j| j| jd�| _W | jS ty9 tjj| j| jd�| _Y | jS w | jS )N�
_functions�utils)r �context�r
) �hasattr�salt�loaderr �optsr r
r �AttributeError)�self� r �?/opt/saltstack/salt/lib/python3.10/site-packages/salt/runner.py� functions) s
���zRunnerClient.functionsc s� � � d�}t| j|� � fdd�dD �}tjjj� � dg �dd�\}}|�� � di �� |�� � g }|�|� |� t
dd d
i|��� tjj| j| |d
d�\}}t
d|||d�d
�|��S )a�
Format the low data for RunnerClient()'s master_call() function
This also normalizes the following low data formats to a single, common
low data structure.
Old-style low: ``{'fun': 'jobs.lookup_jid', 'jid': '1234'}``
New-style: ``{'fun': 'jobs.lookup_jid', 'kwarg': {'jid': '1234'}}``
CLI-style: ``{'fun': 'jobs.lookup_jid', 'arg': ['jid="1234"']}``
�func s i | ]}|� v r|� � |��qS r )�pop)�.0�i��lowr r �
<dictcomp>H s
�
z.RunnerClient._reformat_low.<locals>.<dictcomp>)�username�password�eauth�token�client�user�key�argF)Z condition�kwargZ __kwarg__T)Zignore_invalid)r$ r# )r r$ Nr )
r r r r
r �args�parse_input�update�extend�append�dict�minion�load_args_and_kwargs) r r r Zeauth_credsZ_argZ_kwargZmungedr# r$ r r r �
_reformat_low: s
�
�zRunnerClient._reformat_lowc C s | � |�}tj�| |�S )a�
Execute a runner function asynchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:: python
runner.cmd_async({
'fun': 'jobs.list_jobs',
'username': 'saltdev',
'password': 'saltdev',
'eauth': 'pam',
})
)r- r �AsyncClientMixin� cmd_async)r r �reformatted_lowr r r r/ l s
zRunnerClient.cmd_asyncNFc C s | � |�}tj�| |||�S )a�
Execute a runner function synchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:: python
runner.cmd_sync({
'fun': 'jobs.list_jobs',
'username': 'saltdev',
'password': 'saltdev',
'eauth': 'pam',
})
)r- r �SyncClientMixin�cmd_sync)r r �timeout�full_returnr0 r r r r2 � s
�zRunnerClient.cmd_syncTc s t � �||||||�S )a�
Execute a function
.. code-block:: python
>>> opts = salt.config.master_config('/etc/salt/master')
>>> runner = salt.runner.RunnerClient(opts)
>>> runner.cmd('jobs.list_jobs', [])
{
'20131219215650131543': {
'Arguments': [300],
'Function': 'test.sleep',
'StartTime': '2013, Dec 19 21:56:50.131543',
'Target': '*',
'Target-type': 'glob',
'User': 'saltdev'
},
'20131219215921857715': {
'Arguments': [300],
'Function': 'test.sleep',
'StartTime': '2013, Dec 19 21:59:21.857715',
'Target': '*',
'Target-type': 'glob',
'User': 'saltdev'
},
}
)�super�cmd)r r r# Zpub_datar$ Zprint_eventr4 �� __class__r r r6 � s %zRunnerClient.cmd)NF)NNNTF)
�__name__�
__module__�__qualname__�__doc__r Z
tag_prefix�propertyr r- r/ r2 r6 �
__classcell__r r r7 r r s
2
�r c s8 e Zd ZdZd
� fdd� Z� fdd�Zddd �Z� ZS )�Runnerz+
Execute the salt runner interface
Nc s8 t � j||d� tjj|| j|d�| _tj�|�| _d S )Nr )r5 �__init__r
r Z returnersr Z
outputters)r r r
r7 r r r@ � s zRunner.__init__c sL | j �dd�}t� �|�}t|�D ]}t|� d�d| j � t|| � qdS )z.
Print out the documentation!
r N�:�text)r �getr5 �get_docs�sortedr �print)r r# Zdocsr r7 r r �
print_docs� s �zRunner.print_docsFc C s� ddl }i }| j�dd�r| �� dS d| jd i}�za| j| j�d�d�}|d | _|jjj| jd | j�d g �d
�}t | j
|d � |j�| j
|d |�\}}||d<