images – Image metadata

This module provides classes for manipulating images.json files. images.json files provide details about images included in composes.

Example::

import productmd.compose compose = productmd.compose.Compose(“/path/to/compose”)

# Print the entire dict that maps all variants, arches, and images for this # compose: print(compose.images.images)

# Find all the qcow2 images in this compose: qcow2s = set()

for variant in compose.images.images:
for arch in compose.images.images[variant]:
for images in compose.images.images[variant].values():
if image.type == ‘qcow2’:

qcow2s.add(image)

print(qcow2s)

print(qcow2s)

# … prints the set of qcow2 images in all our variants: # [<Image:Server-RT/x86_64/images/rhel-kvm-rt-image-7.6-220.x86_64.qcow2:qcow2:x86_64>, # <Image:Server/x86_64/images/rhel-guest-image-7.6-210.x86_64.qcow2:qcow2:x86_64>, # <Image:Server/ppc64le/images/rhel-guest-image-7.6-210.ppc64le.qcow2:qcow2:ppc64le>]

Classes

class productmd.images.Images
serialize(parser, force_version=None)

Serialize images metadata.

Parameters:
  • parser (dict) – Dictionary to serialize into

  • force_version (tuple or None) – Force output version (overrides output_version)

add(variant, arch, image)

Assign an Image object to variant and arch.

Parameters:
  • variant (str) – compose variant UID

  • arch (str) – compose architecture

  • image (Image) – image

detect_data_version(data: Dict[str, Any]) Tuple[int, int]

Detect version from parsed data.

Parameters:

data (dict) – Parsed metadata

Returns:

Version tuple

Return type:

tuple

dump(f)

Dump data to a file.

Parameters:

f (file or str) – file-like object or path to file

dumps()

Dump data to a string.

Return type:

str

get_output_version(force_version: Tuple[int, int] | None = None) Tuple[int, int]

Resolve the effective output version.

Priority: force_version > output_version (instance) > _default_output_version (class)

Parameters:

force_version (tuple or None) – Explicit version override

Returns:

Version tuple

Return type:

tuple

load(f)

Load data from a file.

Parameters:

f (file or str) – file-like object or path to file

loads(s)

Load data from a string.

Parameters:

s (str) – input data

property output_version: Tuple[int, int]

Get the version to use when serializing.

Returns the instance override if set, otherwise the class default.

Returns:

Version tuple (major, minor)

Return type:

tuple

should_use_locations() bool

Check if Location objects should be used for output.

Returns:

True if using v2.0+ format

Return type:

bool

validate()

Validate attributes by running all self._validate_*() methods.

Raises:
  • TypeError – if an attribute has invalid type

  • ValueError – if an attribute contains invalid value

class productmd.images.Image(parent)
path

(str) – relative path to an image, for example: “Server/x86_64/iso/boot.iso”

mtime

(int) – image mtime

size

(int) – image size

volume_id

(str) –

type

(str) –

format

(str) – Release name, for example: “Fedora”, “Red Hat Enterprise Linux”

arch

(str) – image architecture, for example: “x86_64”, “src”

disc_number

(int) – Release name, for example: “Fedora”, “Red Hat Enterprise Linux”

disc_count

(int) – Release name, for example: “Fedora”, “Red Hat Enterprise Linux”

checksums

(str) – Release name, for example: “Fedora”, “Red Hat Enterprise Linux”

implant_md5

(str or None) – value of implanted md5

bootable

(bool=False) –

subvariant

(str) – image contents, may be same as variant or e.g. ‘KDE’, ‘LXDE’

unified

(bool=False) – indicates if the ISO contains content from multiple variants

additional_variants

([str]) – indicates which variants are present on the ISO

property location

Get or create a Location object for this image (v2.0).

For v1.2 images, this synthesizes a Location from path/size/checksums and caches it. For v2.0 images, this returns the stored Location.

Returns:

Location object

Return type:

productmd.location.Location

property is_remote

Check if this image has a remote location (v2.0 distributed).

Returns:

True if image is stored remotely

Return type:

bool

serialize(parser, force_version=None)

Serialize image to a list (appends to parser).

Parameters:
  • parser (list) – List to append serialized data to

  • force_version (tuple or None) – Force output version (default: use parent’s version)

deserialize(data)

Deserialize image from a dictionary.

Uses header version to determine format: - v2.0+: Uses Location objects - v1.x: Uses path/size/checksums fields

Parameters:

data (dict) – Dictionary with image data

dump(f)

Dump data to a file.

Parameters:

f (file or str) – file-like object or path to file

dumps()

Dump data to a string.

Return type:

str

load(f)

Load data from a file.

Parameters:

f (file or str) – file-like object or path to file

loads(s)

Load data from a string.

Parameters:

s (str) – input data

validate()

Validate attributes by running all self._validate_*() methods.

Raises:
  • TypeError – if an attribute has invalid type

  • ValueError – if an attribute contains invalid value