aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2018-05-26 20:35:33 +0100
committerBryn M. Reeves <bmr@redhat.com>2018-06-20 18:01:21 +0100
commitb0dca512087d704d7f0bfa7e24e71f8c3c1cd8e5 (patch)
tree43c3cf01872d13cb86b18509e3bd9aa9d2591b41
parenta07fd4f5cb374d88fb1093200020cf8e45ccd916 (diff)
downloadsos-b0dca512087d704d7f0bfa7e24e71f8c3c1cd8e5.tar.gz
[sos] add automatic preset detection infrastructure
Add a new special value for the --preset argument, 'auto', which enables automatic detection of the preset identifier string by the policy class. A new method, probe_preset() is added which should be implemented by derived classes of Policy to return a ProductDefaults() object initialised appropriately for the running preset. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/__init__.py1
-rw-r--r--sos/policies/__init__.py11
-rw-r--r--sos/sosreport.py8
3 files changed, 17 insertions, 3 deletions
diff --git a/sos/__init__.py b/sos/__init__.py
index 315d6777..c7534034 100644
--- a/sos/__init__.py
+++ b/sos/__init__.py
@@ -55,6 +55,7 @@ _arg_defaults = {
"log_size": 10,
"chroot": "auto",
"compression_type": "auto",
+ "preset": "auto"
}
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 2ad8b632..a5ba8109 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -517,7 +517,7 @@ No changes will be made to system configuration.
"""Find a preset profile matching the specified preset string.
:param preset: a string containing a preset profile name.
- :returns: a matching ProductProfile.
+ :returns: a matching PresetProfile.
"""
# FIXME: allow fuzzy matching?
for match in self.presets.keys():
@@ -527,6 +527,15 @@ No changes will be made to system configuration.
# Return default preset
return self.presets[""]
+ def probe_preset(self):
+ """Return a ``PresetDefaults`` object matching the runing host.
+
+ Stub method to be implemented by derived policy classes.
+
+ :returns: a ``PresetDefaults`` object.
+ """
+ return self.presets[""]
+
class GenericPolicy(Policy):
"""This Policy will be returned if no other policy can be loaded. This
diff --git a/sos/sosreport.py b/sos/sosreport.py
index b08baf77..d4afebed 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -274,7 +274,7 @@ def _parse_args(args):
dest="onlyplugins", type=str,
help="enable these plugins only", default=deque())
parser.add_argument("--preset", action="store", type=str,
- help="A preset identifier")
+ help="A preset identifier", default="auto")
parser.add_argument("-p", "--profile", action="extend",
dest="profiles", type=str, default=deque(),
help="enable plugins used by the given profiles")
@@ -343,7 +343,11 @@ class SoSReport(object):
self._is_root = self.policy.is_root()
- self.preset = self.policy.find_preset(cmd_args.preset)
+ # Apply per-preset command line defaults
+ if cmd_args.preset != _arg_defaults["preset"]:
+ self.preset = self.policy.find_preset(cmd_args.preset)
+ else:
+ self.preset = self.policy.probe_preset()
self.opts.merge(self.preset.opts)
# system temporary directory to use