ó
ÍÿŠTc           @   sx   d  d l  Z  d  d l Z d  d l m Z m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d e
 f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   get_mount_infot   is_device_removable(   t   CoverageMonitor(   t   Accumulator(   t   MonitorPlugint	   MountInfoc           B   s•   e  Z d  Z d Z d Z d d d e j d d d „ Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s
   mount-infot   diskiÈ   i,  i<   s   /proc/mountss	   /etc/mtabc         C   s   | |  _  | |  _ | |  _ | |  _ | |  _ | d  k rE t j } n  | |  _ | |  _ g  |  _	 g  |  _
 d  |  _ t |  _ d  S(   N(   t   run_intervalt   _monitor_intervalt   _create_timet   _mounts_filet
   _mtab_filet   Nonet   ost   statvfst   _statvfst   _free_spacet   _mount_infot   _mount_info_to_persistR   (   t   selft   intervalt   monitor_intervalt   mounts_filet   create_timeR   t	   mtab_file(    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyt   __init__   s    										c         C   s­   t  t |  ƒ j | ƒ t |  j |  j j ƒ |  _ t |  j	 d d d |  j
 ƒ|  _ |  j j j |  j |  j j ƒ |  j j j d |  j j d d ƒ|  j d |  j t ƒ d  S(   Ngš™™™™™é?s   mount info snapshotR   t   stopt   priorityiÐ  s
   mount-info(   t   superR   t   registerR   t   _persistt   registryt	   step_sizet   _accumulateR   R   R	   t   _monitort   reactort
   call_everyR   t   logt   call_ont   call_on_acceptedt   send_messagest   True(   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyR   "   s    "c         C   s   t  d  |  j ƒ  |  j ƒ  g ƒ S(   N(   t   filterR   t   create_mount_info_messaget   create_free_space_message(   R   (    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyt   create_messages-   s    c         C   s>   |  j  r: i d d 6|  j  d 6} |  j  |  _ g  |  _  | Sd  S(   Ns
   mount-infot   type(   R   R   R   (   R   t   message(    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyR+   1   s    		c         C   sH   |  j  rD |  j  |  j  } i d d 6| d 6} |  j  |  j |  _  | Sd  S(   Ns
   free-spaceR.   (   R   t    max_free_space_items_to_exchangeR   (   R   t   items_to_exchangeR/   (    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyR,   9   s    	


c            se   x^ ˆ  j  ƒ  D]P } ˆ  j j j | ˆ  j d | ƒ} | d d k r | j ‡  f d †  ƒ q q Wd  S(   Nt   urgentR.   s
   mount-infoc            s
   ˆ  j  ƒ  S(   N(   t   persist_mount_info(   t   x(   R   (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyt   <lambda>I   s    (   R-   R   t   brokert   send_messaget   _session_idt   addCallback(   R   R2   R/   t   d(    (   R   s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyR(   D   s
    c         C   s   |  j  j j d |  j ƒ d  S(   Ns
   mount-info(   R   R6   t   call_if_acceptedR(   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyt   exchangeK   s    c         C   sW   x: |  j  D]/ \ } } | d } |  j j d | f | ƒ q
 Wd  |  _  |  j j ƒ  d  S(   Ns   mount-points
   mount-info(   R   R   t   setR   R   t   flush(   R   t	   timestampt
   mount_infot   mount_point(    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyR3   O   s
    
	c         C   s5  |  j  j ƒ  t |  j ƒ  ƒ } t ƒ  } x|  j ƒ  D]ø } | d } | j d ƒ } d | f } |  j | | | ƒ } | r± | d } t | d ƒ } |  j j	 | | | f ƒ n  |  j
 j d | f ƒ }	 |	 sÜ |	 | k r | g  |  j D] \ }
 } | ^ qé k r |  j j	 | | f ƒ q n  | j | ƒ q5 Wd  S(   Ns   mount-points
   free-spaces   accumulate-free-spacei    i   s
   mount-info(   R"   t   pingt   intR	   R=   t   _get_mount_infot   popR!   R   t   appendR   t   getR   t   add(   R   t   nowt   current_mount_pointsR@   RA   t
   free_spacet   keyt	   step_dataR?   t   prev_mount_infot   tt   m(    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyt   runY   s"    	

(c         c   s‡   |  j  ƒ  } xt t |  j |  j ƒ D]] } | d } | d } | j d ƒ r" | j d ƒ r" |  j | ƒ r" | | k r" | Vq" q" Wd S(   s=   Generator yields local mount points worth recording data for.t   devices   mount-points   /dev/N(   t   _get_bound_mount_pointsR    R
   R   t
   startswithR   (   R   t   bound_mount_pointst   infoRR   RA   (    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyRD   o   s    

c         C   s¿   t  ƒ  } |  j s) t j j |  j ƒ r- | St |  j d ƒ } xy | D]q } y/ | j ƒ  d  \ } } } } | j d ƒ } Wn t k
 r‘ qF n Xd | j d ƒ k rF | j	 | ƒ qF qF W| S(   si   
        Returns a set of mount points that have the "bind" option
        by parsing /etc/mtab.
        t   ri   s   string-escapet   bindt   ,(
   R=   R   R   t   patht   isfilet   opent   splitt   decodet
   ValueErrorRH   (   R   t   bound_pointst   filet   lineRR   RA   t
   filesystemt   options(    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyRS   |   s    	 i  N(   t   __name__t
   __module__t   persist_namet   scopeR0   t   timeR   R   R   R-   R+   R,   t   FalseR(   R<   R3   RQ   RD   RS   (    (    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyR   
   s    							
		(   Ri   R   t   landscape.lib.diskR    R   t   landscape.lib.monitorR   t   landscape.accumulateR   t   landscape.monitor.pluginR   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/landscape/monitor/mountinfo.pyt   <module>   s   