Uname - command uname -a

The 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

Example

>>> 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
class insights.parsers.uname.RedhatRelease(major, minor)

Bases: tuple

property major
property minor
class insights.parsers.uname.Uname(context)[source]

Bases: insights.core.CommandParser

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 -a command. 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 #.#.#-#.#.#.el#.arch.

  • name: The kernel name, usually Linux.

  • 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_64 or 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 version-release.

  • rhel_release: A list of two elements, the major and minor RHEL product release numbers.

  • debug_kernel: A bool that’s returns True when the server is running the debug kernel.

fixed_by(*fixes, **kwargs)[source]

Determine whether the Uname object is fixed by a range of releases or by a specific release.

Parameters
  • 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.

classmethod from_kernel(kernel)[source]

Create a Uname object from a kernel NVR (e.g. ‘2.6.32-504.el6.x86_64’).

Parameters
  • kernel - the kernel version and release string.

classmethod from_release(release)[source]

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.

Parameters
  • release: RHEL release version.

classmethod from_uname_str(uname_str)[source]

Create a Uname object from a string containing the output of ‘uname -a’.

Parameters
  • uname_str - the string output of uname -a

parse_content(content)[source]

Parses uname content into individual uname components.

Parameters
  • content: Uname content from Insights to be parsed.

Exceptions
  • UnameError: Raised when there are any errors evaluating the uname content.

classmethod parse_nvr(nvr, data=None, arch=True)[source]

Called by parse_uname_line to separate the version, release and arch information.

Parameters
  • nvr: Uname content to parse.

  • arch: Flag to indicate whether there is architecture information in the release.

Exceptions
  • UnameError: Raised on errors in evaluating the uname content.

exception insights.parsers.uname.UnameError(msg, uname_line)[source]

Bases: Exception

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.

insights.parsers.uname.pad_release(release_to_pad, num_sections=4)[source]

Pad out package and kernel release versions so that LooseVersion comparisons will be correct.

Release versions with less than num_sections will be padded in front of the last section with zeros.

For example

pad_release("390.el6", 4)

will return 390.0.0.el6 and

pad_release("390.11.el6", 4)

will return 390.11.0.el6.

If the number of sections of the release to be padded is greater than num_sections, a ValueError will be raised.