%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/transport/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/transport/ipc.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZ
ddlZ
ddl
Z
ddlmZddlmZmZddlmZmZddlZddlZddlmZeje�Zd�Zd	e
j j!fd
��YZ"de#fd��YZ$d
e#fd��YZ%de%fd��YZ&de$fd��YZ'de#fd��YZ(de%fd��YZ)dS(u
IPC transport classes
i(tabsolute_importtprint_functiontunicode_literalsN(tLock(tIOLooptTimeoutError(tIOStreamtStreamClosedError(tsixcC@s&|jdk	r"|jj|�ndS(N(t_future_with_timeouttNonet_done_callback(tfuture((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytfuture_with_timeout_callback$stFutureWithTimeoutcB@s#eZd�Zd�Zd�ZRS(cC@s�tt|�j�||_||_|dk	rq|dkrFd}n|jj|jj�||j�|_	n	d|_	t
|jd�r�||j_|jj�r�t
|j�q�n||j_|jjt
�dS(Ng�������?u_future_with_timeout(tsuperRt__init__tio_loopt_futureR
tadd_timeoutttimet_timeout_callbackt_timeout_handlethasattrR	tdoneR
tadd_done_callback(tselfRRttimeout((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR*s				"	cC@s)d|_d|j_|jt��dS(N(R
RRR	t
set_exceptiontTornadoTimeoutError(R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRAs	cC@slyE|jdk	r1|jj|j�d|_n|j|j��Wn tk
rg}|j|�nXdS(N(RR
Rtremove_timeoutt
set_resulttresultt	ExceptionR(RRtexc((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRJs(t__name__t
__module__RRR(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR)s			t	IPCServercB@sVeZdZddd�Zd�Zejjd��Z	d�Z
d�Zd�ZRS(u�
    A Tornado IPC server very similar to Tornado's TCPServer class
    but using either UNIX domain sockets or TCP sockets
    cC@sF||_t|_||_d|_|p3tj�|_t|_	dS(u	
        Create a new Tornado IPC server

        :param str/int socket_path: Path on the filesystem for the
                                    socket to bind to. This socket does
                                    not need to exist prior to calling
                                    this method, but parent directories
                                    should.
                                    It may also be of type 'int', in
                                    which case it is used as the port
                                    for a tcp localhost connection.
        :param IOLoop io_loop: A Tornado ioloop to handle scheduling
        :param func payload_handler: A function to customize handling of
                                     incoming data.
        N(
tsocket_pathtFalset_startedtpayload_handlerR
tsockRtcurrentRt_closing(RR&RR)((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRZs				cC@s�tjd|j�t|jt�r�tjtjtj�|_|jj	tj
tjd�|jjd�|jj
d|jf�|jjd�ntjj|j�|_tjjj|j��tjj|j|j�WdQXt|_dS(uy
        Perform the work necessary to start up a Tornado IPC server

        Blocks until socket is established
        u IPCServer: binding to socket: %siiu	127.0.0.1i�N(tlogttraceR&t
isinstancetinttsockettAF_INETtSOCK_STREAMR*t
setsockoptt
SOL_SOCKETtSO_REUSEADDRtsetblockingtbindtlistenttornadotnetutiltbind_unix_sockettsalttutilstasynchronoustcurrent_ioloopRtadd_accept_handlerthandle_connectiontTrueR((R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytstartss	c	#@s�tjjd����fd�}tjdkrFitjd6}n&tjr_idd6}n
idd6}tj|�}x	|j	�s�yh|j
d	d
t�V}|j|�x>|D]6}|d}|j
j|j||||d��q�WWq~tk
rtjd
|j�Pq~tjk
r`}|jdkrMtjd|�q�tjd|�q~tk
r�}tjd|�q~Xq~WdS(u�
        Override this to handle the streams as they arrive

        :param IOStream stream: An IOStream for processing

        See https://tornado.readthedocs.io/en/latest/iostream.html#tornado.iostream.IOStream
        for additional details.
        cS@stjjd��dS(N(R:tgentReturnR
(tmsg((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt_null�sc@s9�jd�r1tjj��fd��}|S�SdS(Numidc3@s>tjjj|di�dd6dt�}�j|�VdS(Ntheaderumidtraw_body(R=t	transporttframet
frame_msg_ipcRCtwrite(RGtpack(RItstream(s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytreturn_message�s
	(tgetR:REt	coroutine(RPRIRQ(RH(RIRPs6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytwrite_callback�siiiurawuencodinguutf-8itpartialubodyuheaduClient disconnected from IPC %su=Exception occured with error number 0, spurious exception: %su,Exception occurred while handling stream: %sN(iii(R:RERStmsgpacktversionRtPY2R
tUnpackertclosedt
read_bytesRCtfeedRtspawn_callbackR)RR-R.R&R1terrorterrnoR!(	RRPRTtmsgpack_kwargstunpackert
wire_bytest
framed_msgtbodyR"((RHs6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt
handle_stream�s6
	



.
	
	
	cC@stjd|�yEtjjj|j��t|�}WdQX|jj|j	|�Wn#t
k
rz}tjd|�nXdS(Nu-IPCServer: Handling connection to address: %suIPC streaming error: %s(R-R.R=R>R?R@RRR]ReR!R^(Rt
connectiontaddressRPR"((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRB�s	cC@s<|jr
dSt|_t|jd�r8|jj�ndS(u�
        Routines to handle any cleanup before the instance shuts down.
        Sockets and filehandles should be closed explicitly, to prevent
        leaks.
        Nuclose(R,RCRR*tclose(R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRh�s
		cC@s&y|j�Wntk
r!nXdS(N(Rht	TypeError(R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt__del__�s
N(
R#R$t__doc__R
RRDR:RERSReRBRhRj(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR%Us	<		t	IPCClientcB@s\eZdZdd�Zd�Zddd�Zejj	dd��Z
d�Zd�ZRS(u�
    A Tornado IPC client very similar to Tornado's TCPClient class
    but using either UNIX domain sockets or TCP sockets

    This was written because Tornado does not have its own IPC
    server/client implementation.

    :param IOLoop io_loop: A Tornado ioloop to handle scheduling
    :param str/int socket_path: A path on the filesystem where a socket
                                belonging to a running IPCServer can be
                                found.
                                It may also be of type 'int', in which
                                case it is used as the port for a tcp
                                localhost connection.
    cC@s�|ptjjj�|_||_t|_d|_	t
jdkrXitj
d6}n&tj
rqidd6}n
idd6}t
j|�|_dS(	u�
        Create a new IPC client

        IPC clients cannot bind to ports, but must connect to
        existing IPC servers. Clients can then send messages
        to the server.

        iiiurawuencodinguutf-8N(iii(R:tioloopRR+RR&R'R,R
RPRVRWRRXRYRa(RR&RR`((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR�s					
cC@s|jdk	o|jj�S(N(RPR
RZ(R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt	connectedsc@s�t�d�r+�jj�r+�j}nGt�d�rJ�jj�ntjj�}|�_�jd|��dk	r���fd�}|j	|�n|S(u+
        Connect to the IPC socket
        u_connecting_futureRc@s#|j�}�jj�|�dS(N(R Rtadd_callback(Rtresponse(tcallbackR(s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt
handle_future#sN(
Rt_connecting_futureRt	exceptionR:t
concurrenttFuturet_connectR
R(RRqRRRr((RqRs6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytconnects	cc@s�t|jt�r-tj}d|jf}ntj}|j}d|_|dk	rgtj�|}nx;t	r�|j
r}Pn|jdkr�tjj
j|j��#ttj|tj��|_WdQXny9tjd|j�|jj|�V|jjt	�PWqjtk
r�}|jj�r2d|_n|dksPtj�|kr�|jdk	rx|jj�d|_n|jj|�Pntjjd�VqjXqjWdS(u0
        Connect to a running IPCServer
        u	127.0.0.1Nu#IPCClient: Connecting to socket: %si(R/R&R0R1R2tAF_UNIXR
RPRRCR,R=R>R?R@RRR3R-R.RxRsRR!RZRhRR:REtsleep(RRt	sock_typet	sock_addrt
timeout_atte((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRw*s<						$
cC@sSy|j�Wn>tjk
r>}|jtjkrO�qOntk
rNnXdS(N(RhR1R^R_tEBADFRi(RR"((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRjUs	
cC@s_|jr
dSt|_tjd|jj�|jdk	r[|jj�r[|jj	�ndS(u�
        Routines to handle any cleanup before the instance shuts down.
        Sockets and filehandles should be closed explicitly, to prevent
        leaks.
        NuClosing %s instance(
R,RCR-tdebugt	__class__R#RPR
RZRh(R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRhas		N(
R#R$RkR
RRnRxR:RERSRwRjRh(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRl�s		*	tIPCMessageClientcB@s)eZdZejjddd��ZRS(u�
    Salt IPC message client

    Create an IPC client to send messages to an IPC server

    An example of a very simple IPCMessageClient connecting to an IPCServer. This
    example assumes an already running IPCMessage server.

    IMPORTANT: The below example also assumes a running IOLoop process.

    # Import Tornado libs
    import tornado.ioloop

    # Import Salt libs
    import salt.config
    import salt.transport.ipc

    io_loop = tornado.ioloop.IOLoop.current()

    ipc_server_socket_path = '/var/run/ipc_server.ipc'

    ipc_client = salt.transport.ipc.IPCMessageClient(ipc_server_socket_path, io_loop=io_loop)

    # Connect to the server
    ipc_client.connect()

    # Send some data
    ipc_client.send('Hello world')
    cc@sJ|j�s|j�Vntjjj|dt�}|jj|�VdS(u

        Send a message to an IPC socket

        If the socket is not currently connected, a connection will be established.

        :param dict msg: The message to be sent
        :param int timeout: Timeout when sending message (Currently unimplemented)
        RJN(	RnRxR=RKRLRMRCRPRN(RRGRttriesRO((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytsend�s
N(R#R$RkR:RERSR
R�(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR�rs	tIPCMessageServercB@seZdZRS(uN
    Salt IPC message server

    Creates a message server which can create and bind to a socket on a given
    path and then respond to messages asynchronously.

    An example of a very simple IPCServer which prints received messages to
    a console:

        # Import Tornado libs
        import tornado.ioloop

        # Import Salt libs
        import salt.transport.ipc
        import salt.config

        opts = salt.config.master_opts()

        io_loop = tornado.ioloop.IOLoop.current()
        ipc_server_socket_path = '/var/run/ipc_server.ipc'
        ipc_server = salt.transport.ipc.IPCMessageServer(opts, io_loop=io_loop
                                                         stream_handler=print_to_console)
        # Bind to the socket and prepare to run
        ipc_server.start(ipc_server_socket_path)

        # Start the server
        io_loop.start()

        # This callback is run whenever a message is received
        def print_to_console(payload):
            print(payload)

    See IPCMessageClient() for an example of sending messages to an IPCMessageServer instance
    (R#R$Rk(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR��s"tIPCMessagePublishercB@s\eZdZdd�Zd�Zejjd��Z	d�Z
d�Zd�Zd�Z
RS(	u~
    A Tornado IPC Publisher similar to Tornado's TCPServer class
    but using either UNIX domain sockets or TCP sockets
    cC@sR||_||_t|_d|_|p3tj�|_t|_	t
�|_dS(u�
        Create a new Tornado IPC server
        :param dict opts: Salt options
        :param str/int socket_path: Path on the filesystem for the
                                    socket to bind to. This socket does
                                    not need to exist prior to calling
                                    this method, but parent directories
                                    should.
                                    It may also be of type 'int', in
                                    which case it is used as the port
                                    for a tcp localhost connection.
        :param IOLoop io_loop: A Tornado ioloop to handle scheduling
        N(toptsR&R'R(R
R*RR+RR,tsettstreams(RR�R&R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR�s					cC@s�tjd|j�t|jt�r�tjtjtj�|_|jj	tj
tjd�|jjd�|jj
d|jf�|jjd�ntjj|j�|_tjjj|j��tjj|j|j�WdQXt|_dS(uy
        Perform the work necessary to start up a Tornado IPC server

        Blocks until socket is established
        u*IPCMessagePublisher: binding to socket: %siiu	127.0.0.1i�N(R-R.R&R/R0R1R2R3R*R4R5R6R7R8R9R:R;R<R=R>R?R@RRARBRCR((R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRD�s	cc@s�y|j|�VWntk
rHtjd|j�|jj|�nLtk
r�}tjd|�|j	�s�|j
�n|jj|�nXdS(NuClient disconnected from IPC %su,Exception occurred while handling stream: %s(RNRR-R.R&R�tdiscardR!R^RZRh(RRPROR"((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt_write�s

cC@s_t|j�sdStjjj|dt�}x*|jD]}|jj|j	||�q8WdS(u7
        Send message to all connected sockets
        NRJ(
tlenR�R=RKRLRMRCRR]R�(RRGRORP((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytpublish
s
c@s�tjd|�y�i}�jddkrW�jd|d<tjd�jd�ntjjj�j��t||��WdQX�j	j
����fd�}�j|�Wn#tk
r�}tj
d|�nXdS(Nu-IPCServer: Handling connection to address: %suipc_write_bufferiumax_write_buffer_sizeu'Setting IPC connection write buffer: %sc@s�jj��dS(N(R�R�((RRP(s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pytdiscard_after_closed$suIPC streaming error: %s(R-R.R�R=R>R?R@RRR�taddtset_close_callbackR!R^(RRfRgtkwargsR�R"((RRPs6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRBscC@sg|jr
dSt|_x|jD]}|j�q W|jj�t|jd�rc|jj�ndS(u�
        Routines to handle any cleanup before the instance shuts down.
        Sockets and filehandles should be closed explicitly, to prevent
        leaks.
        Nuclose(R,RCR�RhtclearRR*(RRP((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRh+s		
cC@s&y|j�Wntk
r!nXdS(N(RhRi(R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRj:s
N(R#R$RkR
RRDR:RERSR�R�RBRhRj(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR��s	
			tIPCMessageSubscribercB@seeZdZdd�Zejjdd��Zdd�Z	ejjd��Z
d�Zd�ZRS(u�
    Salt IPC message subscriber

    Create an IPC client to receive messages from IPC publisher

    An example of a very simple IPCMessageSubscriber connecting to an IPCMessagePublisher.
    This example assumes an already running IPCMessagePublisher.

    IMPORTANT: The below example also assumes the IOLoop is NOT running.

    # Import Tornado libs
    import tornado.ioloop

    # Import Salt libs
    import salt.config
    import salt.transport.ipc

    # Create a new IO Loop.
    # We know that this new IO Loop is not currently running.
    io_loop = tornado.ioloop.IOLoop()

    ipc_publisher_socket_path = '/var/run/ipc_publisher.ipc'

    ipc_subscriber = salt.transport.ipc.IPCMessageSubscriber(ipc_server_socket_path, io_loop=io_loop)

    # Connect to the server
    # Use the associated IO Loop that isn't running.
    io_loop.run_sync(ipc_subscriber.connect)

    # Wait for some data
    package = ipc_subscriber.read_sync()
    cC@s>tt|�j|d|�d|_g|_t�|_dS(NR(RR�RR
t_read_stream_futuret_saved_dataRt_read_in_progress(RR&R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRds

		c	c@sy|jjdd�VWn)tjjk
rCtjjd��nXd}d}yx�trN|jdkr�|j	j
ddt�|_n|dkr�|jV}nt|j|j|�V}d|_d}|j
j|�t}x^|j
D]S}|r|jj||d�q�|r)|d}t}q�|jj|d�q�W|sVPqVqVWWn|tk
rid}nftk
r�}tjd|j�d|_|}n2tk
r�}tjd|�d|_|}nX|jj�|dk	r�|�ntjj|��dS(NRg:�0�yE>iRUubodyu#Subscriber disconnected from IPC %su:Exception occurred in Subscriber while handling stream: %s(R�tacquireR:RERRFR
RCR�RPR[RRRaR\R]R'R�tappendRRR-R.R&R!R^trelease(	RRRqtexc_to_raisetretRbtfirst_sync_msgRcR"((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt_readksT	
	
	
	
				

	c@s5�jr�jjd�S�jj��fd��S(uZ
        Read a message from an IPC socket

        The socket must already be connected.
        The associated IO Loop must NOT be running.
        :param int timeout: Timeout when receiving message
        :return: message data if successful. None if timed out. Will raise an
                 exception for all other error conditions.
        ic@s
�j��S(N(R�((RR(s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt<lambda>�s(R�tpopRtrun_sync(RR((RRs6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt	read_sync�s
	cc@s�x�|j�s�y|jdd�VWqtk
r[tjd|j�tjjd�Vqt	k
r�}tj
d|�tjjd�VqXqW|jd|�VdS(u�
        Asynchronously read messages and invoke a callback when they are ready.

        :param callback: A callback with the received data
        Riu1Subscriber closed stream on IPC %s before connectiu2Exception occurred while Subscriber connecting: %sN(
RnRxRR-R.R&R:RERzR!R^R�R
(RRqR"((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt
read_async�s
cC@s}|jr
dStt|�j�|jdk	ry|jj�ry|jj�}|ryt|t	�ryt
jd|�qyndS(u�
        Routines to handle any cleanup before the instance shuts down.
        Sockets and filehandles should be closed explicitly, to prevent
        leaks.
        Nu!Read future returned exception %r(R,RR�RhR�R
RRtR/RR-R^(RR"((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRh�s	cC@s tt�kr|j�ndS(N(R�tglobalsRh(R((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyRj�sN(
R#R$RkR
RR:RERSR�R�R�RhRj(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyR�Cs 	:	(*Rkt
__future__RRRR_tloggingR1RRVR:ttornado.genttornado.netutilttornado.concurrentt
tornado.locksRttornado.ioloopRRRttornado.iostreamRRtsalt.transport.clientR=tsalt.transport.frametsalt.extRt	getLoggerR#R-R
RuRvRtobjectR%RlR�R�R�R�(((s6/usr/lib/python2.7/site-packages/salt/transport/ipc.pyt<module>s2	,��0%|

Zerion Mini Shell 1.0