U
    -_g                     @   s2   d dl Z d dlmZmZmZ G dd deeZdS )    N)PluginDebianPlugin	PluginOptc                   @   s<   e Zd ZdZdZdZdZeddddgZd	d
 Z	dd Z
dS )Proxmoxz
    This plugin will capture information about the system's
    Proxmox Virtualization Environment.

    It will collect information about the cluster, nodes, pools and
    storage from the Proxmox API.
    zProxmox cluster informationZproxmox)z
proxmox-veoutput-formatsz@List of output formats to use for the commands separated by ":".text)Zdescdefaultc                    sf   |  dd ddddddd	d
ddddg}g }|D ]}|| | q4|  fdd|D  d S )Nr   :zcluster/resourceszcluster/config/nodeszcluster/optionsznodes/:id/statusznodes/:id/storageznodes/:id/networkZpoolsZstoragezstorage/:sidzcluster/ceph/statuszcluster/ceph/metadatazcluster/ceph/flagsc              	      s8   g | ]0} D ]&}d | d|dkr$dnd d| qqS )z
pvesh get  r   z
--noborder z --output-format  ).0cmdformatZoutput_formatsr   </usr/lib/python3/dist-packages/sos/report/plugins/proxmox.py
<listcomp>;   s    z!Proxmox.setup.<locals>.<listcomp>)Z
get_optionsplitextendbuild_cmd_pathsZadd_cmd_output)selfZcommandsZ	cmd_pathsZcommandr   r   r   setup$   s(    zProxmox.setupc           
   
   C   s   | d}g }tdd t|D d}|dk	rd|d| }d||d d }| d| d}|d d	krt|d
 }|D ](}	|| | d|	d  d|  qn|	d| |S )z
        Build command paths,
        replacing dynamic attributes with data from the API

        :param base_path: The base path to build from
        :type base_path: str

        :return: A list of paths
        /c                 s   s    | ]\}}| d r|V  qdS )r	   N)
startswith)r   ipartr   r   r   	<genexpr>O   s    
z*Proxmox.build_cmd_paths.<locals>.<genexpr>N   z	pvesh ls z --output-format jsonZstatusr   outputname)
r   next	enumeratejoinZexec_cmdjsonloadsr   r   append)
r   	base_pathpartspathsZid_indexpathZtrailing_pathZresultsZchildrenZchildr   r   r   r   B   s&    

zProxmox.build_cmd_pathsN)__name__
__module____qualname____doc__Z
short_descZplugin_nameZpackagesr   Zoption_listr   r   r   r   r   r   r      s   r   )r#   Zsos.report.pluginsr   r   r   r   r   r   r   r   <module>
   s   