Current File : //usr/lib/python3.6/site-packages/sos/report/plugins/__pycache__/microk8s.cpython-36.pyc |
3
\��h� � @ s6 d dl Z d dlZd dlmZmZ G dd� dee�ZdS )� N)�Plugin�UbuntuPluginc @ s4 e Zd ZdZdZdZd
ZdZdZdd� Z dd� Z
d S )�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.
zThe lightweight Kubernetes�microk8s� containerc s � j dd� 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 W W d Q R X W n: t k
�r� } z� j
d)|� d*|� �� W Y d d }~X nX xt|
D ]l}| }|jd+g �}x|D ]}|� d,|� �}�q�W tj
|jd-��}|jd.�}� j|� d,|� �d/|� �d� �q�W d S )0Nzsnap.microk8s.*)Zunitszaddons repo list�configzctr plugins lszctr plugins ls -dZstatus�versionz!/var/snap/microk8s/current/args/*z4/var/snap/microk8s/current/credentials/client.configc s g | ]}� j � d |� ��qS )� )�microk8s_cmd)�.0Zsubcmd)�self� �/usr/lib/python3.6/microk8s.py�
<listcomp>3 s z"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 �optsr z.leader�rzutf-8)�encodingz#Address:\s*(\d+\.\d+\.\d+\.\d+:\d+)z
.describe z
.describe_)r r r zFailed to parse z: r r r r Z
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 �optr Zfile_suffixr
)r r �setup"