From fb8c2af36672b5868f504bae0704392f9e9b44a5 Mon Sep 17 00:00:00 2001
From: Jake Hunsaker <jhunsake@redhat.com>
Date: Fri, 12 Apr 2019 14:45:01 -0400
Subject: [PATCH 1/3] [clusters] Add a cluster_name class member for better
identification
Adds a cluster_name class member to Cluster() so that clusters may
specify a well-defined name beyond the name/acronym used to enable the
cluster manually.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
---
soscollector/clusters/__init__.py | 9 +++++++++
soscollector/sos_collector.py | 3 +--
soscollector/sosnode.py | 1 -
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/soscollector/clusters/__init__.py b/soscollector/clusters/__init__.py
index b9d2418..c1bd360 100644
--- a/soscollector/clusters/__init__.py
+++ b/soscollector/clusters/__init__.py
@@ -26,6 +26,7 @@ class Cluster(object):
sos_plugins = []
sos_plugin_options = {}
sos_preset = ''
+ cluster_name = None
def __init__(self, config):
'''This is the class that cluster profile should subclass in order to
@@ -50,6 +51,14 @@ class Cluster(object):
self.options = []
self._get_options()
+ @classmethod
+ def name(cls):
+ '''Returns the cluster's name as a string.
+ '''
+ if cls.cluster_name:
+ return cls.cluster_name
+ return cls.__name__.lower()
+
def _get_options(self):
'''Loads the options defined by a cluster and sets the default value'''
for opt in self.option_list:
diff --git a/soscollector/sos_collector.py b/soscollector/sos_collector.py
index fee48ab..54410a2 100644
--- a/soscollector/sos_collector.py
+++ b/soscollector/sos_collector.py
@@ -554,8 +554,7 @@ this utility or remote systems that it connects to.
break
self.config['cluster'] = cluster
- name = str(cluster.__class__.__name__).lower()
- self.config['cluster_type'] = name
+ self.config['cluster_type'] = cluster.name()
self.log_info(
'Cluster type set to %s' % self.config['cluster_type'])
break
diff --git a/soscollector/sosnode.py b/soscollector/sosnode.py
index 405d05d..3aba0bf 100644
--- a/soscollector/sosnode.py
+++ b/soscollector/sosnode.py
@@ -100,7 +100,6 @@ class SosNode():
return True
return False
-
def create_sos_container(self):
'''If the host is containerized, create the container we'll be using
'''
--
2.17.2
From 8d94e9ee9162c1b7676822958a94dfcd727d6dc8 Mon Sep 17 00:00:00 2001
From: Jake Hunsaker <jhunsake@redhat.com>
Date: Fri, 12 Apr 2019 14:47:31 -0400
Subject: [PATCH 2/3] [clusters] Add cluster_name where appropriate
Adds a cluster_name to a few of the existing cluster profiles.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
---
soscollector/clusters/kubernetes.py | 1 +
soscollector/clusters/ovirt.py | 2 ++
2 files changed, 3 insertions(+)
diff --git a/soscollector/clusters/kubernetes.py b/soscollector/clusters/kubernetes.py
index c5c2094..e18ee71 100644
--- a/soscollector/clusters/kubernetes.py
+++ b/soscollector/clusters/kubernetes.py
@@ -52,6 +52,7 @@ class kubernetes(Cluster):
class openshift(kubernetes):
+ cluster_name = 'OpenShift Container Platform'
packages = ('atomic-openshift',)
sos_preset = 'ocp'
cmd = 'oc'
diff --git a/soscollector/clusters/ovirt.py b/soscollector/clusters/ovirt.py
index 0a074ca..18cbf2e 100644
--- a/soscollector/clusters/ovirt.py
+++ b/soscollector/clusters/ovirt.py
@@ -23,6 +23,7 @@ from getpass import getpass
class ovirt(Cluster):
+ cluster_name = 'oVirt'
packages = ('ovirt-engine',)
option_list = [
@@ -122,6 +123,7 @@ class ovirt(Cluster):
class rhv(ovirt):
+ cluster_name = 'Red Hat Virtualization'
packages = ('rhevm', 'rhvm')
sos_preset = 'rhv'
--
2.17.2
From 4606699e9a460ebd6345444ae915ff8384619ed3 Mon Sep 17 00:00:00 2001
From: Jake Hunsaker <jhunsake@redhat.com>
Date: Tue, 16 Apr 2019 15:41:33 -0400
Subject: [PATCH 3/3] [ovirt] Add RHHI-V support
Adds support for RHHI-V environments which are RHV environments that
also use the hypervisors as gluster nodes. The new 'rhhi_virt' cluster
profile will be enabled when sos-collector is run against an environment
that is _both_ RHV and has nodes listed in the 'gluster_server' table in
the RHV database. Note that this means if community oVirt is in use, the
gluster bits enabled by 'rhhi_virt' will not be enabled for the oVirt
cluster type.
Included with this change is making DB queries more programmatic, and
making minor stylistic changes to the main query used by get_nodes() to
allow easier reading of the SQL query being built.
Finally, remove an unused import of getpass.
Resolves: #21
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
---
soscollector/clusters/ovirt.py | 44 ++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/soscollector/clusters/ovirt.py b/soscollector/clusters/ovirt.py
index 18cbf2e..8697d2e 100644
--- a/soscollector/clusters/ovirt.py
+++ b/soscollector/clusters/ovirt.py
@@ -18,13 +18,13 @@ import fnmatch
from pipes import quote
from soscollector.clusters import Cluster
-from getpass import getpass
class ovirt(Cluster):
- cluster_name = 'oVirt'
+ cluster_name = 'Community oVirt'
packages = ('ovirt-engine',)
+ db_exec = '/usr/share/ovirt-engine/dbscripts/engine-psql.sh -c'
option_list = [
('no-database', False, 'Do not collect a database dump'),
@@ -33,6 +33,14 @@ class ovirt(Cluster):
('no-hypervisors', False, 'Do not collect from hypervisors')
]
+ def _run_db_query(self, query):
+ '''
+ Wrapper for running DB queries on the master. Any scrubbing of the
+ query should be done _before_ passing the query to this method.
+ '''
+ cmd = "%s %s" % (self.db_exec, quote(query))
+ return self.exec_master_cmd(cmd, need_root=True)
+
def _sql_scrub(self, val):
'''
Manually sanitize SQL queries since we can't leave this up to the
@@ -58,18 +66,16 @@ class ovirt(Cluster):
def format_db_cmd(self):
cluster = self._sql_scrub(self.get_option('cluster'))
datacenter = self._sql_scrub(self.get_option('datacenter'))
- query = ("select host_name from vds_static 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'))" % (cluster, datacenter))
- self.dbcmd = ('/usr/share/ovirt-engine/dbscripts/engine-psql.sh '
- '-c {}'.format(quote(query)))
- self.log_debug('Query command for ovirt DB set to: %s' % self.dbcmd)
+ self.dbquery = ("SELECT host_name from vds_static 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'))" % (cluster, datacenter))
+ self.log_debug('Query command for ovirt DB set to: %s' % self.dbquery)
def get_nodes(self):
if self.get_option('no-hypervisors'):
return []
- res = self.exec_master_cmd(self.dbcmd, need_root=True)
+ res = self._run_db_query(self.dbquery)
if res['status'] == 0:
nodes = res['stdout'].splitlines()[2:-1]
return [n.split('(')[0].strip() for n in nodes]
@@ -134,3 +140,21 @@ class rhv(ovirt):
return 'rhvh'
else:
return 'rhelh'
+
+
+class rhhi_virt(rhv):
+
+ cluster_name = 'Red Hat Hyperconverged Infrastructure - Virtualization'
+ sos_plugins = ('gluster',)
+ sos_plugin_options = {'gluster.dump': 'on'}
+ sos_preset = 'rhv'
+
+ def check_enabled(self):
+ return (self.master.is_installed('rhvm') and self._check_for_rhhiv())
+
+ def _check_for_rhhiv(self):
+ ret = self._run_db_query('SELECT count(server_id) FROM gluster_server')
+ if ret['status'] == 0:
+ # if there are any entries in this table, RHHI-V is in use
+ return ret['stdout'].splitlines()[2].strip() != '0'
+ return False
--
2.17.2