
    ([Qh                     <    d dl Z d dlZd dlmZmZ  G d dee      Zy)    N)PluginUbuntuPluginc                   0    e Zd ZdZdZdZdZdZdZd Z	d Z
y)	Microk8sa  The Microk8s plugin collects the current status of the microk8s
    snap on a Ubuntu machine.

    It will collect logs from journald related to the snap.microk8s
    units as well as run microk8s commands to retrieve the configuration,
    status, version and loaded plugins.
    zThe lightweight Kubernetesmicrok8s)	container)r   c                    | j                  d       g d}| j                  d       | j                  |D cg c]  }| j                   d|  c}       d}| d}| j                  d| d	       d}| j	                  |d
       | j                  | d| d| dg       d}| d}| d}| d}	| d| d| d|	 d}
dddddgdddddg}	 t        |	dd      5 }|j                         }t        j                  d|      }|D ]  }|j                  d| d | dgd!         	 d d d        |D ]t  }|
}|j                  d$g       }|D ]	  }| d| } t        j                  |j                  d%            }|j                  d&      }| j                  | d| d'|        v y c c}w # 1 sw Y   xY w# t        $ r!}| j                  d"|	 d#|        Y d }~d }~ww xY w)(Nzsnap.microk8s.*)units)zaddons repo listconfigzctr plugins lszctr plugins ls -dstatusversion4/var/snap/microk8s/current/credentials/client.config z1/var/snap/microk8s/current/var/kubernetes/backendz/cluster.crtzopenssl x509 -in z -noout -datesls_microk8s_dqlite_dir)suggest_filenamez
/info.yamlz/cluster.yamlz/failure-domainz!/snap/microk8s/current/bin/dqlitez/cluster.keyz -c z -k z -s file://z k8sz.cluster)querysuggested_file_suffixz-f jsonz.cluster_-f_json)r   optsr   z.leaderrzutf-8)encodingz#Address:\s*(\d+\.\d+\.\d+\.\d+:\d+)z
.describe z
.describe_)r   r   r   zFailed to parse z: r   r   r   microk8s_sql_)add_journaladd_copy_specadd_cmd_outputmicrok8s_cmdadd_dir_listingopenreadrefindallappend	Exception	add_alertgetjsondumps)selfmicrok8s_subcmdssubcmdcrt_dir
dqlite_crtdb_path
dqlite_bincertkeyservers
dqlite_cmdqueriescluster_definitionclusternodesnodeequery_entrysql_cmdr   optr   file_suffixs                          =/usr/lib/python3/dist-packages/sos/report/plugins/microk8s.pysetupzMicrok8s.setup"   s   01
 	B	
 	:J
06t  !6(+
 	 Fy-

|>:	
 F 	5 	 	

 	iz"i}%i'
 	 9
,'	&I]+"|4vT#k'$O
 $)3
 $"); #)2
 	>gsW5 9K,113

:G " DNN#-dV!43=dV1D!*$   # 	K G??62.D -$IQse,- JJ{w78E%//*ABK)1UG$#0!>   	A
`   	>NN-gYb<==	>s6   F/G  "A
F4-G  4F=9G   	G*	G%%G*c                     d}| j                  | j                  |d       g d}ddj                  |       d}| j                  d|d       y )	Nz((certificate-authority-data:|token:)\s.*z\1 "**********")zcertificate-authority-datazclient-certificate-datazclient-key-datatokenz(^\s*(|z)\s*:\s*)(.*)r   z\1*********)do_cmd_output_subr   joindo_path_regex_sub)r'   rsubprotect_keys	key_regexs       r<   postproczMicrok8s.postproc~   sW    :t00$8JK
 chh|45]C	B~	
    N)__name__
__module____qualname____doc__
short_descplugin_nameprofilespackagesr   r=   rG    rH   r<   r   r      s.     .JKHHLZx
rH   r   )r%   r   sos.report.pluginsr   r   r   rQ   rH   r<   <module>rS      s      	 3}
v| }
rH   