Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/sos/collector/clusters/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/sos/collector/clusters/__pycache__/ovirt.cpython-36.pyc

3

�f��@sXddlZddlmZddlmZdZGdd�de�ZGdd�de�ZGd	d
�d
e�ZdS)�N)�quote)�Clusterz(/etc/pki/ovirt-engine/keys/engine_id_rsac@sreZdZdZdZd$ZdZd%d&d'd(d)gZdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd �Zd!d"�Zd#S)*�ovirta�
    This cluster profile is for the oVirt/RHV project which provides for a
    virtualization cluster built ontop of KVM.

    Nodes enumerated will be hypervisors within the envrionment, not virtual
    machines running on those hypervisors. By default, ALL hypervisors within
    the environment are returned. This may be influenced by the 'cluster' and
    'datacenter' cluster options, which will limit enumeration to hypervisors
    within the specific cluster and/or datacenter. The spm-only cluster option
    may also be used to only collect from hypervisors currently holding the
    SPM role.

    Optionally, to only collect an archive from manager and the postgresql
    database, use the no-hypervisors cluster option.

    By default, a second archive from the manager will be collected that is
    just the postgresql plugin configured in such a way that a dump of the
    manager's database that can be explored and restored to other systems will
    be collected.

    The ovirt profile focuses on the upstream, community ovirt project.

    The rhv profile is for Red Hat customers running RHV (formerly RHEV).

    The rhhi_virt profile is for Red Hat customers running RHV in a
    hyper-converged setup and enables gluster collections.
    zCommunity oVirt�ovirt-enginez3/usr/share/ovirt-engine/dbscripts/engine-psql.sh -c�no-databaseF�Do not collect a database dump�cluster��'Only collect from hosts in this cluster�
datacenter�*Only collect from hosts in this datacenter�no-hypervisors�Do not collect from hypervisors�spm-only�Only collect from SPM host(s)cCs d|jt|�f}|j|dd�S)z�
        Wrapper for running DB queries on the manager. Any scrubbing of the
        query should be done _before_ passing the query to this method.
        z%s %sT)�	need_root)�db_execr�exec_primary_cmd)�selfZquery�cmd�r�/usr/lib/python3.6/ovirt.py�
_run_db_query<szovirt._run_db_querycsF|sdSdddddddg�t�fd	d
�|D��rB|jd|�dS|S)z�
        Manually sanitize SQL queries since we can't leave this up to the
        driver since we do not have an actual DB connection
        �%��\�
�
��"�'c3s|]}|�kVqdS)Nr)�.0�x)�
invalid_charsrr�	<genexpr>Msz#ovirt._sql_scrub.<locals>.<genexpr>zMWARNING: Cluster option '%s' contains invalid characters. Using '%%' instead.)�anyZlog_warn)r�valr)r#r�
_sql_scrubDszovirt._sql_scrubcCsF|jjrBt|jj|jj|jjg�sB|jjt�rB|j	t�|j
d�dS)a
        Checks for the presence of the VDSM ssh keys the manager uses for
        communication with hypervisors.

        This only runs if we're locally on the RHV-M, *and* if no ssh-keys are
        called out on the command line, *and* no --password option is given.
        z]Found engine SSH key. User command line does not specify a key or password, using engine key.N)�primaryZlocalr%ZoptsZssh_keyZpasswordZpassword_per_nodeZfile_exists�
ENGINE_KEYZadd_default_ssh_key�	log_debug)rrrr�_check_for_engine_keysTs
zovirt._check_for_engine_keyscCs.d|_|jd�s|j�|_|j�|j�dS)NFzno-database)Zpg_pass�
get_option�
parse_db_conf�conf�
format_db_cmdr+)rrrr�setupes


zovirt.setupcCsZ|j|jd��}|j|jd��}d||f|_|jd�rF|jd7_|jd|j�dS)Nrrz�SELECT host_name from vds where cluster_id in (select cluster_id FROM cluster WHERE name like '%s' and storage_pool_id in (SELECT id FROM storage_pool WHERE name like '%s'))zspm-onlyz AND spm_status = 2z%Query command for ovirt DB set to: %s)r'r,�dbqueryr*)rrrrrrr/ls
zovirt.format_db_cmdcCs\|jd�rgS|j|j�}|ddkrH|dj�dd
�}dd�|D�Std	|d��dS)Nzno-hypervisors�statusr�output��cSsg|]}|jd�dj��qS)�(r)�split�strip)r!�nrrr�
<listcomp>�sz#ovirt.get_nodes.<locals>.<listcomp>z&database query failed, return code: %s���)r,rr1�
splitlines�	Exception)r�resZnodesrrr�	get_nodes{s
zovirt.get_nodescCs|jd�r|jr|j�SdS)Nzno-databaseF)r,r.�collect_database)rrrr�
run_extra_cmd�szovirt.run_extra_cmdcCs�i}d}|jd|dd�}|ddkr�|dj�}xZ|D]R}y8t|jd�d�}t|jd�d	jd
d��}|||<Wq8tk
r�Yq8Xq8W|SdS)
Nz6/etc/ovirt-engine/engine.conf.d/10-setup-database.confzcat %sT)rr2rr3�=r5rr	F)rr<�strr7�replace�
IndexError)rr.Zengconfr>�config�line�k�vrrrr-�s

zovirt.parse_db_confcCs�d}d|�d|jd�d|�d|jd�d|�d|jd	�d|�d
|jd��}d|jd
�d|��}|j|dd�}xF|dj�D]6}tj|d�r�|j�}|jjjd|jd�d�|Sq�W|j	d�dS)NZ
postgresqlz-k z.dbname=ZENGINE_DB_DATABASEz -k z.dbhost=ZENGINE_DB_HOSTz.dbport=ZENGINE_DB_PORTz.dbuser=ZENGINE_DB_USERzPGPASSWORD=ZENGINE_DB_PASSWORDz> /usr/sbin/sos report --name=postgresql --batch -o postgresql T)rr3z*sosreport-*tar*Zpostgresql_dump�/r5zFailed to gather database dumpFr;)
r.rr<�fnmatchr8r(ZmanifestZ	add_fieldr7Z	log_error)rZpluginZsos_optrZdb_sosrGZ_pg_dumprrrr@�sL

zovirt.collect_databaseN)r)rFr)rr	r
)rr	r)r
Fr)rFr)�__name__�
__module__�__qualname__�__doc__�cluster_name�packagesrZoption_listrr'r+r0r/r?rAr-r@rrrrrs$rc@s eZdZdZdZdZdd�ZdS)�rhvzRed Hat Virtualization�rhevm�rhvmcCs(|j|jjkrdS|jd�r dSdSdS)NZmanagerzovirt-node-ng-nodectlZrhvhZrhelh)Zaddressr(�is_installed)rZnoderrr�set_node_label�s

zrhv.set_node_labelN)rSrT)rLrMrNrPrQ�
sos_presetrVrrrrrR�srRc@s0eZdZdZdZddiZdZdd�Zdd	�Zd
S)�	rhhi_virtz6Red Hat Hyperconverged Infrastructure - Virtualization�glusterzgluster.dumpZonrRcCs|jjd�o|j�S)NrT)r(rU�_check_for_rhhiv)rrrr�
check_enabled�szrhhi_virt.check_enabledcCs2|jd�}|ddkr.|dj�dj�dkSdS)Nz+SELECT count(server_id) FROM gluster_serverr2rr3r4�0F)rr<r8)r�retrrrrZ�s
zrhhi_virt._check_for_rhhivN)rY)	rLrMrNrPZsos_pluginsZsos_plugin_optionsrWr[rZrrrrrX�srX)	rKZpipesrZsos.collector.clustersrr)rrRrXrrrr�<module>s!

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists