ó
æ”\c           @   sW   d  d l  m Z d d l j Z d d l Z e j j ƒ  Z d e j	 f d „  ƒ  YZ	 d S(   i   (   t   baseiÿÿÿÿNt   Pluginc           B   sh   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   s:   
	Base class for plugins with device hotpluging support.
	c         O   s   t  t |  ƒ j | | Ž  d  S(   N(   t   superR   t   __init__(   t   selft   argst   kwargs(    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR      s    c         C   s!   t  t |  ƒ j ƒ  |  j ƒ  d  S(   N(   R   R   t   cleanupt   _hardware_events_cleanup(   R   (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR      s    c         C   s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R   (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyt   _hardware_events_init   s    c         C   s   t  ƒ  ‚ d  S(   N(   R	   (   R   (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR      s    c         C   s   |  j  ƒ  d  S(   N(   R
   (   R   (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyt   _init_devices   s    c         C   sd   | d k r0 t  j d | j ƒ |  j | ƒ n0 | d k r` t  j d | j ƒ |  j | ƒ n  d  S(   Nt   adds   device '%s' addedt   removes   device '%s' removed(   t   logt   infot   sys_namet   _add_devicet   _remove_device(   R   t   eventt   device(    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyt   _hardware_events_callback   s    c         C   s  | j  } | |  j |  j Bk r# d  Sxè t |  j j ƒ  ƒ D]° \ } } t |  j | | g ƒ ƒ d k r9 t j	 d | | f ƒ |  j j
 | ƒ |  j | | j d | g ƒ |  j | | ƒ |  j | | j d | g ƒ | j j
 | ƒ Pq9 q9 Wt j d | ƒ |  j j
 | ƒ d  S(   Ni   s!   instance %s: adding new device %st   applys   no instance wants %s(   R   t   _assigned_devicest   _free_devicest   listt
   _instancest   itemst   lent   _get_matching_devicesR   R   R   t   _call_device_scriptt
   script_pret   _added_device_apply_tuningt   script_postt   processed_devicest   debug(   R   R   t   device_namet   instance_namet   instance(    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR   $   s    	"!c         C   s÷   | j  } | |  j |  j Bk r# d  SxÍ t |  j j ƒ  ƒ D]¦ } | | j k r9 |  j | | j d | g ƒ |  j	 | | ƒ |  j | | j
 d | g ƒ | j j | ƒ t | j ƒ t | j ƒ d k | _ |  j j | ƒ Pq9 q9 W|  j j | ƒ d  S(   Nt   unapplyi    (   R   R   R   R   R   t   valuesR"   R   R!   t   _removed_device_unapply_tuningR   R   R   t   assigned_devicest   active(   R   R   R$   R&   (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR   6   s    	c         C   sN   |  j  | | g ƒ | j rJ |  j j t j t j ƒ rJ |  j | | ƒ n  d  S(   N(   t   _execute_all_device_commandst   has_dynamic_tuningt   _global_cfgt   gett   constst   CFG_DYNAMIC_TUNINGt   CFG_DEF_DYNAMIC_TUNINGt   _instance_apply_dynamic(   R   R&   R$   (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR    J   s    $c         C   sN   | j  r7 |  j j t j t j ƒ r7 |  j | | ƒ n  |  j | | g ƒ d  S(   N(   R-   R.   R/   R0   R1   R2   t   _instance_unapply_dynamict   _cleanup_all_device_commands(   R   R&   R$   (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR)   O   s    $(   t   __name__t
   __module__t   __doc__R   R   R
   R   R   R   R   R   R    R)   (    (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyR      s   									(
   t    R    t   tuned.constsR0   t
   tuned.logst   tunedt   logsR/   R   R   (    (    (    s9   /usr/lib/python2.7/site-packages/tuned/plugins/hotplug.pyt   <module>   s   