Anons79 Mini Shell

Directory : /proc/self/root/lib/python2.7/site-packages/ansible/plugins/connection/
Upload File :
Current File : //proc/self/root/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyo

�
�Udac@`sddlmZmZmZeZdZddlZddlZddl	Z	ddl
Z
ddlZddlZe
ZyddlZeZWnek
r�nXddlmZddlmZddlmZmZddlmZdefd	��YZdS(
i(tabsolute_importtdivisiontprint_functions�
    author: Joerg Thalheim <[email protected]>
    connection: lxc
    short_description: Run tasks in lxc containers via lxc python library
    description:
        - Run commands or put/fetch files to an existing lxc container using lxc python library
    version_added: "2.0"
    options:
      remote_addr:
        description:
            - Container identifier
        default: inventory_hostname
        vars:
            - name: ansible_host
            - name: ansible_lxc_host
      executable:
        default: /bin/sh
        description:
            - Shell executable
        vars:
            - name: ansible_executable
            - name: ansible_lxc_executable
N(t	constants(terrors(tto_bytest	to_native(tConnectionBaset
ConnectioncB`sneZdZdZeZdZd�Zd�Zd�Z	d�Z
ded�Z
d�Zd	�Zd
�ZRS(s Local lxc based connections tlxctrootcO`s;tt|�j||||�|jj|_d|_dS(N(tsuperRt__init__t
_play_contexttremote_addrtcontainer_nametNonet	container(tselftplay_contextt	new_stdintargstkwargs((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyR;scC`s�tt|�j�ts1d}tj|��n|jr>dS|jjdd|j	�t
j|j	�|_|jjdkr�tjd|j	��ndS(s( connect to the lxc; nothing to do here s*lxc bindings for python2 are not installedNsTHIS IS A LOCAL LXC DIRthosttSTOPPEDs%s is not running(
RRt_connectt
HAS_LIBLXCRtAnsibleErrorRt_displaytvvvRt_lxct	Containertstate(Rtmsg((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyRAs	cC`s�ig|6g|6}||g}|r2|g}ng}xt|�dks_t|�dkrOy"tj||g�\}	}
}Wn5tjk
r�}|jdtjkr�q;n�nXxF|
D]>}
|tj|
|�}t|�dkr�|j|
�q�q�WxG|	D]?}
tj	|
d�}|s7|j|
�n||
j
|�q	Wq;Wtj|d�\}}|dj||�dj||�fS(Nii�t(
tlentselectterrorRterrnotEINTRtostwritetremovetreadtappendtwaitpidtjoin(Rtpidtin_datatstdintstdouttstderrtbuftread_fdst	write_fdstready_readstready_writest_tetfdtdatat
returncode((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyt_communicateQs.'"

cC`s6tj|tj�tjB}tj|tj|�|S(N(tfcntltF_GETFLR(t
O_NONBLOCKtF_SETFL(RR;tflags((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyt_set_nonblockingmsc	C`s�tt|�j|d|d|�t|jjdd�}|dt|dd�g}d\}}d\}}	d\}
}z8tj�\}}tj�\}}	i|j	|�d6|j	|	�d6t
jd6}|r�tj�\}
}|j	|
�|d	<n|jj
d
|d|j�|jjt
j||�}
|
dkrad
|j}tj|��ntj|�}tj|	�}	|
r�tj|
�}
n|j|
||||�SWd||||	|
|g}x$|D]}|r�tj|�q�q�WXdS(s run a command on the chroot R0tsudoableRtsurrogate_or_stricts-cR2R3t
env_policyR1sEXEC %sRi����s failed to attach to container %sN(NN(NN(NN(RRtexec_commandRR
t
executableRR(tpipeRDRtLXC_ATTACH_CLEAR_ENVRRRRtattachtattach_run_commandRRtcloseR>(RtcmdR0RERIt	local_cmdtread_stdouttwrite_stdouttread_stderrtwrite_stderrt
read_stdintwrite_stdinRR/R!tfdsR;((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyRHrsN"

		
c`sHtt|�j|��|jjd|�fd|j�t|dd�}t�dd��tjj	|�s�d|}t
j|��nyt|d��Wn.t
k
r�tj�t
jd|��nXzd��fd�}y|jj|d
�Wn4t
k
r4tj�d	�}t
j|��nXWd
�j�Xd
S(s# transfer a file from local to lxc sPUT %s TO %sRRRFs!file or module does not exist: %strbsfailed to open input file to %sc`s,t�d��}tj�|�WdQXdS(Nswb+(topentshutiltcopyfileobj(Rtdst_file(tout_pathtsrc_file(sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyt
write_file�ssfailed to transfer file to %sN(RRtput_fileRRRRR(tpathtexistsRtAnsibleFileNotFoundRYtIOErrort	tracebackt	print_excRRtattach_waitRRN(Rtin_pathR]R!R_((R]R^sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyR`�s*#





c`s&tt|�j�|�|jjd�|fd|j�t�dd��t|dd�}yt|d��Wn4tk
r�t	j
�d|}tj|��nXzj��fd�}y|j
j|d	�Wn:tk
rt	j
�d�|f}tj|��nXWd	�j�Xd	S(
s  fetch a file from lxc to local sFETCH %s TO %sRRRFtwbsfailed to open output file %sc`s>z,t�d��}tj|��WdQXWd�j�XdS(NRX(RYRZR[RN(RR^(R\Rh(sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyR_�ss%failed to transfer file from %s to %sN(RRt
fetch_fileRRRRRYRdReRfRRRRgRRN(RRhR]R!R_((R\RhsB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyRj�s&#




cC`s tt|�j�t|_dS(s. terminate the connection; nothing to do here N(RRRNtFalset
_connected(R((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyRN�sN(t__name__t
__module__t__doc__t	transporttTruethas_pipeliningtdefault_userRRR>RDRRkRHR`RjRN(((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyR4s				5		(t
__future__RRRttypet
__metaclass__t
DOCUMENTATIONR(RZReR$R?R&RkRR	RRqtImportErrortansibleRtCRtansible.module_utils._textRRtansible.plugins.connectionRR(((sB/usr/lib/python2.7/site-packages/ansible/plugins/connection/lxc.pyt<module>s&



Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]