ó
ÍÿŠTc           @   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   sJ   e  Z d  Z d Z d Z d „  Z d „  Z e d „  ƒ Z	 e d „  ƒ Z
 RS(   sy   
    @cvar persist_name: If specified as a string, a C{_persist} attribute
    will be available after registration.
    c         C   sP   t  t |  ƒ j | ƒ |  j d  k	 rC |  j j j |  j ƒ |  _ n	 d  |  _ d  S(   N(	   t   superR   t   registert   persist_namet   Nonet   monitort   persistt   root_att   _persist(   t   selfR
   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR      s    c         C   s,   |  j  d  k	 r( |  j j j |  j  ƒ n  d  S(   N(   R   R	   t   registryR   t   remove(   R   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyt   _reset   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    N(   t   __name__t
   __module__t   __doc__R	   R   t   scopeR   R   t   propertyR   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   datat   typeN(   t   get_dataR   t   gett   sett   message_typet   message_key(   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyt   get_message7   s    c            sƒ   ˆ  j  ƒ  } | d  k	 ry t d t ˆ  ƒ ƒ ˆ  j 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"   I   s    (   R    R	   R    R   R   t   brokert   send_messaget   _session_idt   addCallbackt
   addErrbackR   R   (   R   R!   t   messaget   resultR"   (    (   R   s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR%   A   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"   Q   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   exchangeX   s    N(   R   R   R   R	   R   R   R    R%   R"   t   FalseR,   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/monitor/plugin.pyR   )   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   