
    HmdD)                         d dl mZ d dlmZ d dlZd dlZdZdZdZ	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd ZdS )    )print_function)lfN         c                     ddl m} ddlm}  |t          j        d          | j                   d|_        t          j        t          d| j                             d S )Nr   )set_monitor_status)rconf
state-fileFzMonitor Status Change)status)
gsyncdstatusr	   r
   gconfgetr   log_exitlogginginfor   )argsr	   r
   s      @/usr/lib/x86_64-linux-gnu/glusterfs/python/syncdaemon/subcmds.pysubcmd_monitor_statusr      sr    //////uy..<<<ENL+DK@@@AAAAA    c                 T   ddl m} | j                            dd          }| j                            dd          } |t          j        d          d| j        d||t          j        d                    }t          j        dd          }|                    || j	        	           d S )
Nr   )GeorepStatus: zssh://r   pid-file
checkpoint)checkpoint_timejson_output)
r   r   primaryreplace	secondaryr   r   
local_pathprint_statusjson)r   r   primary_namesecondary_databrick_statusr   s         r   subcmd_statusr(       s    ))))))<''R00L^++Hb99N<	, 7 7 " $ " , . %	* 5 57 7L ia00Oo*.)  5 5 5 5 5r   c                 &   dd l }ddlm}m}m} | j        rdnd}|                    |           |                                  |d| j                  }| j	        
                    d          \  }} |||          }	|                     ||	          S )Nr   GLUSTERSSHPopenFT	localhost::)monitorresourcer+   r,   r-   debugstartupinit_errhandlerr   r!   split)
r   r0   r+   r,   r-   	go_daemonlocalsecondaryhostsecondaryvolremotes
             r   subcmd_monitorr;   2   s    NNN,,,,,,,,,,-IOOI	GK..E"&."6"6t"<"<M<S--F??5&)))r   c                 .    t          j        d           d S )NzAble to spawn gsyncd.py)r   r   )r   s    r   subcmd_verify_spawningr=   ?   s    L*+++++r   c                 J   dd l }dd l}ddlm}m}m} |                                 |                    | j        |j        |j	                    |d| j
                  }| j                            d          \  }}d|vr| j        }	n%|                    d          d         d| j        }	 ||	|          }
|
                                 |                                 t!          j        d           |                    | j                   |                    |
           d S )Nr   r*   r.   r/   @z6Worker spawn successful. Acknowledging back to monitor)osfcntlr1   r+   r,   r-   r4   feedback_fdF_SETFD
FD_CLOEXECr   r!   r5   resource_remoteconnect_remoteconnectr   r   closeservice_loop)r   r@   rA   r+   r,   r-   r7   secondary_urlr9   r8   r:   s              r   subcmd_workerrK   C   s=   IIILLL,,,,,,,,,,		KK %-1ABBBGK..E"&."6"6t"<"<M<
-,#0#6#6s#;#;A#>#>#>@T@TUS--F
	MMOOOLIJJJHHT	vr   c                     ddl m}m} |                                 | j                            d          d         } |d|          }|                                 |                                 d S )Nr   )r+   r-   r/   r.   )r1   r+   r-   r4   r!   r5   rG   rI   )r   r+   r-   r9   r7   s        r   subcmd_secondaryrN   Y   s|    ''''''''	>''--b1LGK..E	MMOOO	r   c           
         ddl m}m} dd lmc m} t          |d          r|j        nt          }ddd| j	        z   dd| j
        g}| j        r|                    d	            ||dd ||d
          }|                                \  }}|j        dk    r6t          j        t#          d| j
        | j	        |j                             dS |                    |          }	|	                    d          j        dk    rIt          j        t#          d| j
        | j	        |	                    d          j                             dS 	 |	                    d          j        }
nP# |t*          t,          f$ r;}t          j        t#          d| j
        | j	        |                     d}
Y d }~nd }~ww xY wt/          |
           d S )Nr   )r-   PIPE
ParseErrorglusterz--xmlz--remote-host=volumer   z--inet6T)bufsizestdinstdoutstderruniversal_newlineszUVolume info failed, unable to get volume uuid of secondaryvol, returning empty string)r9   r8   errorr   opRet0zAUnable to get volume uuid of secondaryvol, returning empty stringopErrstrzvolInfo/volumes/volume/idzEParsing failed to volume uuid of secondaryvol, returning empty string)
subprocessr-   rP   xml.etree.ElementTreeetreeElementTreehasattrrQ   SyntaxErrorhostvolnameinet6appendcommunicate
returncoder   r   r   
fromstringfindtextAttributeError
ValueErrorprint)r   r-   rP   XETrQ   cmdpovixerrvivoluuides               r   subcmd_voluuidgetrw   d   s'   &&&&&&&&'''''''''#*3#=#=N;Jg/$);VT\+C z 

9	sA$t"&
( 
( 
(B ~~HC	}R 1 &*\&*i m- - - 	. 	. 	. r			B	www##R 1%)\&*i ggj116	8 8 8 	9 	9 	9
 r''566;
3   R 1%)\&*i	! ! ! 	" 	" 	"
  
'NNNNNs   E" "F/41F**F/c                     dd l }ddlm} ddlm} dd l}	 |                    |            d S # t          t          f$ r5 |	                                d         j        |k    rY d S  |d| z            w xY w)Nr   )ENOENT)GsyncdError   zUnlink error: %s)
r@   errnory   
syncdutilsrz   sysunlinkOSErrorIOErrorexc_info)pathr@   ry   rz   r~   s        r   _unlinkr      s    III&&&&&&JJJ9
		$W 9 9 9<<>>!"f,,DD+047888	9s   - 4A3$A3c                    dd l }dd l}dd l}dd l}ddlm}m} dd l}ddlm	}m
}	m}
 dd l} |j        d            |j        dd           }g }|                     |j        d                     	 |                     |j        d                     nW# t"          t$          f$ rC |                                d         j        |k    rn |d	 |j        d          z            Y nw xY w	 |                     |j        d
                     nW# t"          t$          f$ rC |                                d         j        |k    rn |d	 |j        d
          z            Y nw xY w|D ],}|                    |dz             D ]}t)          |           -| j        rZ|rX| j        D ]P}|dk    rH |
|	j        ||dz   |                    ddd          f||g            |
|	j        ||dz   f||g           Qd S )Nr   )ry   ENODATA)rz   Xattr
errno_wrapzgeo-replication deletezstime-xattr-prefixr   zgeorep-session-working-dirr{   z$Error while removing working dir: %szworking-dir*r   z.stimez!IIz.entry_stime)r   shutilglobr~   r|   ry   r   structr}   rz   r   r   gsyncdconfigr   r   rf   rmtreer   r   r   r   reset_sync_timepaths	lsetxattrpacklremovexattr)r   r   r   r   r~   ry   r   r   rz   r   r   r   stime_xattr_prefixcleanup_pathsr   fps                    r   subcmd_deleter      s   NNNMMMKKKJJJ%%%%%%%%MMM9999999999    GL)*** ##7>> M:..///9iei <==>>>>W 9 9 9<<>>!"f,,+6	67789 9 9 D9*iei..////W * * *<<>>!"f,,+6	-(()* * * D*   4#:&& 	 	AAJJJJ	  . 2 . 	. 	.ABww 
5?1H<"KKq!446"G,. . . 
5-1NBC"G,. . . Fs&   2#B AC*)C*.#D AE&%E&Fc                     |}t          |t                    r!t          |                                          }|rt	          |           d S |r|                     dd          } t	          | d|           d S )N-_r   )
isinstanceboolstrlowerrn   r    )namevalue
only_valueuse_underscorevals        r   print_configr      s    
C% !%jj   'c




 	*<<S))D$$$$&&&&&r   c                 .    |                      dd          S )Nr   r   )r    )r   s    r   config_name_formatr      s    ;;sC   r   c           	         dd l }dd l}t          j        | j        d          }| j        |                    t          | j                  d           }|<|j        	                    d| j        z             |
                    t                     t          | j        |d         | j        | j                   d S | j        rg }t          |          D ]W}||         }|                    |t#          |d                   t#          |d                   |d         |d	         d
           Xt%          |                    |                     d S t          |          D ]%}t          |||         d         | j                   &d S )Nr   T)show_defaultsshow_non_configurableInvalid config name "%s"
r   )r   r   defaultconfigurablemodified)r   r   r   r   r   )r   )r~   r$   r   getallr   r   r   r   rW   writeexitERROR_CONFIG_INVALIDr   r   r   sortedrf   r   rn   dumps)r   r~   r$   
all_configr   outkvs           r   subcmd_config_getr      s   JJJKKKD,>48: : :Jynn/	::DAA;J;diGHHHHH)***TYG$($7	9 	9 	9 	9y 
## 	 	A1AJJQwZq|,, !. 1jM      	tzz#   J 9 9Q
1g.$($7	9 	9 	9 	9 	99 9r   c                    dd l }	 t          j        t          | j                  | j        d           d S # t          j        $ r t          j        t          | j                  d           }|<|j        	                    d| j        z             |
                    t                     |j        	                    d| j        z             |
                    t                     Y d S t          j        $ rI |j        	                    d| j        d| j        d           |
                    t                     Y d S w xY w)	Nr   F)r   with_conffiler   Not configurable "%s"
Invalid config value "="
)r~   r   checkr   r   r   GconfNotConfigurabler   rW   r   r   r   ERROR_CONFIG_NOT_CONFIGURABLEGconfInvalidValueERROR_CONFIG_INVALID_VALUEr   r~   cnf_vals      r   subcmd_config_checkr     s[   JJJ-&ty11"'	) 	) 	) 	) 	) 	)% 0 0 0).ty994@@?J;diGHHHHH)*** 	
4ty@AAA.//////" - - -
tyyy?CzzzK 	L 	L 	L+,,,,,,-s   .6 B0E )AE ?E c                    dd l }	 t          j        t          | j                  | j                   d S # t          j        $ r t          j        t          | j                  d           }|<|j        	                    d| j        z             |
                    t                     |j        	                    d| j        z             |
                    t                     Y d S t          j        $ rI |j        	                    d| j        d| j        d           |
                    t                     Y d S w xY w)Nr   r   r   r   r   r   )r~   r   	setconfigr   r   r   r   r   rW   r   r   r   r   r   r   r   s      r   subcmd_config_setr   .  sI   JJJ-*4955tzBBBBB% 0 0 0).ty994@@?J;diGHHHHH)*** 	
4ty@AAA.//////" - - -
tyyy?CzzzK 	L 	L 	L+,,,,,,-s   ,4 B0D>'AD>=D>c                    dd l }	 t          j        t          | j                             d S # t          j        $ r t          j        t          | j                  d           }|<|j                            d| j        z             |	                    t                     |j                            d| j        z             |	                    t                     Y d S w xY w)Nr   r   r   )r~   r   resetconfigr   r   r   r   rW   r   r   r   r   r   s      r   subcmd_config_resetr   B  s    JJJ
0,TY7788888% 0 0 0).ty994@@?J;diGHHHHH)*** 	
4ty@AAA.//////0s   &. B0C"!C")FF)
__future__r   r}   r   r   r   r   r   r   r   r   r(   r;   r=   rK   rN   rw   r   r   r   r   r   r   r   r    r   r   <module>r      sJ   & % % % % %               ! B B B5 5 5$
* 
* 
*, , ,  ,  , , ,^9 9 9= = =@' ' ' '! ! !"9 "9 "9J- - -*- - -(0 0 0 0 0r   