InstalledRpms - Command rpm -qa

InstalledRpms - command rpm -qa

ContainerInstalledRpms - command rpm -qa for containers

class insights.parsers.installed_rpms.ContainerInstalledRpms(context)[source]

Bases: ContainerParser, InstalledRpms

Parses the data for list of installed rpms of the running containers which are based on RHEL images.

Sample output:

a52dec-0.7.4-18.el7.nux.x86_64                  Tue 14 Jul 2015 09:25:38 AEST   1398536494
aalib-libs-1.4.0-0.22.rc5.el7.x86_64            Tue 14 Jul 2015 09:25:40 AEST   1390535634
abrt-2.1.11-35.el7.x86_64                       Wed 09 Nov 2016 14:52:01 AEDT   1446193355
kernel-3.10.0-267.el7.x86_64                    Sat 24 Oct 2015 09:56:17 AEDT   1434466402
kernel-3.10.0-327.36.3.el7.x86_64               Wed 09 Nov 2016 14:53:25 AEDT   1476954923
kernel-headers-3.10.0-327.36.3.el7.x86_64       Wed 09 Nov 2016 14:20:59 AEDT   1476954923
kernel-tools-3.10.0-327.36.3.el7.x86_64         Wed 09 Nov 2016 15:09:42 AEDT   1476954923
kernel-tools-libs-3.10.0-327.36.3.el7.x86_64    Wed 09 Nov 2016 14:52:13 AEDT   1476954923
kexec-tools-2.0.7-38.el7_2.1.x86_64             Wed 09 Nov 2016 14:48:21 AEDT   1452845178
zlib-1.2.7-15.el7.x86_64                        Wed 09 Nov 2016 14:21:19 AEDT   1431443476
zsh-5.0.2-14.el7_2.2.x86_64                     Wed 09 Nov 2016 15:13:19 AEDT   1464185248

Examples

>>> type(container_rpms)
<class 'insights.parsers.installed_rpms.ContainerInstalledRpms'>
>>> container_rpms.container_id
'cc2883a1a369'
>>> container_rpms.image
'quay.io/rhel8'
>>> container_rpms.engine
'podman'
>>> container_rpms.get_min('kernel').package == 'kernel-3.10.0-267.el7'
True
>>> container_rpms.get_max("kernel").name
'kernel'
>>> container_rpms.get_max("kernel").version
'3.10.0'
insights.parsers.installed_rpms.Installed

alias of InstalledRpms

class insights.parsers.installed_rpms.InstalledRpm(data)[source]

Bases: object

Class for holding information about one installed RPM.

This class is usually created from dictionary with following structure:

{
   'name': 'package name',
   'version': 'package version',
   'release': 'package release',
   'arch': 'package architecture'
 }

It may also contain supplementary information from SOS report or epoch information from JSON.

When comparing rpms whose epoch is not null, it is necessary to create InstalledRpm object with epoch information like following example:

InstalledRpm.from_json('{"name":"microcode_ctl","epoch":"4","version":"20200609","release":"2.20201027.1.el8_3"}'

Factory methods are provided such as from_package to create an object from a short package string:

kernel-devel-3.10.0-327.36.1.el7.x86_64

from_json to create an object from JSON:

{"name": "kernel-devel",
 "version": "3.10.0",
 "release": "327.36.1.el7",
 "arch": "x86_64"}

and from_line to create an object from a long package string:

('kernel-devel-3.10.0-327.36.1.el7.x86_64'
 '                                '
 'Wed May 18 14:16:21 2016' '       '
 '1410968065' '     '
 'Red Hat, Inc.' '  '
 'hs20-bc2-4.build.redhat.com' '    '
 '8902150305004...b3576ff37da7e12e2285358267495ac48a437d4eefb3213' '        '
 'RSA/8, Mon Aug 16 11:14:17 2010, Key ID 199e2f91fd431d51')
PRODUCT_SIGNING_KEYS = ['199e2f91fd431d51', '1ac4971355a34a82', '5054e4a45a6340b3', 'e1a4bd708a828aad', 'f76f66c3d4082792', '5326810137017186', '45689c882fa658e0', '219180cddb42a60e', '7514f77d8366b0d9', '08dd962c1c711042', 'fd372689897da07a', '938a80caf21541eb08b871e6a5787476', 'e191ddb2c509e861', '66e8f8a29c65f85c', '680b9144769a9f8f', '8ed29db42a2898c8']

List of package-signing keys in all lower cases. Should be updated timely according to https://access.redhat.com/security/team/key/

Type:

list

SOSREPORT_KEYS = ['installtime', 'buildtime', 'vendor', 'buildserver', 'pgpsig', 'pgpsig_short']

List of keys for SOS Report RPM information.

Type:

list

arch

RPM package architecture.

Type:

str

classmethod from_json(json_line)[source]

The object of this class is usually created from dictionary. Alternatively it can be created from JSON line.

Parameters:

json_line (str) --

JSON string in the following format (shown as Python string):

'{"name": "kernel-devel", "version": "3.10.0", "release": "327.36.1.el7", "arch": "x86_64"}'

classmethod from_line(line)[source]

The object of this class is usually created from dictionary. Alternatively it can be created from package line.

Parameters:

line (str) --

package line in the following format (shown as Python string):

('kernel-devel-3.10.0-327.36.1.el7.x86_64'
 '                                '
 'Wed May 18 14:16:21 2016' '       '
 '1410968065' '     '
 'Red Hat, Inc.' '  '
 'hs20-bc2-4.build.redhat.com' '    '
 '8902150305004...b3576ff37da7e12e2285358267495ac48a437d4eefb3213' '        '
 'RSA/8, Mon Aug 16 11:14:17 2010, Key ID 199e2f91fd431d51')

classmethod from_package(package_string)[source]

The object of this class is usually created from dictionary. Alternatively it can be created from package string.

Parameters:

package_string (str) --

package string in the following format (shown as Python string):

'kernel-devel-3.10.0-327.36.1.el7.x86_64'

name

RPM package name.

Type:

str

property nevra

Package string in the format:

name-epoch:version-release.arch
Type:

str

property nvr

Package name-version-release string.

Type:

str

property nvra

Package name-version-release.arch string.

Type:

str

property package

Package name-version-release string.

Type:

str

property package_with_epoch

Package string in the format:

name-epoch:version-release
Type:

str

redhat_signed

True when RPM package is signed by Red Hat, False when RPM package is not signed by Red Hat, None when no sufficient info to determine

Type:

bool

release

RPM package release.

Type:

str

property source

Returns source RPM of this RPM object.

Type:

InstalledRpm

vendor

RPM package vendor. None when no ‘vendor’ info

Type:

str

version

RPM package version.

Type:

str

class insights.parsers.installed_rpms.InstalledRpms(*args, **kwargs)[source]

Bases: CommandParser, RpmList

The InstalledRpms class parses the output of the rpm -qa command. Each line is parsed and stored in an InstalledRpm object. The rpm -qa command may output data in different formats and each format can be handled by the parsing routines of this class. The basic format of command is the package and is shown in the Examples.

A parser for working with data containing a list of installed RPM files on the system and related information.

Sample input data:

a52dec-0.7.4-18.el7.nux.x86_64  Tue 14 Jul 2015 09:25:38 AEST   1398536494
aalib-libs-1.4.0-0.22.rc5.el7.x86_64    Tue 14 Jul 2015 09:25:40 AEST   1390535634
abrt-2.1.11-35.el7.x86_64       Wed 09 Nov 2016 14:52:01 AEDT   1446193355
...
kernel-3.10.0-267.el7.x86_64    Sat 24 Oct 2015 09:56:17 AEDT   1434466402
kernel-3.10.0-327.36.3.el7.x86_64       Wed 09 Nov 2016 14:53:25 AEDT   1476954923
kernel-headers-3.10.0-327.36.3.el7.x86_64       Wed 09 Nov 2016 14:20:59 AEDT   1476954923
kernel-tools-3.10.0-327.36.3.el7.x86_64 Wed 09 Nov 2016 15:09:42 AEDT   1476954923
kernel-tools-libs-3.10.0-327.36.3.el7.x86_64    Wed 09 Nov 2016 14:52:13 AEDT   1476954923
kexec-tools-2.0.7-38.el7_2.1.x86_64     Wed 09 Nov 2016 14:48:21 AEDT   1452845178
...
zlib-1.2.7-15.el7.x86_64        Wed 09 Nov 2016 14:21:19 AEDT   1431443476
zsh-5.0.2-14.el7_2.2.x86_64     Wed 09 Nov 2016 15:13:19 AEDT   1464185248

Examples

>>> type(rpms)
<class 'insights.parsers.installed_rpms.InstalledRpms'>
>>> 'kernel' in rpms
True
>>> rpms.corrupt
False
>>> rpms.get_max('kernel')
0:kernel-3.10.0-327.36.3.el7
>>> type(rpms.get_max('kernel'))
<class 'insights.parsers.installed_rpms.InstalledRpm'>
>>> rpms.get_min('kernel')
0:kernel-3.10.0-267.el7
>>> rpm = rpms.get_max('kernel')
>>> rpm
0:kernel-3.10.0-327.36.3.el7
>>> type(rpm)
<class 'insights.parsers.installed_rpms.InstalledRpm'>
>>> rpm.package == 'kernel-3.10.0-327.36.3.el7'
True
>>> rpm.nvr == 'kernel-3.10.0-327.36.3.el7'
True
>>> rpm.source
>>> rpm.name
'kernel'
>>> rpm.version
'3.10.0'
>>> rpm.release
'327.36.3.el7'
>>> rpm.arch
'x86_64'
>>> rpm.epoch
'0'
>>> from insights.parsers.installed_rpms import InstalledRpm
>>> rpm2 = InstalledRpm.from_package('kernel-3.10.0-267.el7')
>>> rpm == rpm2
False
>>> rpm > rpm2
True
>>> rpm < rpm2
False
property corrupt

True if RPM database is corrupted, else False.

Type:

bool

errors

List of input lines that indicate an error acquiring the data on the client.

Type:

list

packages

Dictionary of RPMs keyed by package name.

Note

The packages could be empty, e.g. when rpm database corrupt. When doing exclusion check, make sure the packages is NOT empty, e.g.:

>>> if rpms.packages and "pkg_name" not in rpms.packages:
>>>     pass
Type:

dict (InstalledRpm)

parse_content(content)[source]

This method must be implemented by classes based on this class.

unparsed

List of input lines that raised an exception during parsing.

Type:

list

insights.parsers.installed_rpms.KNOWN_ARCHITECTURES = ['x86_64', 'i386', 'i486', 'i586', 'i686', 'src', 'ia64', 'ppc', 'ppc64', 's390', 's390x', 'amd64', '(none)', 'noarch', 'alpha', 'alphaev4', 'alphaev45', 'alphaev5', 'alphaev56', 'alphaev6', 'alphaev67', 'alphaev68', 'alphaev7', 'alphapca56', 'arm64', 'armv5tejl', 'armv5tel', 'armv6l', 'armv7hl', 'armv7hnl', 'armv7l', 'athlon', 'armhfp', 'geode', 'ia32e', 'nosrc', 'ppc64iseries', 'ppc64le', 'ppc64p7', 'ppc64pseries', 'sh3', 'sh4', 'sh4a', 'sparc', 'sparc64', 'sparc64v', 'sparcv8', 'sparcv9', 'sparcv9v', 'aarch64']

List of recognized architectures.

This list is taken from the PDC (Product Definition Center) available here https://pdc.fedoraproject.org/rest_api/v1/arches/.

Type:

list

insights.parsers.installed_rpms.Rpm

alias of InstalledRpm

class insights.parsers.installed_rpms.RpmList[source]

Bases: object

Mixin class providing __contains__, get_max, get_min, newest, and oldest implementations for components that handle rpms.

get_max(package_name)[source]

Returns the highest version of the installed package with the given name.

Parameters:

package_name (str) -- Installed RPM package name such as ‘bash’

Returns:

Installed RPM with highest version

Return type:

InstalledRpm

get_min(package_name)[source]

Returns the lowest version of the installed package with the given name.

Parameters:

package_name (str) -- Installed RPM package name such as ‘bash’.

Returns:

Installed RPM with lowest version

Return type:

InstalledRpm

newest(package_name)

Returns the highest version of the installed package with the given name.

Parameters:

package_name (str) -- Installed RPM package name such as ‘bash’

Returns:

Installed RPM with highest version

Return type:

InstalledRpm

oldest(package_name)

Returns the lowest version of the installed package with the given name.

Parameters:

package_name (str) -- Installed RPM package name such as ‘bash’.

Returns:

Installed RPM with lowest version

Return type:

InstalledRpm

insights.parsers.installed_rpms.from_package(package_string)

The object of this class is usually created from dictionary. Alternatively it can be created from package string.

Parameters:

package_string (str) --

package string in the following format (shown as Python string):

'kernel-devel-3.10.0-327.36.1.el7.x86_64'

insights.parsers.installed_rpms.pad_version(left, right)[source]

Returns two sequences of the same length so that they can be compared. The shorter of the two arguments is lengthened by inserting extra zeros before non-integer components. The algorithm attempts to align character components.