InstalledRpms - Command rpm -qa

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.

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-230.el7synaptics.1186112.1186106.2.x86_64 Wed 20 May 2015 11:24:00 AEST   1425955944
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'>
>>> 'openjpeg-libs' in rpms
True
>>> rpms.corrupt
False
>>> rpms.get_max('openjpeg-libs')
0:openjpeg-libs-1.3-9.el6_3
>>> type(rpms.get_max('openjpeg-libs'))
<class 'insights.parsers.installed_rpms.InstalledRpm'>
>>> rpms.get_min('openjpeg-libs')
0:openjpeg-libs-1.3-9.el6_3
>>> rpm = rpms.get_max('openssh-server')
>>> rpm
0:openssh-server-5.3p1-104.el6
>>> type(rpm)
<class 'insights.parsers.installed_rpms.InstalledRpm'>
>>> rpm.package
'openssh-server-5.3p1-104.el6'
>>> rpm.nvr
'openssh-server-5.3p1-104.el6'
>>> rpm.source
>>> rpm.name
'openssh-server'
>>> rpm.version
'5.3p1'
>>> rpm.release
'104.el6'
>>> rpm.arch
'x86_64'
>>> rpm.epoch
'0'
>>> from insights.parsers.installed_rpms import InstalledRpm
>>> rpm2 = InstalledRpm.from_package('openssh-server-6.0-100.el6.x86_64')
>>> rpm == rpm2
False
>>> rpm > rpm2
False
>>> rpm < rpm2
True
insights.parsers.installed_rpms.Installed

alias of insights.parsers.installed_rpms.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.

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 = ['F76F66C3D4082792', '199e2f91fd431d51', '5326810137017186', '45689c882fa658e0', '219180cddb42a60e', '7514f77d8366b0d9', 'fd372689897da07a', '938a80caf21541eb', '08b871e6a5787476', 'E191DDB2C509E861']

List of package-signing keys. 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 = None

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 = None

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 = None

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 = None

RPM package release.

Type

str

property source

Returns source RPM of this RPM object.

Type

InstalledRpm

version = None

RPM package version.

Type

str

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

Bases: insights.core.CommandParser, insights.parsers.installed_rpms.RpmList

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

property corrupt

True if RPM database is corrupted, else False.

Type

bool

errors = None

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

Type

list

packages = None

Dictionary of RPMs keyed by package name.

Type

dict (InstalledRpm)

parse_content(content)[source]

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

unparsed = None

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 insights.parsers.installed_rpms.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

property is_hypervisor

Warning

This method is deprecated, please use insights.parsers.virt_what.VirtWhat which uses the command virt-what to check the hypervisor type.

bool: True if “.el[6|7]ev” exists in “vdsm”.release, else False.

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.