3 ܓi@sXddlZddlmZddlmZdZGdddeZGdddeZGd d d eZdS) N)quote)Clusterz(/etc/pki/ovirt-engine/keys/engine_id_rsac@sreZdZdZdZd$ZdZd%d&d'd(d)gZddZddZ ddZ ddZ ddZ ddZ ddZdd 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-databaseFDo not collect a database dumpcluster'Only collect from hosts in this cluster datacenter*Only collect from hosts in this datacenterno-hypervisorsDo not collect from hypervisorsspm-onlyOnly collect from SPM host(s)cCs"|jdt|}|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.  T) need_root)db_execrexec_primary_cmd)selfZquerycmdr/usr/lib/python3.6/ovirt.py _run_db_query<szovirt._run_db_querycsJ|sdSdddddddgtfd d |DrF|jd |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|]}|kVqdS)Nr).0x) invalid_charsrr Msz#ovirt._sql_scrub..zWARNING: Cluster option 'z2' contains invalid characters. Using '%%' instead.)anyZlog_warn)rvalr)r$r _sql_scrubDszovirt._sql_scrubcCsF|jjrBt|jj|jj|jjgsB|jjtrB|j t|j ddS)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_nodeZ file_exists ENGINE_KEYZadd_default_ssh_key log_debug)rrrr_check_for_engine_keysTs    zovirt._check_for_engine_keyscCs.d|_|jds|j|_|j|jdS)NFz no-database)Zpg_pass get_option parse_db_confconf format_db_cmdr,)rrrrsetupes   z ovirt.setupcCsb|j|jd}|j|jd}d|d|d|_|jdrL|jd7_|jd|jdS) Nrr z_SELECT host_name from vds where cluster_id in (select cluster_id FROM cluster WHERE name like 'zG' and storage_pool_id in (SELECT id FROM storage_pool WHERE name like 'z'))zspm-onlyz AND spm_status = 2z#Query command for ovirt DB set to: )r(r-dbqueryr+)rrr rrrr0ls  zovirt.format_db_cmdcCs^|jdrgS|j|j}|ddkrH|djdd }dd|DStd |ddS) Nzno-hypervisorsstatusroutputcSsg|]}|jddjqS)(r)splitstrip)r"nrrr sz#ovirt.get_nodes..z$database query failed, return code: )r-rr2 splitlines Exception)rresZnodesrrr get_nodes{s   zovirt.get_nodescCs|jd r|jr|jSdS)Nz no-databaseF)r-r/collect_database)rrrr run_extra_cmdszovirt.run_extra_cmdc Csi}d}|jd|dd}|ddkr|dj}xZ|D]R}y8t|jdd}t|jdd jd d }|||<Wq:tk rYq:Xq:W|Sd S) Nz6/etc/ovirt-engine/engine.conf.d/10-setup-database.confzcat T)rr3rr4=r6r r F)rr=strr8replace IndexError)rr/Zengconfr?configlinekvrrrr.s     zovirt.parse_db_confcCsd}d|d|jdd|d|jdd|d|jd d|d |jd }d |jd d|}|j|dd}xF|djD]6}tj|dr|j}|jjjd|jdd|SqW|j ddS)NZ postgresqlz-k z.dbname=ZENGINE_DB_DATABASEz -k z.dbhost=ZENGINE_DB_HOSTz.dbport=ZENGINE_DB_PORTz.dbuser=ZENGINE_DB_USERz PGPASSWORD=ZENGINE_DB_PASSWORDz> /usr/sbin/sos report --name=postgresql --batch -o postgresql T)rr4z*sosreport-*tar*Zpostgresql_dump/r6zFailed to gather database dumpFr<) r/rr=fnmatchr9r)ZmanifestZ add_fieldr8Z log_error)rZpluginZsos_optrZdb_sosrHZ_pg_dumprrrrAsL   zovirt.collect_databaseN)r)rFr)rr r )r r r )r Fr)rFr)__name__ __module__ __qualname____doc__ cluster_namepackagesrZ option_listrr(r,r1r0r@rBr.rArrrrrs$ rc@s eZdZdZdZdZddZdS)rhvzRed Hat VirtualizationrhevmrhvmcCs$|j|jjkrdS|jdr dSdS)NZmanagerzovirt-node-ng-nodectlZrhvhZrhelh)Zaddressr) is_installed)rZnoderrrset_node_labels  zrhv.set_node_labelN)rTrU)rMrNrOrQrR sos_presetrWrrrrrSsrSc@s0eZdZdZd ZddiZdZddZdd Zd S) rhhi_virtz6Red Hat Hyperconverged Infrastructure - Virtualizationglusterz gluster.dumpZonrScCs|jjdo|jS)NrU)r)rV_check_for_rhhiv)rrrr check_enabledszrhhi_virt.check_enabledcCs2|jd}|ddkr.|djdjdkSdS)Nz+SELECT count(server_id) FROM gluster_serverr3rr4r50F)rr=r9)rretrrrr[s  zrhhi_virt._check_for_rhhivN)rZ) rMrNrOrQZ sos_pluginsZsos_plugin_optionsrXr\r[rrrrrYs rY) rLZshlexrZsos.collector.clustersrr*rrSrYrrrr s