
    /I_                         S SK r S SKrS SKrS SKr S SKJs  Jr  S SKJr  S SK	7  S SK
Jr   " S S\5      rg! \\4 a    S SKJr  S SKJr  S SK7  S SKJr   N-f = f)    N)
moduleBase)*)utilsc                       \ rS rSrSrSSSS/S/S.S	S
S/S/S.SS/S/S.S.S.rS rS rS rS r	S r
S r\\
S.rS rSS jrSrg)vrrpd   z5ifupdown2 addon module to configure vrrpd attributes z+ethtool configuration module for interfaceszvrrp instance id14096z	vrrp-id 1)help
validrangeexamplezset vrrp priority0255zvrrp-priority 20zset vrrp virtual ipz<ipv4>zvrrp-virtual-ip 10.0.1.254)r   	validvalsr   )vrrp-idvrrp-priorityvrrp-virtual-ip)mhelpattrsc                 8    [         R                  " U /UQ70 UD6  g N)r   __init__)selfargskargss      $/usr/share/ifupdown2/addons/vrrpd.pyr   vrrpd.__init__.   s    D14151    c                    / nSn [         R                  U/n[         R                  " US S9R                  S5      nU(       d  / $ UR                  5       nU(       d  U$ U H  nUR                  SS5      n U R                  SU-  5      n	[        R                  " SSU	5      n	U R                  R                  SU	-  5        U R                  R                  SU-  5        U R                  R                  S	[        U	5      [        U5      4-  5        U	(       a  X:X  a  UR                  U5        M  M  M     U$ ! [         a     GNf = f! [         a     M  f = f)
N )stderr
 z/proc/%s/cmdlinez\\(.)z\1z(%s)z	(%d) (%d))r   	pidof_cmdexec_commandlstrip	Exceptionsplitreplaceread_file_onelineresubloggerinfolenappend)
r   cmdnamecmdline
targetpidspidstrcmdlpidspid
tmpcmdlinepcmdlines
             r   _check_if_process_is_running"vrrpd._check_if_process_is_running1   s?   
	OOW-D((d;AA$GF 9||~C b1J	112Dc2IJ66(E8<  (!34  *!56  s8}c*o.N!NO 6$$S) !78  )  		$  s$   6D7 6B7E7
EE
EEc                    [         R                  R                  (       d2  [        R                  R                  SUR                  -  5      (       d  gSnUR                  S5      nU(       a	  USU-  -  nOgUR                  S5      nU(       a	  USU-  -  nO)U R                  R                  SUR                  -  S	5        UR                  S
5      nU(       a	  USU-  -  nO*U R                  R                  SUR                  -  S5        g[        R                  < SUR                  < SU< 3n[        R                  " U5        [        R                  < SUR                  < S3nU R                  [        R                  U5      (       a)  U R                  R                  SUR                  -  5        g[        R                  " U5        g)z[up vrrpd -n -D -i $IFACE -v 1 -p 20 10.0.1.254
up ifplugd -i $IFACE -b -f -u0 -d1 -I -p -q z/sys/class/net/%sNr    r   z -v %sr   z -p %sz%s: incomplete vrrp parameters z(priority not found)r   z %sz%s: incomplete vrrp arguments z(virtual ip not found)z
 -n -D -i r#   z -i z -b -f -u0 -d1 -I -p -qz%s: ifplugd already running)ifupdownflagsflagsDRYRUNospathexistsnameget_attr_value_firstr-   warningr   	vrrpd_cmdexec_commandifplugd_cmdr:   r.   )r   ifaceobjcmdattrvals       r   _up	vrrpd._upM   sh    ##**2HMMABB//	:8W$$C//@8W$$CKK A8== P*,//0AB5'>!CKK @(-- O,.53 !!8==2,,U->->DD;;98==HI3r   c                    [         R                  R                  U5      (       ah  U R                  U5      n[         R                  R                  SU-  5      (       a/  [         R                  " [        U5      [        R                  5        g g g )Nz/proc/%s)r@   rA   rB   r*   killintsignalSIGTERM)r   pidfilenamer7   s      r   _kill_pid_from_filevrrpd._kill_pid_from_files   s\    77>>+&&((5Cww~~j#o..wws3x0 / 'r   c           	      P   UR                  S5      nU(       d  g [        R                  " [        R                  < SUR                  < 35        [        R                  " SUR                  -  5       H  n U R                  U5        M     g! [
         a@  nU R                  R                  UR                  < S[        U5      < S35         SnANSnAff = f! [
         aA  nU R                  R                  UR                  < S[        U5      < S35         SnAM  SnAff = f)zGdown ifplugd -k -i $IFACE
down kill $(cat /var/run/vrrpd_$IFACE_*.pid) r   Nz -k -i z: ifplugd down error ()z/var/run/vrrpd_%s_*.pidz: vrrpd down error ()rD   r   rG   rH   rC   r'   r-   debugstrglobrT   )r   rI   rK   epidfiles        r   _downvrrpd._downy   s     //	:	 % 1 18== B C yy!:HMM!IJG((1 K  	KK (s1v7 8	  !!$,MM3q6#; <s/   5B 7C
C6CC
D%$6D  D%c                     g r    )r   rI   ifaceobjcurrs      r   _query_checkvrrpd._query_check   s    r   )zpost-upzpre-downc                 H    [        U R                  R                  5       5      $ )z-returns list of ops supported by this module )list_run_opskeys)r   s    r   get_opsvrrpd.get_ops   s    DMM&&())r   Nc                 z    U R                   R                  U5      nU(       d  gUS:X  a
  U" XU5        gU" X5        g)as  run ethtool configuration on the interface object passed as
    argument

Args:
    **ifaceobj** (object): iface object

    **operation** (str): any of 'post-up', 'query-checkcurr',
        'query-running'
Kwargs:
    **query_ifaceobj** (object): query check ifaceobject. This is only
        valid when op is 'query-checkcurr'. It is an object same as
        ifaceobj, but contains running attribute values and its config
        status. The modules can use it to return queried running state
        of interfaces. status is success if the running state is same
        as user required state in ifaceobj. error otherwise.
Nzquery-checkcurr)rf   get)r   rI   	operationquery_ifaceobj
extra_args
op_handlers         r   run	vrrpd.run   s9    " ]]&&y1
))t~6t&r   r`   r   )__name__
__module____qualname____firstlineno____doc___modinfor   r:   rL   rT   r]   rb   rf   rh   rp   __static_attributes__r`   r   r   r   r      s    AG '9-0&M*58 &9-0%L*<)=? &;,4<*F)GIJKH28$ L1,
  "$H*'r   r   )r@   r+   rZ   rQ    ifupdown2.ifupdown.ifupdownflagsifupdownr=   #ifupdown2.ifupdownaddons.modulebaser   ifupdown2.ifupdown.ifaceifupdown2.ifupdown.utilsr   ImportErrorModuleNotFoundErrorifupdown.ifupdownflagsifupdownaddons.modulebaseifupdown.ifaceifupdown.utilsr   r`   r   r   <module>r      sX    
 	  %<<>*.V'J V' 	() %24 $%s   8 AA