Current File : //usr/lib/python3.6/site-packages/sos/report/plugins/__pycache__/microk8s.cpython-36.pyc
3

\��h��@s6ddlZddlZddlmZmZGdd�dee�ZdS)�N)�Plugin�UbuntuPluginc@s4eZdZdZdZdZd
ZdZdZdd�Z	dd�Z
d	S)�Microk8saThe 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.
    zThe lightweight Kubernetes�microk8s�	containercs�jdd�ddddddg}�jd	d
g��j�fdd�|D��d
}|�d�}�jd|�d��d
}�j|dd��j|�d�|�d�|�d�g�d}|�d�}|�d�}|�d�}|�d|�d|�d|�d�}	ddd�ddgdd �d!d!d�g}
ybt|d"d#d$��J}|j�}tjd%|�}
x.|
D]&}|
jd&|��d'|��dgd(���q WWdQRXWn:t	k
�r�}z�j
d)|�d*|���WYdd}~XnXxt|
D]l}|	}|jd+g�}x|D]}|�d,|��}�q�Wtj
|jd-��}|jd.�}�j|�d,|��d/|��d��q�WdS)0Nzsnap.microk8s.*)Zunitszaddons repo list�configzctr plugins lszctr plugins ls -dZstatus�versionz!/var/snap/microk8s/current/args/*z4/var/snap/microk8s/current/credentials/client.configcsg|]}�j�d|���qS)� )�microk8s_cmd)�.0Zsubcmd)�self��/usr/lib/python3.6/microk8s.py�
<listcomp>3sz"Microk8s.setup.<locals>.<listcomp>z1/var/snap/microk8s/current/var/kubernetes/backendz/cluster.crtzopenssl x509 -in z -noout -datesZls_microk8s_dqlite_dir)Zsuggest_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�optsrz.leader�rzutf-8)�encodingz#Address:\s*(\d+\.\d+\.\d+\.\d+:\d+)z
.describe z
.describe_)rrrzFailed to parse z: rr	rrZ
microk8s_sql_)Zadd_journalZ
add_copy_specZadd_cmd_outputZadd_dir_listing�open�read�re�findall�append�	ExceptionZ	add_alert�get�json�dumps)rZmicrok8s_subcmdsZcrt_dirZ
dqlite_crtZdb_pathZ
dqlite_binZcert�keyZserversZ
dqlite_cmdZqueriesZcluster_definitionZclusterZnodesZnode�eZquery_entryZsql_cmdr�optrZfile_suffixr
)rr�setup"st





 (


zMicrok8s.setupcCsDd}|j|j|d�ddddg}ddj|��d	�}|jd
|d�dS)Nz((certificate-authority-data:|token:)\s.*z\1 "**********"zcertificate-authority-datazclient-certificate-datazclient-key-data�tokenz(^\s*(�|z
)\s*:\s*)(.*)z4/var/snap/microk8s/current/credentials/client.configz\1*********)Zdo_cmd_output_subr
�joinZdo_path_regex_sub)rZrsubZprotect_keysZ	key_regexr
r
r�postprocszMicrok8s.postprocN)r)r)�__name__�
__module__�__qualname__�__doc__Z
short_descZplugin_nameZprofilesZpackagesr
r!r%r
r
r
rrs]r)rrZsos.report.pluginsrrrr
r
r
r�<module>s