File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/container_resource.cpython-310.pyc
Back
o ;j�3 � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZ ddl Z ddlZ ddlm Z mZ e�e�ZdZdd� Zdd� Zd d � Zdd� Ze ddd��Ze ddd��ZdS )aa Common resources for LXC and systemd-nspawn containers .. versionadded:: 2015.8.0 These functions are not designed to be called directly, but instead from the :mod:`lxc <salt.modules.lxc>`, :mod:`nspawn <salt.modules.nspawn>`, and :mod:`docker <salt.modules.docker>` execution modules. They provide for common logic to be re-used for common actions. � N)�CommandExecutionError�SaltInvocationErrorzJPATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/bin:/usr/local/bin:/usr/local/sbinc s t �� �� fdd��}|S )z; Decorator for common function argument validation c s� |� d�}|� d�}dddd�}||vr!td�|d�t|�����||| vr3td �d�|| ����|d krBtjj�d �sBtd��� | i tjj j di |����S ) N�container_type�exec_driver)� lxc-attach�nsenter�docker-exec)r )r )Zdocker�lxcZnspawnz0Invalid container type '{}'. Valid types are: {}�, z7Invalid command execution driver. Valid drivers are: {}r zmThe 'lxc-attach' execution driver has been chosen, but lxc-attach is not available. LXC may not be installed.� )�getr �format�join�sorted�salt�utils�path�which�argsZclean_kwargs)r �kwargsr r Zvalid_driver��wrappedr �S/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/container_resource.py�wrapper# s. ������z_validate.<locals>.wrapper)� functools�wraps)r r r r r � _validate s r c C s d| � d�S )zE Return the nsenter command to attach to the named container �nsenter --target z --mount --uts --ipc --net --pidr )�pidr r r �_nsenterB s r c C sB || dt �|�� �dd�}z |d �� d W S ty Y dS w )z< Get the sha256 checksum of a file from a container z sha256sum T)�ignore_retcode�stdoutr N)�shlex�quote�split� IndexError)�namer Zrun_func�retr r r �_get_sha256I s �r( c C sR z| � d�rtd | �}|std| � ���|W S W | S ty( td| � ���w )z� Wrapper for cp.cache_file which raises an error if the file was unable to be cached. CLI Example: .. code-block:: bash salt myminion container_resource.cache_file salt://foo/bar/baz.txt zsalt://z cp.cache_filezUnable to cache zInvalid source file )� startswith�__salt__r �AttributeErrorr )�sourceZ cached_sourcer r r � cache_fileU s ���r- FT�debugc C sN d} |du r d}n|| vrt d�d�| ����d}|du s"t|t�r%g }n!t|ttf�sDz|�d�}W n tyC t � d� g }Y nw |}|d kr�d }| rY|dt�| �� d�7 }|d urm|d7 }d|vrm|dt � d�7 }|d�dd� |D ��7 }|dt�| �� d|� �7 }ns|dkr�t|� d� | �}d|� d�}|d ur�|d7 }d|vr�|t � d�7 }|d�dd� |D ��7 }|d|� �7 }n9|dkr�d}|r�|d7 }|| � d�7 }|d ur�|d7 }d|vr�|t � d�7 }|d�dd� |D ��7 }|d|� �7 }|�s t| ||||| d�}|S d \}}tjjj|||d!k�rd!nd"||d d d#d#d$� }z|zI|j�r_z%|�� \}}|�r9||7 }|�rJ|du �rF||7 }n||7 }t�d%� W n t�yZ Y nw |j�s+|du �rf|n|jd&||d'�}W n$ tjjj�y� t�� }t �|� |du �r�|nd(d&||d'�}Y nw W |�� |S W |�� |S |�� w ))aS Common logic for running shell commands in containers path path to the container parent (for LXC only) default: /var/lib/lxc (system default) CLI Example: .. code-block:: bash salt myminion container_resource.run mycontainer 'ps aux' container_type=docker exec_driver=nsenter output=stdout )r! �stderr�retcode�allN�cmd.runz/'output' param must be one of the following: {}r zcmd.run_all�,z Invalid keep_env value, ignoringr zlxc-attach z-P � Tz--clear-env �PATH� --set-var c S s2 g | ]}|t jv rd |� dt�t j| �� ��qS )r6 �=��os�environr"