Current Path : /usr/lib/python2.7/dist-packages/landscape/broker/ |
Current File : //usr/lib/python2.7/dist-packages/landscape/broker/ping.pyc |
Tc @ s d Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d e f d YZ d e f d YZ d e f d YZ d S( 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( t info( t Failure( t defer( t loads( t fetch( t log_failuret PingClientc B s, e Z d Z d d Z d Z d Z RS( s: An HTTP client which knows how to talk to the ping server.c C s+ | d k r t } n | | _ | | _ d S( N( t NoneR t _reactort get_page( t selft reactorR ( ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt __init__2 s c s | d k r i d d 6} t j i | d 6 } t j f d } | j j j | | j | d t d | d | j | j St j t S( sr Ask 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-Typet insecure_idc s j t | | | d S( N( t errbackR ( t typet valuet tb( t page_deferred( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR G s t postt datat headersN( R t urllibt urlencodeR t DeferredR t call_in_threadt callbackR t Truet addCallbackt _got_resultt succeedt False( R t urlR R R R ( ( R s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt ping8 s c C s! t | i t d 6k r t Sd S( 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. t messagesN( R R ( R t webtext( ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR Q s N( t __name__t __module__t __doc__R R R! R ( ( ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR / s t Pingerc B sk e Z d Z e d Z d Z d Z d Z d Z d Z d Z d Z d 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. c C sV | | _ | | _ | | _ | | _ d | _ d | _ | | _ | j d | j d S( Nt message( t _configt _identityR t _exchangerR t _call_idt _ping_clientt ping_client_factoryt call_ont _handle_set_intervals( R R t identityt exchangert configR. ( ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyR j s c C s | j j S( N( R) t ping_url( R ( ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt get_urlu s c C s | j j S( N( R) t ping_interval( R ( ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt get_intervalx s c C s# | j | j | _ | j d S( s Start pinging.N( R. R R- t _schedule( R ( ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt start{ s c s[ j j j j j j } | j j | j j | j f d d S( s8 Perform a ping; if there are messages, fire an exchange.c s j S( N( R8 ( t _( R ( s9 /usr/lib/python2.7/dist-packages/landscape/broker/ping.pyt <lambda>