ó
½-'Nc           @   s€   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
 S(   iÿÿÿÿ(   t   info(   t   succeed(   t   format_object(   t   log_failure(   t   BrokerClientPlugint   MonitorPluginc           B   sM   e  Z d  Z d Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z	 d „  Z
 RS(   sy   
    @cvar persist_name: If specified as a string, a C{_persist} attribute
    will be available after registration.
    c         C   si   t  t |  ƒ j | ƒ |  j d  k	 r\ |  j j j |  j ƒ |  _ |  j	 j
 j d |  j ƒ n	 d  |  _ d  S(   Nt   resynchronize(   t   superR   t   registert   persist_namet   Nonet   monitort   persistt   root_att   _persistt   registryt   reactort   call_ont   _resynchronize(   t   selfR   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR      s
    c         C   s   |  j  j j |  j ƒ d  S(   N(   R   R   t   removeR	   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR      s    c         C   s   |  j  S(   s   Return our L{Persist}, if any.(   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR      s    c         C   s   |  j  S(   s%   An alias for the C{client} attribute.(   t   client(   R   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR   "   s    c            s5   ‡ ‡  ‡ f d †  } |  j  j j d | f | ƒ d S(   sV   
        Register a callback fired upon a C{message-type-acceptance-changed}.
        c            s   |  r ˆ  ˆ ˆ Ž  Sd  S(   N(    (   t
   acceptance(   t   callablet   argst   kwargs(    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyt   acceptance_changed,   s    s   message-type-acceptance-changedN(   R   R   R   (   R   t   typeR   R   R   R   (    (   R   R   R   s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyt   call_on_accepted'   s    N(   t   __name__t
   __module__t   __doc__R
   R	   R   R   t   propertyR   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR   
   s   		t   DataWatcherc           B   sA   e  Z d  Z d Z d Z d „  Z d „  Z d „  Z e	 d „ Z
 RS(   sY  
    A utility for plugins which send data to the Landscape server
    which does not constantly change. New messages will only be sent
    when the result of get_data() has changed since the last time it
    was called.

    Subclasses should provide a get_data method, and message_type,
    message_key, and persist_name class attributes.
    c         C   sS   |  j  ƒ  } |  j j d ƒ | k rO |  j j d | ƒ i |  j d 6| |  j 6Sd S(   s}   
        Construct a message with the latest data, or None, if the data
        has not changed since the last call.
        t   dataR   N(   t   get_dataR   t   gett   sett   message_typet   message_key(   R   R"   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyt   get_messageB   s    c            s}   ˆ  j  ƒ  } | d  k	 rs t d t ˆ  ƒ ƒ ˆ  j j j | d | ƒ} ‡  f d †  } | j | ƒ | j t	 ƒ | St
 d  ƒ S(   Ns9   Queueing a message with updated data watcher info for %s.t   urgentc            s   ˆ  j  ƒ  d  S(   N(   t   persist_data(   t
   message_id(   R   (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR*   S   s    (   R(   R
   R    R   R   t   brokert   send_messaget   addCallbackt
   addErrbackR   R   (   R   R)   t   messaget   resultR*   (    (   R   s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR-   L   s    c         C   s   d S(   ss   
        Sub-classes that need to defer the saving of persistent data
        should override this method.
        N(    (   R   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR*   [   s    c         C   s   |  j  j j |  j |  j | ƒ S(   sd   
        Conditionally add a message to the message store if new data
        is available.
        (   R   R,   t   call_if_acceptedR&   R-   (   R   R)   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyt   exchangeb   s    N(   R   R   R   R
   R&   R'   R(   R-   R*   t   FalseR3   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR!   4   s   		
		N(   t   loggingR    t   twisted.internet.deferR   t   landscape.logR   t   landscape.lib.logR   t   landscape.broker.clientR   R   R!   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyt   <module>   s   *