%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/plugins/connection/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/plugins/connection/__pycache__/__init__.cpython-39.pyc

a

�)g<@�@s�ddlmZmZmZeZddlZddlZddlZddl	Z
ddlmZddl
mZddlmZddlmZmZddlmZddlmZdd	lmZmZdd
lmZe�ZddgZd
Z dd�Z!Gdd�de�Z"Gdd�de"�Z#dS)�)�absolute_import�division�print_functionN)�abstractmethod��wraps)�	constants)�to_bytes�to_text)�
AnsiblePlugin)�Display)�connection_loader�get_shell_plugin)�unfrackpath�ConnectionBase�ensure_connecticst���fdd��}|S)Ncs$|js|���|g|�Ri|��S�N)�
_connected�_connect)�self�args�kwargs��func��G/usr/lib/python3.9/site-packages/ansible/plugins/connection/__init__.py�wrapped szensure_connect.<locals>.wrappedr)rrrrrrscs�eZdZdZdZdZdZdZdZdZ	dZ
dZdZd$�fdd�	Z
dd	�Zed
d��Zedd
��Zedd��Zeedd���Zedd��Zeed%dd���Zeedd���Zeedd���Zedd��Zdd�Zdd�Zd d!�Zd"d#�Z�Z S)&rz>
    A base class for connections to contain common code.
    FT)�Ncs�tt|���t|d�s||_t|d�s.||_t|d�s>t|_t|d�sNd|_d|_	d|_
d|_d|_||_|js�|j
r~|j
n
t|dd�}t||jjd�|_d|_dS)N�
_play_context�
_new_stdin�_displayrFZ_shell_type)�
shell_type�
executable)�superr�__init__�hasattrrr�displayr rZsuccess_key�prompt�_socket_path�_shell�shell�getattrrr"�become)r�play_context�	new_stdinr*rrr!��	__class__rrr$>s$



zConnectionBase.__init__cCs
||_dSr)r,)r�pluginrrr�set_become_plugin]sz ConnectionBase.set_become_plugincCs|jS)zYRead-only property holding whether the connection to the remote host is active or closed.)r�rrrr�	connected`szConnectionBase.connectedcCs|jS)zJRead-only property holding the connection socket path for this remote host)r(r3rrr�socket_patheszConnectionBase.socket_pathcCsdd�t�|�D�S)z�
        Takes a string like '-o Foo=1 -o Bar="foo bar"' and returns a
        list ['-o', 'Foo=1', '-o', 'Bar=foo bar'] that can be added to
        the argument list. The list will not contain any empty elements.
        cSs g|]}|��rt|����qSr)�stripr
)�.0�xrrr�
<listcomp>r�z2ConnectionBase._split_ssh_args.<locals>.<listcomp>)�shlex�split)Z	argstringrrr�_split_ssh_argsjszConnectionBase._split_ssh_argscCsdS)z@String used to identify this Connection class from other classesNrr3rrr�	transporttszConnectionBase.transportcCsdS)z/Connect to the host we've been initialized withNrr3rrrrzszConnectionBase._connectcCsdS)atRun a command on the remote host.

        :arg cmd: byte string containing the command
        :kwarg in_data: If set, this data is passed to the command's stdin.
            This is used to implement pipelining.  Currently not all
            connection plugins implement pipelining.
        :kwarg sudoable: Tell the connection plugin if we're executing
            a command via a privilege escalation mechanism.  This may affect
            how the connection plugin returns data.  Note that not all
            connections can handle privilege escalation.
        :returns: a tuple of (return code, stdout, stderr)  The return code is
            an int while stdout and stderr are both byte strings.

        When a command is executed, it goes through multiple commands to get
        there.  It looks approximately like this::

            [LocalShell] ConnectionCommand [UsersLoginShell (*)] ANSIBLE_SHELL_EXECUTABLE [(BecomeCommand ANSIBLE_SHELL_EXECUTABLE)] Command
        :LocalShell: Is optional.  It is run locally to invoke the
            ``Connection Command``.  In most instances, the
            ``ConnectionCommand`` can be invoked directly instead.  The ssh
            connection plugin which can have values that need expanding
            locally specified via ssh_args is the sole known exception to
            this.  Shell metacharacters in the command itself should be
            processed on the remote machine, not on the local machine so no
            shell is needed on the local machine.  (Example, ``/bin/sh``)
        :ConnectionCommand: This is the command that connects us to the remote
            machine to run the rest of the command.  ``ansible_user``,
            ``ansible_ssh_host`` and so forth are fed to this piece of the
            command to connect to the correct host (Examples ``ssh``,
            ``chroot``)
        :UsersLoginShell: This shell may or may not be created depending on
            the ConnectionCommand used by the connection plugin.  This is the
            shell that the ``ansible_user`` has configured as their login
            shell.  In traditional UNIX parlance, this is the last field of
            a user's ``/etc/passwd`` entry   We do not specifically try to run
            the ``UsersLoginShell`` when we connect.  Instead it is implicit
            in the actions that the ``ConnectionCommand`` takes when it
            connects to a remote machine.  ``ansible_shell_type`` may be set
            to inform ansible of differences in how the ``UsersLoginShell``
            handles things like quoting if a shell has different semantics
            than the Bourne shell.
        :ANSIBLE_SHELL_EXECUTABLE: This is the shell set via the inventory var
            ``ansible_shell_executable`` or via
            ``constants.DEFAULT_EXECUTABLE`` if the inventory var is not set.
            We explicitly invoke this shell so that we have predictable
            quoting rules at this point.  ``ANSIBLE_SHELL_EXECUTABLE`` is only
            settable by the user because some sudo setups may only allow
            invoking a specific shell.  (For instance, ``/bin/bash`` may be
            allowed but ``/bin/sh``, our default, may not).  We invoke this
            twice, once after the ``ConnectionCommand`` and once after the
            ``BecomeCommand``.  After the ConnectionCommand, this is run by
            the ``UsersLoginShell``.  After the ``BecomeCommand`` we specify
            that the ``ANSIBLE_SHELL_EXECUTABLE`` is being invoked directly.
        :BecomeComand ANSIBLE_SHELL_EXECUTABLE: Is the command that performs
            privilege escalation.  Setting this up is performed by the action
            plugin prior to running ``exec_command``. So we just get passed
            :param:`cmd` which has the BecomeCommand already added.
            (Examples: sudo, su)  If we have a BecomeCommand then we will
            invoke a ANSIBLE_SHELL_EXECUTABLE shell inside of it so that we
            have a consistent view of quoting.
        :Command: Is the command we're actually trying to run remotely.
            (Examples: mkdir -p $HOME/.ansible, python $HOME/.ansible/tmp-script-file)
        Nr�r�cmdZin_dataZsudoablerrr�exec_command~sBzConnectionBase.exec_commandcCsdS)�$Transfer a file from local to remoteNr�rZin_pathZout_pathrrr�put_file�szConnectionBase.put_filecCsdS)zlFetch a file from remote to local; callers are expected to have pre-created the directory chain for out_pathNrrCrrr�
fetch_file�szConnectionBase.fetch_filecCsdS)zTerminate the connectionNrr3rrr�close�szConnectionBase.closecCsV|jj}tjdt��|f|jjd�t�|tj	�tjdt��|f|jjd�dS)Nz)CONNECTION: pid %d waiting for lock on %d��hostz&CONNECTION: pid %d acquired lock on %d)
r�connection_lockfdr&�vvvv�os�getpid�remote_addr�fcntl�lockfZLOCK_EX�r�frrr�connection_lock�szConnectionBase.connection_lockcCs8|jj}t�|tj�tjdt��|f|jj	d�dS)Nz&CONNECTION: pid %d released lock on %drG)
rrIrNrOZLOCK_UNr&rJrKrLrMrPrrr�connection_unlock�sz ConnectionBase.connection_unlockcCst�d�dS)Nz,Reset is not implemented for this connection)r&�warningr3rrr�reset�szConnectionBase.resetc
Cs�tjD]�}d}||vrqn�d|vsd|vr.qn�|dkr>|j}n�|dkrP|jj}nxtj�d|j|�}|rv|�|d�}nRd|vr�tj��D]>\}}||vr�zt	|j
|�}Wq�Wq�ty�Yq�Yq�0q�|durt�
d	�||��|||<qdS)
z�
        Adds 'magic' variables relating to connections to the variable dictionary provided.
        In case users need to access from the play, this is a legacy from runner.
        N�password�passwdZansible_connectionZansible_shell_type�
connectionrr,zSet connection var {0} to {1})�CZCOMMON_CONNECTION_VARSZ
_load_namer)ZconfigZget_plugin_options_from_var�
get_optionZMAGIC_VARIABLE_MAPPING�itemsr+r�AttributeErrorr&�debug�format)rZ	variablesZvarname�value�optionsZpropZvar_listrrr�update_vars�s0


zConnectionBase.update_vars)N)NT)!�__name__�
__module__�__qualname__�__doc__Zhas_pipeliningZhas_native_asyncZalways_pipeline_modulesZhas_ttyZ!module_implementation_preferencesZallow_executableZsupports_persistence�force_persistenceZdefault_userr$r2�propertyr4r5�staticmethodr=rr>rrrArDrErFrRrSrUra�
__classcell__rrr/rr(sL


	
B
cs�eZdZdZdZdZ�fdd�Zdd�Zddd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zd�fdd�	Zdd�Zdd�Z�ZS)�NetworkConnectionBasez5
    A base class for network-style connections.
    Tcsttt|�j||g|�Ri|��g|_d|_|jj|_t�	d|d�|_
|j
��i|_d|_
|�	d�|_|��dS)NF�localz	/dev/null)NNNZansible_playbook_pid)r#rjr$�	_messages�_conn_closedrZ
network_osZ_network_osr
�get�_local�set_options�_sub_pluginZ_cached_variables�_ansible_playbook_pid�_update_connection_state)rr-r.rrr/rrr$s 

zNetworkConnectionBase.__init__cCsnz|j|WStyh|�d�sP|j�d�}|rPt||d�}|durP|YStd|jj|f��Yn0dS)N�_�objz!'%s' object has no attribute '%s')	�__dict__�KeyError�
startswithrqrnr+r\r0rb)r�namer1�methodrrr�__getattr__#s
z!NetworkConnectionBase.__getattr__NcCs|j�|||�Sr)rorAr?rrrrA/sz"NetworkConnectionBase.exec_commandcCs|j�||f�dS)a�
        Adds a message to the queue of messages waiting to be pushed back to the controller process.

        :arg level: A string which can either be the name of a method in display, or 'log'. When
            the messages are returned to task_executor, a value of log will correspond to
            ``display.display(message, log_only=True)``, while another value will call ``display.[level](message)``
        N)rl�append)r�level�messagerrr�
queue_message2sz#NetworkConnectionBase.queue_messagecCs|jg}|_|Sr)rl)r�messagesrrr�pop_messages<sz"NetworkConnectionBase.pop_messagescCs|j�||�S)rB)rorDrCrrrrD@szNetworkConnectionBase.put_filecCs|j�||�S)z!Fetch a file from remote to local)rorErCrrrrEDsz NetworkConnectionBase.fetch_filecCs0|jr |�dd|j�|��|�dd�dS)z&
        Reset the connection
        rJz2resetting persistent connection for socket_path %sz!reset call on connection instanceN)r(rrFr3rrrrUHszNetworkConnectionBase.resetcCsd|_|jrd|_dS)NTF)rmrr3rrrrFQszNetworkConnectionBase.closecs�tt|�j|||d�|�d�rZd|jj}ttd�}|durJ|d|7}|�dd|�|j	�
d�r�|j	�
d	�d
kr�z|j	dj|||d�Wnty�Yn0dS)N)�	task_keys�var_options�direct�persistent_log_messageszOPersistent connection logging is enabled for %s. This will log ALL interactionsZDEFAULT_LOG_PATHz to %srTzP%s and WILL NOT redact sensitive configuration like passwords. USE WITH CAUTION!ru�typeZexternal)r#rjrprZrrMr+rYrrqrnr\)rr�r�r�rTZlogpathr/rrrpVs

z!NetworkConnectionBase.set_optionscCsjtjddd�}|�|jj|jj|jj|jj|j�}t	t
j�}t	|t|d��}t
j�|�rfd|_||_dS)ac
        Reconstruct the connection socket_path and check if it exists

        If the socket path exists then the connection is active and set
        both the _socket_path value to the path and the _connected value
        to True.  If the socket path doesn't exist, leave the socket path
        value to None and the _connected value to False
        �sshT)Z
class_only)Z	directoryN)r
rnZ_create_control_pathrrM�portZremote_userrXrrrrYZPERSISTENT_CONTROL_PATH_DIR�dictrK�path�existsrr()rr�Zcontrol_pathZtmp_pathr5rrrrses	�
z.NetworkConnectionBase._update_connection_statecCs|�d�r|�d|�dS)Nr��log)rZr)rr~rrr�
_log_messages|s
z#NetworkConnectionBase._log_messages)NT)NNN)rbrcrdrerfZ_remote_is_localr$r{rArr�rDrErUrFrprsr�rirrr/rrj	s

	rj)$Z
__future__rrrr�Z
__metaclass__rNrKr;�typing�t�abcr�	functoolsrZansiblerrYZansible.module_utils._textr	r
Zansible.pluginsrZansible.utils.displayrZansible.plugins.loaderr
rZansible.utils.pathrr&�__all__�BUFSIZErrrjrrrr�<module>s(	b

Zerion Mini Shell 1.0