Uname - command
Uname class reads the output of the
uname -a command and
interprets it. It also does a number of handy extra things, like deriving
the RHEL release from the kernel version.
Uname objects can also be compared by their kernel versions.
An example from the following
uname -a output:
Linux server1.example.com 2.6.32-504.el6.x86_64 #1 SMP Tue Sep 16 01:56:35 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
>>> type(uname) <class 'insights.parsers.uname.Uname'> >>> uname.version '2.6.32' >>> uname.release '504.el6' >>> uname.arch 'x86_64' >>> uname.nodename 'server1.example.com'
Uname objects can be created from, and compared to, other Uname objects or kernel strings:
>>> early_rhel6 = Uname.from_kernel('2.6.32-71') >>> late_rhel6 = Uname.from_release('6.7') >>> late_rhel6 > early_rhel6 True >>> early_rhel6 > '2.6.32-279.el6.x86_64' False
A utility class to parse uname content data and compare version and release information.
The input is a uname content string. The content is parsed into specific uname elements that are made available through instance variables. Operators are provided for comparison of version and release information. Uname content is expected to be in the format returned by the
uname -acommand. The following instance variables are provided by this class:
kernel: Provides an unparsed copy of the full version and release string provided in the uname content input. No validation is performed on this information. Generally in the format
name: The kernel name, usually
nodename: Hostname of the computer where the uname command was executed. This information may obfuscated for security.
version: The major identification number for the kernel release. It should be in the format
#.#.#[.#]or a UnameError exception will be raised.
release: The minor identification number for the kernel release. This information is generally in the format #.#.#.el#, however this is not strictly enforced. If the release.arch information cannot be reliably parsed then release and release_arch will be the same value.
release_arch: This is the release plus the kernel architecture information as provided in arch.
arch: This contains the kernel architecture information like
x86_64or s390. A list of known architectures is provided by the global variable KNOWN_ARCHITECTURES. This information is not always present in the uname content.
ver_rel: This is a combination of version and release in the format
rhel_release: A list of two elements, the major and minor RHEL product release numbers.
Determine whether the Uname object is fixed by a range of releases or by a specific release.
fixes: List of one or more Uname objects to compare to the current object. fixes is a list of one or more Uname objects and each will be compared with the current object to determine a match.
kwargs: List of key word argument/Uname object pairs. Currently only introduced_in is supported as a keyword. When used the current Uname object is checked to see if it is prior to the introduced_in release. It will be further checked against fixes only if it is the same as or newer than the introduced_in release.
Create a Uname object from a kernel NVR (e.g. ‘2.6.32-504.el6.x86_64’).
kernel - the kernel version and release string.
Attempt to create a Uname object from a release (e.g. ‘7.2’).
This translates from the release to the kernel version for that release, and then uses that to generate a Uname object using the class from_kernel method. If the release does not match a known release, it returns None.
release: RHEL release version.
Create a Uname object from a string containing the output of ‘uname -a’.
uname_str - the string output of uname -a
Parses uname content into individual uname components.
content: Uname content from Insights to be parsed.
UnameError: Raised when there are any errors evaluating the uname content.
parse_nvr(nvr, data=None, arch=True)¶
Called by parse_uname_line to separate the version, release and arch information.
nvr: Uname content to parse.
arch: Flag to indicate whether there is architecture information in the release.
UnameError: Raised on errors in evaluating the uname content.
Exception subclass for errors related to uname content data and the Uname class.
This exception should not be caught by rules plugins unless it is necessary for the plugin to return a particular answer when a problem occurs with uname data. If a plugin catches this exception it must reraise it so that the engine has the opportunity to handle it/log it as necessary.
Pad out package and kernel release versions so that
LooseVersioncomparisons will be correct.
Release versions with less than num_sections will be padded in front of the last section with zeros.
If the number of sections of the release to be padded is greater than num_sections, a
ValueErrorwill be raised.