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/ping.pyc


Tc@sdZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
d	efd
YZdefdYZd
efdYZdS(sR
Implementation of a lightweight exchange-triggering mechanism via
small HTTP requests asking if we should do a full exchange.

Ping Sequence
=============

Diagram::

  1. BrokerService --> Pinger              :  Start

  2. [Loop forever]
  |
  |  2.1 Pinger     --> PingClient         :  Schedule Ping
  |
  |  2.2 PingClient --> {Server} WebPing   :  Ping
  |
  |  2.3 PingClient <-- {Server} WebPing   :  return(messages waiting?
  |                                        :    [Boolean])
  |
  |  2.4 Pinger     <-- PingClient         :  return(messages waiting?
  |                                             [Boolean])
  |
  |  2.5 [If: messages waiting == True ]
  |    |
  |    |  2.5.1 Pinger --> MessageExchange  :  Schedule urgent exchange
  |    |
  |    --[End If]
  |
  |  2.6 [Wait: for ping interval to expire]
  |
  --[End Loop]

iN(tinfo(tFailure(tdefer(tloads(tfetch(tlog_failuret
PingClientcBs,eZdZddZdZdZRS(s:An HTTP client which knows how to talk to the ping server.cCs+|dkrt}n||_||_dS(N(tNoneRt_reactortget_page(tselftreactorR	((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt__init__2s		cs|dk	ridd6}tji|d6}tjfd}|jjj||j|dt	d|d|j
|jStjt
S(	srAsk the question: are there messages for this computer ID?

        @param url: The URL of the ping server to hit.
        @param insecure_id: This client's insecure ID, if C{None} no HTTP
            request will be performed and the result will be C{False}.

        @return: A deferred resulting in True if there are messages
            and False otherwise.
        s!application/x-www-form-urlencodedsContent-Typetinsecure_idcsjt|||dS(N(terrbackR(ttypetvaluettb(t
page_deferred(s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyRGstposttdatatheadersN(Rturllibt	urlencodeRtDeferredRtcall_in_threadtcallbackR	tTruetaddCallbackt_got_resulttsucceedtFalse(R
turlR
RRR((Rs9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pytping8s

cCs!t|itd6krtSdS(s
        Given a response that came from a ping server, return True if
        the response indicates that their are messages waiting for
        this computer, False otherwise.
        tmessagesN(RR(R
twebtext((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyRQsN(t__name__t
__module__t__doc__RRR!R(((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR/s	tPingercBskeZdZedZdZdZdZdZdZ	dZ
dZd	Zd
Z
RS(s
    A plugin which pings the Landscape server with HTTP requests to
    see if a full exchange should be initiated.

    @param reactor: The reactor to schedule calls with.
    @param identity: The L{Identity} holding the insecure ID used when pinging.
    @param exchanger: The L{MessageExchange} to trigger exchanges with.
    @param config: The L{BrokerConfiguration} to get the 'ping_url' and
        'ping_interval' parameters from. The 'ping_url' specifies what URL
        to hit when pinging, and 'ping_interval' how frequently to ping.
        Changes in the configuration object will take effect from the next
        scheduled ping.
    cCsV||_||_||_||_d|_d|_||_|jd|j	dS(Ntmessage(
t_configt	_identityRt
_exchangerRt_call_idt_ping_clienttping_client_factorytcall_ont_handle_set_intervals(R
Rtidentityt	exchangertconfigR.((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyRjs							cCs
|jjS(N(R)tping_url(R
((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pytget_urluscCs
|jjS(N(R)t
ping_interval(R
((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pytget_intervalxscCs#|j|j|_|jdS(sStart pinging.N(R.RR-t	_schedule(R
((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pytstart{scs[jjjjjj}|jj|jj	|j
fddS(s8Perform a ping; if there are messages, fire an exchange.cs
jS(N(R8(t_(R
(s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt<lambda>sN(R-R!R)R4R*R
RRt
addErrbackt
_got_errortaddBoth(R
tdeferred((R
s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR!s
	cCs*|r&td|jjdtndS(Ns@Ping indicates message available. Scheduling an urgent exchange.turgent(RR+tschedule_exchangeR(R
texchange((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyRs
cCst|d|jjfdS(Ns"Error contacting ping server at %s(RR-R (R
tfailure((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR=scCs%|jj|jj|j|_dS(s4Schedule a new ping using the current ping interval.N(Rt
call_laterR)R6R!R,(R
((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR8scCs|ddkrPd|krP|d|j_|jjtd|jjn|jdk	r|jj|j|jndS(NRs
set-intervalsR!s Ping interval set to %d seconds.(	R)R6twriteRR,RRtcancel_callR8(R
R(((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR0s
cCs2|jdk	r.|jj|jd|_ndS(s Stop pinging the message server.N(R,RRRF(R
((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pytstops(R$R%R&RRR5R7R9R!RR=R8R0RG(((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR'[s

								
t
FakePingercBseZdZdZRS(cOsdS(N((R
targstkwargs((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyRscCsdS(N((R
((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR9s(R$R%RR9(((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyRHs	(R&RtloggingRttwisted.python.failureRttwisted.internetRtlandscape.lib.bpickleRtlandscape.lib.fetchRtlandscape.lib.logRtobjectRR'RH(((s9/usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt<module>"s,N