ó
½-'Nc           @   s°   d  d l  Z  d  d l Z d  d l 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 e f d     YZ d S(   i’’’’N(   t   datetime(   t   ProcessInformation(   t   ManagerPlugint   ProcessNotFoundErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyR   
   s   t   ProcessMismatchErrorc           B   s   e  Z RS(    (   R   R   (    (    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyR      s   t   SignalProcessErrorc           B   s   e  Z RS(    (   R   R   (    (    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyR      s   t   ProcessKillerc           B   s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   sb   
    A management plugin that signals processes upon receiving a message from
    the server.
    c         C   s%   | d  k r t   } n  | |  _ d  S(   N(   t   NoneR   t   process_info(   t   selfR
   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyt   __init__   s    c         C   s-   t  t |   j |  | j d |  j  d  S(   Ns   signal-process(   t   superR   t   registert   register_messaget   _handle_signal_process(   R   t   registry(    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyR   !   s    	c         C   s3   |  j  | |  j | d | d | d | d  d  S(   Nt   pidt   names
   start-timet   signal(   t   call_with_operation_resultt   signal_process(   R   t   message(    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyR   &   s    c   
      C   s  t  j d | |  |  j j |  } | s\ t j |  } d | | | f } t |   nd t | d |  d k rĄ t j |  } t j | d  } d | | | | | f } t |   n  t	 t
 d | f  }	 y t j | |	  Wn& d | | | f } t |   n Xd  S(   Ns-   Sending %s signal to the process with PID %d.s?   The process %s with PID %d that started at %s UTC was not founds
   start-timei   s   The process %s with PID %d that started at %s UTC was not found.  A process with the same PID that started at %s UTC was found and not sent the %s signals   SIG%ssE   Attempting to send the %s signal to the process %s with PID %d failed(   t   loggingt   infoR
   t   get_process_infoR    t   utcfromtimestampR   t   absR   t   getattrR   t   ost   killR   (
   R   R   R   t
   start_timet   signameR
   R   t   expected_timet   actual_timet   signum(    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyR   ,   s,    	
	N(   R   R   t   __doc__R	   R   R   R   R   (    (    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyR      s
   		(   R   R   R   R    t   landscape.lib.processR   t   landscape.manager.pluginR   t	   ExceptionR   R   R   R   (    (    (    sC   /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.pyt   <module>   s   