Resources needed by pkg providers
salt.modules.pkg_resource.
add_pkg
(pkgs, name, pkgver)¶Add a package to a dict of installed packages.
CLI Example:
salt '*' pkg_resource.add_pkg '{}' bind 9
salt.modules.pkg_resource.
check_extra_requirements
(pkgname, pkgver)¶Check if the installed package already has the given requirements.
This function will return the result of pkg.check_extra_requirements
if
this function exists for the minion, otherwise it will return True.
CLI Example:
salt '*' pkg_resource.check_extra_requirements <pkgname> <extra_requirements>
salt.modules.pkg_resource.
format_pkg_list
(packages, versions_as_list, attr)¶Formats packages according to parameters for list_pkgs.
salt.modules.pkg_resource.
format_version
(epoch, version, release)¶Formats a version string for list_pkgs.
salt.modules.pkg_resource.
pack_sources
(sources, normalize=True)¶Accepts list of dicts (or a string representing a list of dicts) and packs the key/value pairs into a single dict.
'[{"foo": "salt://foo.rpm"}, {"bar": "salt://bar.rpm"}]'
would become
{"foo": "salt://foo.rpm", "bar": "salt://bar.rpm"}
Normalize the package name by removing the architecture, if the architecture of the package is different from the architecture of the operating system. The ability to disable this behavior is useful for poorly-created packages which include the architecture as an actual part of the name, such as kernel modules which match a specific kernel version.
New in version 2015.8.0.
CLI Example:
salt '*' pkg_resource.pack_sources '[{"foo": "salt://foo.rpm"}, {"bar": "salt://bar.rpm"}]'
salt.modules.pkg_resource.
parse_targets
(name=None, pkgs=None, sources=None, saltenv='base', normalize=True, **kwargs)¶Parses the input to pkg.install and returns back the package(s) to be installed. Returns a list of packages, as well as a string noting whether the packages are to come from a repository or a binary package.
CLI Example:
salt '*' pkg_resource.parse_targets
salt.modules.pkg_resource.
sort_pkglist
(pkgs)¶Accepts a dict obtained from pkg.list_pkgs() and sorts in place the list of versions for any packages that have multiple versions installed, so that two package lists can be compared to one another.
CLI Example:
salt '*' pkg_resource.sort_pkglist '["3.45", "2.13"]'
salt.modules.pkg_resource.
stringify
(pkgs)¶Takes a dict of package name/version information and joins each list of installed versions into a string.
CLI Example:
salt '*' pkg_resource.stringify 'vim: 7.127'
salt.modules.pkg_resource.
version
(*names, **kwargs)¶Common interface for obtaining the version of installed packages.
CLI Example:
salt '*' pkg_resource.version vim
salt '*' pkg_resource.version foo bar baz
salt '*' pkg_resource.version 'python*'
salt.modules.pkg_resource.
version_clean
(verstr)¶Clean the version string removing extra data.
This function will simply try to call pkg.version_clean
.
CLI Example:
salt '*' pkg_resource.version_clean <version_string>
salt.modules.pkg_resource.
version_compare
(ver1, oper, ver2, ignore_epoch=False)¶New in version 3001.
Perform a version comparison, using (where available) platform-specific version comparison tools to make the comparison.
The first version to be compared
One of ==, !=, >=, <=, >, <
The second version to be compared
Note
To avoid shell interpretation, each of the above values should be quoted when this function is used on the CLI.
If True
, both package versions will have their epoch prefix
stripped before comparison.
This function is useful in Jinja templates, to perform specific actions when a package's version meets certain criteria. For example:
{%- set postfix_version = salt.pkg.version('postfix') %}
{%- if postfix_version and salt.pkg_resource.version_compare(postfix_version, '>=', '3.3', ignore_epoch=True) %}
{#- do stuff #}
{%- endif %}
CLI Examples:
salt myminion pkg_resource.version_compare '3.5' '<=' '2.4'
salt myminion pkg_resource.version_compare '3.5' '<=' '2.4' ignore_epoch=True