HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/__pycache__/ssh_sample.cpython-310.pyc
o

�N�gE�@s�dZddlZddlZddlZddlmZdgZe�e	�Z
dd�Zdd�Zd	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdS)%a
    This is a simple proxy-minion designed to connect to and communicate with
    a server that exposes functionality via SSH.
    This can be used as an option when the device does not provide
    an api over HTTP and doesn't have the python stack to run a minion.
�N)�TerminalExceptionZ
ssh_samplecCst�d�dS)z6
    Only return if all the modules are available
    z(ssh_sample proxy __virtual__() called...T)�log�info�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/ssh_sample.py�__virtual__s
rc
Cs�z(tjjjtddtddtddd�td<td�d�\}}dtd	<Wd
Sty@}zt�	|�WYd
}~dSd
}~ww)zH
    Required.
    Can be used to initialize the server connection.
    �proxy�host�username�password)r	r
r�server�helpT�initializedNF)
�salt�utilsZ	vt_helperZ
SSHConnectionZ__opts__�__context__�sendlinerr�error)�opts�out�err�errr�inits



�
��rcCst�dd�S)z�
    Since grains are loaded in many different places and some of those
    places occur before the proxy can be initialized, return whether
    our init() function has been called
    rF)r�getrrrrr2srcCs6t�di�sd}td�|�\}}t|�td<tdS)z0
    Get the grains from the proxied device
    �grains_cacherr)rrr�parse��cmdrrrrr�grains;s
rcCsdtd<t�S)z4
    Refresh the grains from the proxied device
    Nr)rrrrrr�grains_refreshLsrcCsddiS)z)
    Method called by grains module.
    �detailszaThis key is here because a function in grains/ssh_sample.py called fns() here in the proxymodule.rrrrr�fnsTs�r!c
CsJztd�d�\}}WdSty$}zt�|�WYd}~dSd}~ww)zJ
    Required.
    Ping the device on the other end of the connection
    rr
TNF)rrrrr)rrrrrr�ping`s
��r"cCstd��dS)z
    Disconnect
    rN)rZclose_connection)rrrr�shutdownmsr#cCsRg}d}|�d�D]}d|vrd}|r|�|�d|vrd}q	tjj�d�|��S)zw
    Extract json from out.

    Parameter
        out: Type string. The data returned by the
        ssh command.
    F�
�{T�})�split�appendrr�json�loads�join)rZjsonretZin_jsonZln_rrrrts
�rcCstd�d�\}}t|�S)z�
    List "packages" by executing a command via ssh
    This function is called in response to the salt command

    .. code-block:: bash

        salt target_minion pkg.list_pkgs

    rz	pkg_list
�rrr)rrrrr�package_list�sr-cKs>d|}|�dd�r|d|d7}td�|�\}}t|�S)z/
    Install a "package" on the ssh server
    zpkg_install �versionF� r)rrrr)�name�kwargsrrrrrr�package_install�s
r2cC�"d|}td�|�\}}t|�S)z.
    Remove a "package" on the ssh server
    zpkg_remove rr,�r0rrrrrr�package_remove�sr5cCsd}td�|�\}}t|�S)�M
    Start a "service" on the ssh server

    .. versionadded:: 2015.8.2
    Zpsrr,rrrr�service_list�sr7cCr3)r6zstart rr,r4rrr�
service_start��r8cCr3)zL
    Stop a "service" on the ssh server

    .. versionadded:: 2015.8.2
    zstop rr,r4rrr�service_stop�r9r:cCr3)zO
    Restart a "service" on the ssh server

    .. versionadded:: 2015.8.2
    zrestart rr,r4rrr�service_restart�r9r;)�__doc__�loggingZsalt.utils.jsonrZsalt.utils.vt_helperZ
salt.utils.vtrZ__proxyenabled__�	getLogger�__file__rrrrrrr!r"r#rr-r2r5r7r8r:r;rrrr�<module>s.