o id @sXddlZddlmZddlmZdZGdddeZGdddeZGd d d eZdS) N)quote)Clusterz(/etc/pki/ovirt-engine/keys/engine_id_rsac@sleZdZdZdZdZdZgdZddZdd Z d d Z d d Z ddZ ddZ ddZddZddZdS)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)z ovirt-enginez3/usr/share/ovirt-engine/dbscripts/engine-psql.sh -c)) no-databaseFzDo not collect a database dump)clusterz'Only collect from hosts in this cluster) datacenterrz*Only collect from hosts in this datacenter)no-hypervisorsFzDo not collect from hypervisors)spm-onlyFzOnly collect from SPM host(s)cCs d|jt|f}|j|ddS)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_execrexec_primary_cmd)selfquerycmdr>/usr/lib/python3/dist-packages/sos/collector/clusters/ovirt.py _run_db_query<szovirt._run_db_querycs<|sdSgdtfdd|Dr|d|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|]}|vVqdS)Nr).0x invalid_charsrr Msz#ovirt._sql_scrub..zMWARNING: Cluster option '%s' contains invalid characters. Using '%%' instead.)anylog_warn)rvalrrr _sql_scrubDszovirt._sql_scrubcCsR|jjr#t|jj|jj|jjgs%|jtr'| t| ddSdSdSdS)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) primarylocalr"optsssh_keypasswordpassword_per_node file_exists ENGINE_KEYadd_default_ssh_key log_debugrrrr_check_for_engine_keysTs  zovirt._check_for_engine_keyscCs.d|_|ds ||_||dS)NFr)pg_pass get_option parse_db_confconf format_db_cmdr1r0rrrsetupes    z ovirt.setupcCsZ||d}||d}d||f|_|dr#|jd7_|d|jdS)NrrzSELECT 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'))r z AND spm_status = 2z%Query command for ovirt DB set to: %s)r%r3dbqueryr/)rrrrrrr6ls zovirt.format_db_cmdcCsX|drgS||j}|ddkr$|ddd}dd|DStd |d) Nr statusroutputcSsg|] }|ddqS)(r)splitstrip)rnrrr sz#ovirt.get_nodes..z&database query failed, return code: %s)r3rr8 splitlines Exception)rresnodesrrr get_nodes{s   zovirt.get_nodescCs|ds |jr |SdS)NrF)r3r5collect_databaser0rrr run_extra_cmdszovirt.run_extra_cmdc Csi}d}|jd|dd}|ddkrE|d}|D]'}zt|dd}t|dd d d }|||<WqtyBYqw|Sd S) Nz6/etc/ovirt-engine/engine.conf.d/10-setup-database.confzcat %sTr r9rr:=rrF)rrBstrr>replace IndexError)rr5engconfrDconfiglinekvrrrr4s    zovirt.parse_db_confcCsdjd|jd|jd|jd|jdd}d|jd |}|j|d d }|d D]}t|d rI|}|jjd| dd|Sq,| ddS)Nzn-k {plugin}.dbname={db} -k {plugin}.dbhost={dbhost} -k {plugin}.dbport={dbport} -k {plugin}.username={dbuser} postgresqlENGINE_DB_DATABASEENGINE_DB_HOSTENGINE_DB_PORTENGINE_DB_USER)plugindbdbhostdbportdbuserzLPGPASSWORD={} /usr/sbin/sosreport --name=postgresql --batch -o postgresql {}ENGINE_DB_PASSWORDTr r:z*sosreport-*tar*postgresql_dump/r<zFailed to gather database dumpF) formatr5rrBfnmatchr?r&manifest add_fieldr> log_error)rsos_optrdb_sosrP_pg_dumprrrrGs*     zovirt.collect_databaseN)__name__ __module__ __qualname____doc__ cluster_namepackagesr option_listrr%r1r7r6rFrHr4rGrrrrrs  rc@s eZdZdZdZdZddZdS)rhvzRed Hat Virtualization)rhevmrhvmcCs$|j|jjkr dS|drdSdS)Nmanagerzovirt-node-ng-nodectlrhvhrhelh)addressr& is_installed)rnoderrrset_node_labels  zrhv.set_node_labelN)rhrirjrlrm sos_presetrxrrrrros  roc@s0eZdZdZdZddiZdZddZdd Zd S) rhhi_virtz6Red Hat Hyperconverged Infrastructure - Virtualization)glusterz gluster.dumponrocCs|jdo |S)Nrq)r&rv_check_for_rhhivr0rrr check_enabledszrhhi_virt.check_enabledcCs2|d}|ddkr|dddkSdS)Nz+SELECT count(server_id) FROM gluster_serverr9rr:r;0F)rrBr?)rretrrrr}s  zrhhi_virt._check_for_rhhivN) rhrirjrl sos_pluginssos_plugin_optionsryr~r}rrrrrzs rz) rapipesrsos.collector.clustersrr-rrorzrrrrs  #