o
    O6ufè  ã                   @   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 informationÚproxmox)z
proxmox-veúoutput-formatsz@List of output formats to use for the commands separated by ":".Útext)ÚdescÚdefaultc                    sR   |   d¡ d¡‰ g d¢}g }|D ]
}| |  |¡¡ q|  ‡ fdd„|D ƒ¡ d S )Nr   ú:)zcluster/resourceszcluster/config/nodeszcluster/optionsznodes/:id/statusznodes/:id/storageznodes/:id/networkÚpoolsÚstoragezstorage/:sidzcluster/ceph/statuszcluster/ceph/metadatazcluster/ceph/flagsc              	      s8   g | ]}ˆ 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©Úoutput_formatsr   ú</usr/lib/python3/dist-packages/sos/report/plugins/proxmox.pyÚ
<listcomp>;   s    üýÿÿz!Proxmox.setup.<locals>.<listcomp>)Ú
get_optionÚsplitÚextendÚbuild_cmd_pathsÚadd_cmd_output)ÚselfÚcommandsÚ	cmd_pathsÚcommandr   r   r   Úsetup$   s   ýzProxmox.setupc           
   
   C   sÈ   |  d¡}g }tdd„ t|ƒD ƒdƒ}|durZd |d|… ¡}d ||d d… ¡}|  d|› d�¡}|d d	krXt |d
 ¡}|D ]}	| |  |› d|	d › d|› �¡¡ qC|S | 	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 jsonÚstatusr   ÚoutputÚname)
r   ÚnextÚ	enumerateÚjoinÚexec_cmdÚjsonÚloadsr   r   Úappend)
r   Ú	base_pathÚpartsÚpathsÚid_indexÚpathÚtrailing_pathÚresultsÚchildrenÚchildr   r   r   r   B   s(   

ÿÿÿÿzProxmox.build_cmd_pathsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
short_descÚplugin_nameÚpackagesr   Úoption_listr!   r   r   r   r   r   r      s    ýÿr   )r/   Úsos.report.pluginsr   r   r   r   r   r   r   r   Ú<module>   s   	