sos.policies
— Policy Interface¶
-
class
sos.policies.
GenericPolicy
(sysroot=None, probe_runtime=True)[source] Bases:
sos.policies.Policy
This Policy will be returned if no other policy can be loaded. This should allow for IndependentPlugins to be executed on any system
-
get_msg
()[source] This method is used to prepare the preamble text to display to the user in non-batch mode. If your policy sets self.distro that text will be substituted accordingly. You can also override this method to do something more complicated.
Returns: Formatted banner message string Return type: str
-
-
class
sos.policies.
Policy
(sysroot=None, probe_runtime=True)[source] Bases:
object
Policies represent distributions that sos supports, and define the way in which sos behaves on those distributions. A policy should define at minimum a way to identify the distribution, and a package manager to allow for package based plugin enablement.
Policies also control preferred ContainerRuntime()’s, upload support to default locations for distribution vendors, disclaimer text, and default presets supported by that distribution or vendor’s products.
Every Policy will also need at least one “tagging class” for plugins.
Parameters: - sysroot (
str
orNone
) – Set the sysroot for the system, if not / - probe_runtime (
bool
) – Should the Policy try to load a ContainerRuntime
Variables: - distro (
str
) – The name of the distribution the Policy represents - vendor (
str
) – The name of the vendor producing the distribution - vendor_urls (
list
oftuples
formatted(``description
,url
)``) – List of URLs for the vendor’s website, or support portal - vendor_text (
str
) – Additional text to add to the banner message - name_pattern (
str
) – The naming pattern to be used for naming archives generated by sos. Values of legacy, and friendly are preset patterns. May also be set to an explicit custom pattern, see get_archive_name()
-
add_preset
(name=None, desc=None, note=None, opts=SoSOptions())[source] Add a new on-disk preset and write it to the configured presets path.
Parameters: preset – the new PresetDefaults to add
-
check
(remote='')[source] This function is responsible for determining if the underlying system is supported by this policy.
If remote is provided, it should be the contents of os-release from a remote host, or a similar vendor-specific file that can be used in place of a locally available file.
Returns: True
if the Policy should be loaded, elseFalse
Return type: bool
-
display_results
(archive, directory, checksum, archivestat=None, map_file=None)[source] Display final information about a generated archive
Parameters: - archive (
str
) – The name of the archive that was generated - directory (
str
) – The build directory for sos if –build was used - checksum (
str
) – The checksum of the archive - archivestat (os.stat_result) – stat() information for the archive
- map_file (
str
) – If sos clean was invoked, the location of the mapping file for this run
- archive (
-
dist_version
()[source] Return the OS version
-
find_preset
(preset)[source] Find a preset profile matching the specified preset string.
Parameters: preset – a string containing a preset profile name. Returns: a matching PresetProfile.
-
forbidden_paths
This property is used to determine the list of forbidden paths set by the policy. Note that this property will construct a cumulative list based on all subclasses of a given policy.
Returns: All patterns of policy forbidden paths Return type: list
-
get_archive_name
()[source] This function should return the filename of the archive without the extension.
This uses the policy’s name_pattern attribute to determine the name. There are two pre-defined naming patterns - legacy and friendly that give names like the following:
- legacy - sosreport-tux.123456-20171224185433
- friendly - sosreport-tux-mylabel-123456-2017-12-24-ezcfcop.tar.xz
A custom name_pattern can be used by a policy provided that it defines name_pattern using a format() style string substitution.
Usable substitutions are:
- name - the short hostname of the system
- label - the label given by –label
- case - the case id given by –case-id or –ticker-number
- rand - a random string of 7 alpha characters
Note that if a datestamp is needed, the substring should be set in name_pattern in the format accepted by
strftime()
.Returns: A name to be used for the archive, as expanded from the Policy name_pattern Return type: str
-
get_msg
()[source] This method is used to prepare the preamble text to display to the user in non-batch mode. If your policy sets self.distro that text will be substituted accordingly. You can also override this method to do something more complicated.
Returns: Formatted banner message string Return type: str
-
get_preferred_archive
()[source] Return the class object of the prefered archive format for this platform
-
get_preferred_hash_name
()[source] Returns the string name of the hashlib-supported checksum algorithm to use
-
host_sysroot
()[source] Get the host’s default sysroot
Returns: Host sysroot Return type: str
orNone
-
in_container
()[source] Are we running inside a container?
Returns: True
if in a container, elseFalse
Return type: bool
-
is_root
()[source] This method should return true if the user calling the script is considered to be a superuser
Returns: True
if user is superuser, elseFalse
Return type: bool
-
load_presets
(presets_path=None)[source] Load presets from disk.
Read JSON formatted preset data from the specified path, or the default location at
/var/lib/sos/presets
.Parameters: presets_path – a directory containing JSON presets.
-
match_plugin
(plugin_classes)[source] Determine what subclass of a Plugin should be used based on the tagging classes assigned to the Plugin
Parameters: plugin_classes ( list
) – The classes that the Plugin subclassesReturns: The first subclass that matches one of the Policy’s valid_subclasses Return type: A tagging class for Plugins
-
pkg_by_name
(pkg)[source] Wrapper to retrieve a package from the Policy’s package manager
Parameters: pkg ( str
) – The name of the packageReturns: The first package that matches pkg Return type: str
-
post_work
()[source] This function is called after the sosreport has been generated.
-
pre_work
()[source] This function is called prior to collection.
-
probe_preset
()[source] Return a
PresetDefaults
object matching the runing host.Stub method to be implemented by derived policy classes.
Returns: a PresetDefaults
object.
-
register_presets
(presets, replace=False)[source] Add new presets to this policy object.
Merges the presets dictionary
presets
into thisPolicy
object, or replaces the current presets ifreplace
isTrue
.presets
should be a dictionary mappingstr
preset names to<class PresetDefaults>
objects specifying the command line defaults.Parameters: - presets – dictionary of presets to add or replace
- replace – replace presets rather than merge new presets.
-
set_commons
(commons)[source] Set common host data for the Policy to reference
-
classmethod
set_forbidden_paths
()[source] Use this to append policy-specifc forbidden paths that apply to all plugins. Setting this classmethod on an invidual policy will not override subclass-specific paths
-
validate_plugin
(plugin_class, experimental=False)[source] Verifies that the plugin_class should execute under this policy
Parameters: plugin_class (A Plugin() tagging class) – The tagging class being checked Returns: True
if the plugin_class is allowed by the policyReturn type: bool
- sysroot (