Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/broker/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/broker/transport.pyc

ó
ÍÿŠTc@s¸dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZdefd„ƒYZd	efd
„ƒYZdS(sLow-level server communication.iÿÿÿÿN(tfetch(tbpickle(tformat_delta(t
SERVER_APItVERSIONt
HTTPTransportcBsGeZdZdd„Zd„Zd„Zd„Zdded„Z	RS(sÇTransport makes a request to exchange message data over HTTP.

    @param url: URL of the remote Landscape server message system.
    @param pubkey: SSH public key used for secure communication.
    cCs||_||_||_dS(N(t_reactort_urlt_pubkey(tselftreactorturltpubkey((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyt__init__s		cCs|jS(s)Get the URL of the remote message system.(R(R	((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pytget_urlscCs
||_dS(s)Set the URL of the remote message system.N(R(R	R((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pytset_urlsc
Cs‹i|d6dtd6dd6}|r2||d<n|rKt|ƒ|d<ntjƒ}|t|jdtd	|d
|d|jd|ƒfS(
Ns
X-Message-APIslandscape-client/%ss
User-Agentsapplication/octet-streamsContent-Types
X-Computer-IDsX-Exchange-Tokentposttdatatheaderstcainfotcurl(RtstrtpycurltCurlRRtTrueR(R	tpayloadtcomputer_idtexchange_tokentmessage_apiRR((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyt_curl#s


c
Cs1tj|ƒ}tjƒ}tjƒjƒtjkrRtjdtj	|ƒƒny"|j
||||ƒ\}}Wntjd|jƒ‚n3Xtj
dt|ƒt|ƒttjƒ|ƒƒytj|ƒ}	Wntjd|ƒdSXtjƒjƒtjkr-tjdtj	|	ƒƒn|	S(s>Exchange message data with the server.

        @param payload: The object to send, it must be L{bpickle}-compatible.
        @param computer_id: The computer ID to send the message as (see
            also L{Identity}).
        @param exchange_token: The token that the server has given us at the
            last exchange. It's used to prove that we are still the same
            client.

        @type: C{dict}
        @return: The server's response to sent message or C{None} in case
            of error.

        @note: This code is thread safe (HOPEFULLY).

        sSending payload:
%ss"Error contacting the server at %s.s*Sent %d bytes and received %d bytes in %s.s Server returned invalid data: %rsReceived payload:
%sN(Rtdumpsttimetloggingt	getLoggertgetEffectiveLeveltDEBUGtdebugtpprinttpformatRt	exceptionRtinfotlenRtloadstNone(
R	RRRRtspayloadt
start_timetcurlyRtresponse((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pytexchange/s,	N(
t__name__t
__module__t__doc__R+R
RRRRR0(((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyRs			t
FakeTransportcBsDeZdZdddd„Zd„Zd„Zdded„ZRS(s$Fake transport for testing purposes.cCsg||_g|_g|_d|_d|_d|_d|_d|_i|_	||_
||_dS(Ni(Rtpayloadst	responsest_current_responsetnext_expected_sequenceR+RRRtextraRR(R	R
RR((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyR
`s										cCs|jS(N(R(R	((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyRmscCs
||_dS(N(R(R	R((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyRpscCsâ|jj|ƒ||_||_||_|jt|jdgƒƒ7_|jt|j	ƒkr†|j	|j}|jd7_ng}t
|tƒr¤|‚ni|jd6tt
jƒƒd6|d6}|j|jƒ|S(Ntmessagesisnext-expected-sequencesnext-exchange-token(R5tappendRRRR8R)tgetR7R6t
isinstancet	Exceptiontunicodetuuidtuuid4tupdateR9(R	RRRRR/tresult((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyR0ss 			!	

N(	R1R2R3R+R
RRRR0(((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyR4]s
		(R3RR R%R@Rtlandscape.lib.fetchRt
landscape.libRt
landscape.logRt	landscapeRRtobjectRR4(((s>/usr/lib/python2.7/dist-packages/landscape/broker/transport.pyt<module>sN