Operator Libs Linux
- Jon Seager
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 2 | 09 Mar 2023 | |
latest/stable | 1 | 28 Oct 2021 |
juju deploy operator-libs-linux
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.operator_libs_linux.v0.dnf
-
- Last updated 08 Mar 2023
- Revision Library version 0.1
Abstractions for the system's DNF package information and repositories.
This charm library contains abstractions and wrappers around Enterprise Linux (CentOS Stream, AlmaLinux, Rocky Linux, Cloud Linux, etc.) repositories and packages to provide an idiomatic and Pythonic mechanism for managing packages and repositories within machine charms deployed to an Enterprise Linux base.
To install packages using the library:
import charms.operator_libs_linux.v0.dnf as dnf
try:
dnf.install("epel-release")
dnf.install("slurm-slurmd", "slurm-slurmctld", "slurm-slurmdbd", "slurm-slurmrestd")
except dnf.Error:
logger.error("Failed to install requested packages.")
To upgrade specific packages and/or entire system using the library:
import charms.operator_libs_linux.v0.dnf as dnf
try:
# To upgrade a specific package.
dnf.upgrade("slurm-slurmd")
# To upgrade the whole system.
dnf.upgrade()
except dnf.Error:
logger.error("Failed to perform requested package upgrades.")
Important: If no packages are passed to dnf.upgrade(...)
, all packages with newer
versions available in the system's known repositories will be upgraded.
To remove packages using the library:
import charms.operator_libs_linux.v0.dnf as dnf
try:
dnf.remove("slurm-slurmd", "slurm-slurmctld", "slurm-slurmdbd", "slurm-slurmrestd")
dnf.remove("epel-release")
except dnf.Error:
logger.error("Failed to remove requested packages.")
Packages can have three possible states: installed, available, and absent. "installed" means that the package is currently installed on the system. "available" means that the package is available within the system's known package repositories, but is not currently installed. "absent" means that the package was not found either or the system on within the system's known package repositories.
To find details of a specific package using the library:
import charms.operator_libs_linux.v0.dnf as dnf
try:
package = dnf.fetch("slurm-slurmd")
assert package.installed
assert package.version == "22.05.6"
except AssertionError:
logger.error("Package slurm-slurmd is not installed or is not expected version.")
Important: dnf.fetch(...)
will only match exact package names, not aliases. Ensure
that you are using the exact package name, otherwise the fetched package will be marked
as "absent". e.g. use the exact package name "python2.7" and not the alias "python2".
To add a new package repository using the library:
import charms.operator_libs_linux.v0.dnf as dnf
try:
dnf.add_repo("http://mirror.stream.centos.org/9-stream/HighAvailability/x86_64/os")
dnf.install("pacemaker")
except dnf.Error:
logger.error("Failed to install pacemaker package from HighAvailability repository.")
Index
class Error
Description
Raise when dnf encounters an execution error. None
class PackageInfo
Description
Dataclass representing DNF package information. None
Methods
PackageInfo. installed( self )
Description
Determine if package is marked 'installed'. None
PackageInfo. available( self )
Description
Determine if package is marked 'available'. None
PackageInfo. absent( self )
Description
Determine if package is marked 'absent'. None
PackageInfo. full_version( self )
Description
Get full version of package. None
def version()
Description
Get version of dnf
executable. None
def installed()
Description
Determine if the dnf
executable is available on PATH. None
def upgrade()
Upgrade one or more packages.
Arguments
Packages to upgrade on system. If packages is omitted, upgrade all packages on the system.
def install()
Install one or more packages.
Arguments
Packages to install on the system.
def remove()
Remove one or more packages from the system.
Arguments
Packages to remove from system.
def fetch(package: str)
Fetch information about a package.
Arguments
Package to get information about.
Returns
Information about package.
def add_repo(repo: str)
Add a new repository to DNF.
Arguments
URL of new repository to add.