aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-04-09 22:48:11 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-04-22 10:01:00 -0400
commitf73bb689f1211153599a0ca520e060b5ab4f0cd4 (patch)
treeef7dd4558007df335857158a2b5606b0383c75f7
parentd4347c9c56e6032e831b82e886ad824c31bf2828 (diff)
downloadsos-f73bb689f1211153599a0ca520e060b5ab4f0cd4.tar.gz
[clusters|node] Fix setting node SSH key based on cluster
Previously, the ovirt (and family) cluster profile would attempt to set a global SSH key if the ovirt-generated key was locally available by changing the options entry for ssh_key. This no longer worked since decoupling the shared dict, so instead create a new mechanism by which clusters may set this. It may prove necessary in the future to extend this functionality to arbitrary settings, however for now I do not see that being common place. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/collector/__init__.py6
-rw-r--r--sos/collector/clusters/__init__.py12
-rw-r--r--sos/collector/clusters/ovirt.py2
3 files changed, 18 insertions, 2 deletions
diff --git a/sos/collector/__init__.py b/sos/collector/__init__.py
index 708a6e47..46f61d63 100644
--- a/sos/collector/__init__.py
+++ b/sos/collector/__init__.py
@@ -621,7 +621,6 @@ class SoSCollector(SoSComponent):
try:
self.master = SosNode('localhost', self.commons)
except Exception as err:
- print(err)
self.log_debug("Unable to determine local installation: %s" %
err)
self._exit('Unable to determine local installation. Use the '
@@ -645,6 +644,11 @@ class SoSCollector(SoSComponent):
if self.cluster:
self.master.cluster = self.cluster
self.cluster.setup()
+ if self.cluster.cluster_ssh_key:
+ if not self.opts.ssh_key:
+ self.log_debug("Updating SSH key to %s per cluster"
+ % self.cluster.cluster_ssh_key)
+ self.opts.ssh_key = self.cluster.cluster_ssh_key
self.get_nodes()
if self.opts.save_group:
diff --git a/sos/collector/clusters/__init__.py b/sos/collector/clusters/__init__.py
index 2f84845f..d66cb139 100644
--- a/sos/collector/clusters/__init__.py
+++ b/sos/collector/clusters/__init__.py
@@ -33,6 +33,7 @@ class Cluster():
'''
self.master = None
+ self.cluster_ssh_key = None
self.tmpdir = commons['tmpdir']
self.opts = commons['opts']
self.cluster_type = [self.__class__.__name__]
@@ -94,6 +95,17 @@ class Cluster():
return opt.value
return False
+ def add_default_ssh_key(self, key):
+ """Some clusters generate and/or deploy well-known and consistent
+ SSH keys across environments. If this is the case, the cluster profile
+ may call this command so that subsequent node connections will use that
+ key rather than prompting the user for one or a password.
+
+ Note this will only function if collector is being run locally on the
+ master node.
+ """
+ self.cluster_ssh_key = key
+
def exec_master_cmd(self, cmd, need_root=False):
'''Used to retrieve output from a (master) node in a cluster'''
res = self.master.run_command(cmd, get_pty=True, need_root=need_root)
diff --git a/sos/collector/clusters/ovirt.py b/sos/collector/clusters/ovirt.py
index 16f99bca..bdce8cf7 100644
--- a/sos/collector/clusters/ovirt.py
+++ b/sos/collector/clusters/ovirt.py
@@ -66,7 +66,7 @@ class ovirt(Cluster):
if not any([self.opts.ssh_key, self.opts.password,
self.opts.password_per_node]):
if self.master.file_exists(ENGINE_KEY):
- self.opts.ssh_key = ENGINE_KEY
+ self.add_default_ssh_key(ENGINE_KEY)
self.log_debug("Found engine SSH key. User command line"
" does not specify a key or password, using"
" engine key.")