Operator Libs Linux

  • Jon Seager
Channel Revision Published Runs on
latest/stable 2 09 Mar 2023
Ubuntu 22.04 Ubuntu 20.04
latest/stable 1 28 Oct 2021
Ubuntu 22.04 Ubuntu 20.04
juju deploy operator-libs-linux
Show information

Platform:

Ubuntu
22.04 20.04

charms.operator_libs_linux.v0.dnf

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.")

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

Packages to upgrade on system. If packages is omitted, upgrade all packages on the system.

def install()

Install one or more packages.

Arguments

*packages

Packages to install on the system.

def remove()

Remove one or more packages from the system.

Arguments

*packages

Packages to remove from system.

def fetch(package: str)

Fetch information about a package.

Arguments

package

Package to get information about.

Returns

Information about package.

def add_repo(repo: str)

Add a new repository to DNF.

Arguments

repo

URL of new repository to add.