blivet package

Subpackages

Submodules

blivet.actionlist module

class blivet.actionlist.ActionList(addfunc=None, removefunc=None)

Bases: object

add(action)
find(device=None, action_type=None, object_type=None, path=None, devid=None)

Find all actions that match all specified parameters.

A value of None for any of the keyword arguments indicates that any value is acceptable for that field.

Parameters:
  • device (StorageDevice or None) – device to match

  • action_type (str or None) – action type to match (eg: “create”, “destroy”)

  • object_type (str or None) – operand type to match (eg: “device” or “format”)

  • path (str or None) – device path to match

  • devid (int or None) – device id to match

Returns:

a list of matching actions

Return type:

list of DeviceAction

process(callbacks=None, devices=None, fstab=None, dry_run=None)

Execute all registered actions.

Parameters:
  • callbacks (DoItCallbacks) – callbacks to be invoked when actions are executed

  • devices – a list of all devices current in the devicetree

  • fstab – FSTabManagerObject tied to blivet, if None fstab file will not be modified

prune()

Remove redundant/obsolete actions from the action list.

remove(action)
sort()

Sort actions based on dependencies.

blivet.actionlist.with_flag(flag_attr)

Decorator to set a flag attribute while running a method.

blivet.arch module

blivet.arch.get_arch()
Returns:

The hardware architecture

Return type:

string

blivet.arch.get_ppc_mac_book()
Returns:

True if the hardware is an i_book or PowerBook, False otherwise.

Return type:

string

blivet.arch.get_ppc_mac_gen()
Returns:

The PPC generation, or None if not PPC or a powermac.

Return type:

string

blivet.arch.get_ppc_mac_id()
Returns:

The powermac machine type, or None if not PPC or a powermac.

Return type:

string

blivet.arch.get_ppc_machine()
Returns:

The PPC machine type, or None if not PPC.

Return type:

string

blivet.arch.is_aarch64()
Returns:

True if the hardware supports Aarch64, False otherwise.

Return type:

boolean

blivet.arch.is_alpha()
Returns:

True if the hardware supports Alpha, False otherwise.

Return type:

boolean

blivet.arch.is_arm()
Returns:

True if the hardware supports ARM, False otherwise.

Return type:

boolean

blivet.arch.is_cell()
Returns:

True if the hardware is the Cell platform, False otherwise.

Return type:

boolean

blivet.arch.is_efi()
Returns:

True if the hardware supports EFI, False otherwise.

Return type:

boolean

blivet.arch.is_ia64()
Returns:

True if the hardware supports IA64, False otherwise.

Return type:

boolean

blivet.arch.is_ipseries()
blivet.arch.is_loongarch(bits=None)
Returns:

True if the hardware supports loongarch, False otherwise.

Return type:

boolean

Parameters:

bits (int) – The number of bits used to define a memory address.

blivet.arch.is_mactel()
Returns:

True if the hardware is an Intel-based Apple Mac, False otherwise.

Return type:

boolean

blivet.arch.is_pmac()
blivet.arch.is_powernv()
blivet.arch.is_ppc(bits=None)
Returns:

True if the hardware supports PPC, False otherwise.

Return type:

boolean

Parameters:

bits (int) – The number of bits used to define a memory address.

blivet.arch.is_riscv64()
Returns:

True if the hardware supports RISCV64, False otherwise.

Return type:

boolean

blivet.arch.is_s390()
Returns:

True if the hardware supports s390(x), False otherwise.

Return type:

boolean

blivet.arch.is_t2mac()
Returns:

True if the hardware is an Intel-based Apple Mac with the T2 security chip, False otherwise.

:rtype boolean

blivet.arch.is_x86(bits=None)
Returns:

True if the hardware supports X86, False otherwise.

Return type:

boolean

Parameters:

bits (int) – The number of bits used to define a memory address.

blivet.arch.num_bits()

Return an integer representing the length of the “word” used by the current architecture -> it is usually either 32 or 64

Returns:

number of bits for the current architecture

or None if the number could not be determined :rtype: integer or None

blivet.blivet module

class blivet.blivet.Blivet

Bases: object

Top-level class for managing storage configuration.

property btrfs_volumes

A list of the BTRFS volumes in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

compare_disks(first, second)
property compare_disks_key

Return an attribute of instance, which is of type owner.

copy()
create_device(device)

Schedule creation of a device.

Parameters:

device (StorageDevice) – the device to schedule creation of

Return type:

None

property default_fstype

Return an attribute of instance, which is of type owner.

destroy_device(device)

Schedule destruction of a device.

Parameters:

device (StorageDevice) – the device to schedule destruction of

Return type:

None

device_deps(device)

Return a list of the devices that depend on the specified device.

Parameters:

device (StorageDevice) – the subtree root device

Returns:

list of dependent devices

Return type:

list

property devices

A list of all the devices in the device tree.

property disks

A list of the disks in the device tree.

Ignored disks are excluded, as are disks with no media present.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

do_it(callbacks=None)

Commit queued changes to disk.

Parameters:

callbacks (return value of the create_new_callbacks_register()) – callbacks to be invoked when actions are executed

dump_state(suffix)

Dump the current device list to the storage shelf.

property encryption_passphrase

Return an attribute of instance, which is of type owner.

factory_device(device_type=0, **kwargs)

Schedule creation of a device based on a top-down specification.

Parameters:

device_type (int (DEVICE_TYPE_*)) – device type constant

Returns:

the newly configured device

Return type:

StorageDevice

See DeviceFactory for possible kwargs.

format_device(device, fmt)

Schedule formatting of a device.

Parameters:
  • device (StorageDevice) – the device to create the formatting on

  • fmt – the format to create on the device

Return type:

None

A format destroy action will be scheduled first, so it is not necessary to create and schedule an ActionDestroyFormat prior to calling this method.

get_free_space(disks=None, partitions=None)

Return a dict with free space info for each disk.

The dict values are 2-tuples: (disk_free, fs_free). fs_free is space available by shrinking filesystems. disk_free is space not allocated to any partition.

disks and partitions allow specifying a set of disks other than self.disks and partition values other than self.partitions.

Parameters:
Returns:

dict with disk name keys and tuple (disk, fs) free values

Return type:

dict

Note

The free space values are Size instances.

get_fstype(mountpoint=None)

Return the default filesystem type based on mountpoint.

initialize_disk(disk)

(Re)initialize a disk by creating a disklabel on it.

The disk should not contain any partitions except perhaps for a magic partitions on mac and sun disklabels. If the disk does contain partitions other than the disklabel-type-specific “magic” partitions ValueError will be raised.

Parameters:

disk (StorageDevice) – the disk to initialize

Returns None:

Raises:

ValueError

property lvs

A list of the LVM Logical Volumes in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

property mdarrays

A list of the MD arrays in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

property mdcontainers

A list of the MD containers in the device tree.

property mdmembers

A list of the MD member devices in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

property mountpoints

Return an attribute of instance, which is of type owner.

property names

A list of all of the known in-use device names.

new_btrfs(*args, **kwargs)

Return a new BTRFSVolumeDevice or BRFSSubVolumeDevice.

Parameters:
  • fmt_args (dict) – arguments for format constructor

  • mountpoint (str) – mountpoint for format (filesystem)

  • subvol (bool) – whether this is a subvol (as opposed to a volume)

Returns:

the new device

Return type:

BTRFSDevice

All other arguments are passed on to the appropriate BTRFSDevice constructor.

For volumes, the label is the same as the name. If a name/label is not specified, one will be generated based on the hostname and/or product name.

Note

If you are creating a subvolume, the parents kwarg should contain the volume you want to contain the subvolume.

new_btrfs_sub_volume(*args, **kwargs)

Return a new BRFSSubVolumeDevice.

Parameters:
  • fmt_args (dict) – arguments for format constructor

  • mountpoint (str) – mountpoint for format (filesystem)

Returns:

the new device

Return type:

BTRFSSubVolumeDevice

All other arguments are passed on to the BTRFSSubVolumeDevice constructor.

Note

Since you are creating a subvolume, the parents kwarg should contain the volume you want to contain the subvolume.

new_lv(*args, **kwargs)

Return a new LVMLogicalVolumeDevice instance.

Parameters:
  • fmt_type (str) – format type

  • fmt_args (dict) – arguments for format constructor

  • mountpoint (str) – mountpoint for format (filesystem)

  • thin_pool (bool) – whether to create a thin pool

  • thin_volume (bool) – whether to create a thin volume

  • vdo_pool (bool) – whether to create a vdo pool

  • vdo_lv (bool) – whether to create a vdo lv

  • cache_pool (bool) – whether to create a cache pool

Returns:

the new device

Return type:

LVMLogicalVolumeDevice

All other arguments are passed on to the appropriate LVMLogicalVolumeDevice constructor.

If a name is not specified, one will be generated based on the format type and/or mountpoint.

Note

If you are creating a thin volume, the parents kwarg should contain the pool – not the vg.

new_lv_from_lvs(vg, name, seg_type, from_lvs, **kwargs)

Return a new LVMLogicalVolumeDevice created from other LVs

Parameters:
  • vg (LVMVolumeGroupDevice) – VG to create the new LV in

  • name (str) – name of the new LV

  • seg_type (str) – segment type of the new LV

  • from_lvs (tuple of LVMLogicalVolumeDevice) – LVs to create the new LV from (in the (data_lv, metadata_lv) order)

Return type:

LVMLogicalVolumeDevice

All other arguments are passed on to the LVMLogicalVolumeDevice constructor.

new_mdarray(*args, **kwargs)

Return a new MDRaidArrayDevice instance.

Parameters:
  • fmt_type (str) – format type

  • fmt_args (dict) – arguments for format constructor

  • mountpoint (str) – mountpoint for format (filesystem)

Returns:

the new md array device

Return type:

MDRaidArrayDevice

All other arguments are passed on to the MDRaidArrayDevice constructor.

If a name is not specified, one will be generated based on the format type, mountpoint, hostname, and/or product name.

new_partition(*args, **kwargs)

Return a new (unallocated) PartitionDevice instance.

Parameters:
  • fmt_type (str) – format type

  • fmt_args (dict) – arguments for format constructor

  • mountpoint (str) – mountpoint for format (filesystem)

All other arguments are passed on to the PartitionDevice constructor.

new_stratis_filesystem(*args, **kwargs)

Return a new StratisFilesystemDevice instance.

Parameters:

mountpoint (str) – mountpoint for filesystem

Returns:

the new device

Return type:

StratisFilesystemDevice

All other arguments are passed on to the appropriate StratisFilesystemDevice constructor.

If a name is not specified, one will be generated based on the format type and/or mountpoint.

new_stratis_pool(*args, **kwargs)

Return a new StratisPoolDevice instance.

Returns:

the new Stratis pool device

Return type:

StratisPoolDevice

All arguments are passed on to the StratisPoolDevice constructor.

If a name is not specified, one will be generated based on the hostname, and/or product name.

new_tmp_fs(*args, **kwargs)

Return a new TmpFSDevice.

new_vg(*args, **kwargs)

Return a new LVMVolumeGroupDevice instance.

Returns:

the new volume group device

Return type:

LVMVolumeGroupDevice

All arguments are passed on to the LVMVolumeGroupDevice constructor.

If a name is not specified, one will be generated based on the hostname, and/or product name.

property next_id

Used for creating unique placeholder names.

property packages

Return an attribute of instance, which is of type owner.

property partitioned

A list of the partitioned devices in the device tree.

Ignored devices are not included, nor disks with no media present.

Devices of types for which partitioning is not supported are also not included.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

property partitions

A list of the partitions in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

property pvs

A list of the LVM Physical Volumes in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

recursive_remove(device)

Remove a device after removing its dependent devices.

If the device is not a leaf, all of its dependents are removed recursively until it is a leaf device. At that point the device is removed, unless it is a disk. If the device is a disk, its formatting is removed by no attempt is made to actually remove the disk device.

remove_empty_extended_partitions()
reset(cleanup_only=False)

Reset storage configuration to reflect actual system state.

This will cancel any queued actions and rescan from scratch but not clobber user-obtained information like passphrases, iscsi config, &c

Parameters:

cleanup_only (bool) – prepare the tree only to deactivate devices

See devicetree.Devicetree.populate() for more information about the cleanup_only keyword argument.

reset_device(device)

Cancel all scheduled actions and reset formatting.

Parameters:

device (StorageDevice) – the device to reset

Return type:

None

resize_device(device, new_size)

Schedule a resize of a device and its formatting, if any.

Parameters:
  • device (StorageDevice) – the device to resize

  • new_size (Size) – the new target size for the device

Return type:

None

If the device has formatting that is recognized as being resizable an action will be scheduled to resize it as well.

safe_device_name(name, device_type=None)

Convert a device name to something safe and return that.

LVM limits lv names to 128 characters. I don’t know the limits for the other various device types, so I’m going to pick a number so that we don’t have to have an entire library to determine device name limits.

save_passphrase(device)
set_default_fstype(newtype)

Set the default fstype for this instance.

Raise ValueError on invalid input.

setup_disk_images()
property short_product_name

Return an attribute of instance, which is of type owner.

property stratis_pools

A list of the Stratis pools in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

suggest_container_name(prefix='', container_type=None)

Return a reasonable, unused device name.

Parameters:

prefix – a prefix for the container name

Returns:

the suggested name

Return type:

str

suggest_device_name(parent=None, swap=None, mountpoint=None, prefix='', device_type=None)

Return a suitable, unused name for a new device.

Parameters:
  • parent (StorageDevice) – the parent device

  • swap (bool) – will this be a swap device

  • mountpoint (str) – the device’s mountpoint

  • prefix (str) – device name prefix

Returns:

the suggested name

Return type:

str

property swaps

A list of the swap devices in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

property thinlvs

A list of the LVM Thin Logical Volumes in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

property thinpools

A list of the LVM Thin Pool Logical Volumes in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

unique_device_name(name, parent=None, name_set=True, device_type=None)

Turn given name into a unique one by adding numeric suffix to it

property vgs

A list of the LVM Volume Groups in the device tree.

This is based on the current state of the device tree and does not necessarily reflect the actual on-disk state of the system’s disks.

blivet.callbacks module

Module providing classes defining the callbacks used by Blivet and their arguments.

class blivet.callbacks.CallbackList

Bases: object

add(cb)

Add a callback.

remove(cb)

Remove a callback.

class blivet.callbacks.Callbacks

Bases: object

A collection of callbacks for various events

Each trigger/event gets a list of callbacks to run, represented by an instance of CallbackList.

action_added

callback list for when an action is added/registered/scheduled

action_executed

callback list for when an action is executed

action_removed

callback list for when an action is removed/canceled

attribute_changed

callback list for when a device or format attribute’s value is changed

device_added

callback list for when a device is added to the devicetree

device_removed

callback list for when a device is removed from the devicetree

device_scanned

callback list for when a device scan is completed

format_added

callback list for when a format is added to a device

format_removed

callback list for when a format is removed from a device

parent_added

callback list for when a member device is added to a container device

parent_removed

callback list for when a member device is removed from a container device

populate_started

callback list for when devicetree population is started

class blivet.callbacks.CreateFormatPostData(msg)

Bases: tuple

Create new instance of CreateFormatPostData(msg,)

msg

Alias for field number 0

class blivet.callbacks.CreateFormatPreData(msg)

Bases: tuple

Create new instance of CreateFormatPreData(msg,)

msg

Alias for field number 0

class blivet.callbacks.ReportProgressData(msg)

Bases: tuple

Create new instance of ReportProgressData(msg,)

msg

Alias for field number 0

class blivet.callbacks.ResizeFormatPostData(msg)

Bases: tuple

Create new instance of ResizeFormatPostData(msg,)

msg

Alias for field number 0

class blivet.callbacks.ResizeFormatPreData(msg)

Bases: tuple

Create new instance of ResizeFormatPreData(msg,)

msg

Alias for field number 0

class blivet.callbacks.WaitForEntropyData(msg, min_entropy)

Bases: tuple

Create new instance of WaitForEntropyData(msg, min_entropy)

min_entropy

Alias for field number 1

msg

Alias for field number 0

blivet.callbacks.create_new_callbacks_register(create_format_pre=None, create_format_post=None, resize_format_pre=None, resize_format_post=None, wait_for_entropy=None, report_progress=None)

A function for creating a new opaque object holding the references to callbacks. The point of this function is to hide the implementation of such object and to provide default values for non-specified fields (e.g. newly added callbacks).

Parameters:

wait_for_entropy (WaitForEntropyData -> bool) – callback for waiting for enough entropy whose return value indicates whether continuing regardless of available entropy should be forced (True) or not (False)

blivet.deviceaction module

class blivet.deviceaction.ActionAddMember(*args, **kwargs)

Bases: DeviceAction

An action representing addition of a member device to a container.

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 3
obsoletes(action)
  • remove same member from same container
    • add same member to same container w/ higher id

obsoleted by
  • destroy the container

  • destroy the device

  • remove same member from same container

requires(action)
  • create/resize the same device

required by
  • any create/grow action on a device in the same container

type = 50
type_desc_str = 'add container member'
class blivet.deviceaction.ActionConfigureDevice(*args, **kwargs)

Bases: DeviceAction

An action change of an attribute of a device

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 2
obsoletes(action)

Return True is self obsoletes action.

ActionConfigureDevice instances obsolete other ActionConfigureDevice instances with lower id, same device and same attribute.

type = 5
type_desc_str = 'configure device'
class blivet.deviceaction.ActionConfigureFormat(*args, **kwargs)

Bases: DeviceAction

An action change of an attribute of device format

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 1
obsoletes(action)

Return True is self obsoletes action.

ActionConfigureFormat instances obsolete other ActionConfigureFormat instances with lower id, same device and same attribute.

type = 5
type_desc_str = 'configure format'
class blivet.deviceaction.ActionCreateDevice(*args, **kwargs)

Bases: DeviceAction

Action representing the creation of a new device.

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 2
requires(action)

Return True if self requires action.

Device create actions require other actions when either of the following is true:

  • this action’s device depends on the other action’s device

  • both actions are partition create actions on the same disk and this partition has a higher number

  • the other action adds a member to this device’s container

type = 100
type_desc_str = 'create device'
class blivet.deviceaction.ActionCreateFormat(*args, **kwargs)

Bases: DeviceAction

An action representing creation of a new filesystem.

Parameters:
  • device (StorageDevice) – the device on which the format will be created

  • fmt (:class:~.formats.DeviceFormat`) – the format to put on the device

If no format is specified, it is assumed that the format is already associated with the device.

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 1
obsoletes(action)

Return True if this action obsoletes action.

Format create actions obsolete the following actions:

  • format actions w/ lower id on this action’s device, other than those that destroy existing formats

requires(action)

Return True if self requires action.

Format create action can require another action if:

  • this action’s device depends on the other action’s device and the other action is not a device destroy action or a container action

  • the other action is a create or resize of this action’s device

type = 100
type_desc_str = 'create format'
class blivet.deviceaction.ActionDestroyDevice(*args, **kwargs)

Bases: DeviceAction

An action representing the deletion of an existing device.

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 2
obsoletes(action)

Return True if self obsoletes action.

  • obsoletes all actions w/ lower id that act on the same device, including self, if device does not exist

  • obsoletes all but ActionDestroyFormat and ActionRemoveMember actions w/ lower id on the same device if device exists

  • obsoletes all actions that add a member to this action’s (container) device

requires(action)

Return True if self requires action.

Device destroy actions require other actions when either of the following is true:

  • the other action’s device depends on this action’s device

  • both actions are partition create actions on the same disk and this partition has a lower number

  • the other action removes this action’s device from a container

type = 1000
type_desc_str = 'destroy device'
class blivet.deviceaction.ActionDestroyFormat(*args, **kwargs)

Bases: DeviceAction

An action representing the removal of an existing filesystem.

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

wipe the filesystem signature from the device

property format

Return an attribute of instance, which is of type owner.

obj = 1
obsoletes(action)

Return True if this action obsoletes action.

Format destroy actions obsolete the following actions:

  • non-destroy format actions w/ lower id on same device, including self if format does not exist

  • destroy format action w/ higher id on same device

  • format destroy action on a non-existent format shouldn’t obsolete a format destroy action on an existing one

requires(action)

Return True if self requires action.

Format destroy actions require other actions when:

  • the other action’s device depends on this action’s device and the other action is a destroy action

  • the other action removes this action’s device from a container

type = 1000
type_desc_str = 'destroy format'
class blivet.deviceaction.ActionRemoveMember(*args, **kwargs)

Bases: DeviceAction

An action representing removal of a member device from a container.

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 3
obsoletes(action)
  • add same member to same container
    • remove same member from same container w/ higher id

obsoleted by
  • add same member to same container

requires(action)
  • any destroy/shrink action on a device in the same container
    • any add action on this container

required by
  • any destroy/resize action on the device

type = 10
type_desc_str = 'remove container member'
class blivet.deviceaction.ActionResizeDevice(*args, **kwargs)

Bases: DeviceAction

An action representing the resizing of an existing device.

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 2
requires(action)

Return True if self requires action.

A device resize action requires another action if:

  • the other action is a format resize on the same device and both are shrink operations

  • the other action grows a device (or format it contains) that this action’s device depends on

  • the other action shrinks a device (or format it contains) that depends on this action’s device

  • this action is a grow action and the other action is a shrink action and the two actions’ respective devices share one or more ancestors

  • the other action removes this action’s device from a container

  • the other action adds a member to this device’s container

type = 500
type_desc_str = 'resize device'
class blivet.deviceaction.ActionResizeFormat(*args, **kwargs)

Bases: DeviceAction

An action representing the resizing of an existing filesystem.

XXX Do we even want to support resizing of a filesystem without

also resizing the device it resides on?

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

obj = 1
requires(action)

Return True if self requires action.

A format resize action requires another action if:

  • the other action is a device resize on the same device and both are grow operations

  • the other action shrinks a device (or format it contains) that depends on this action’s device

  • the other action grows a device (or format) that this action’s device depends on

  • the other action removes this action’s device from a container

type = 500
type_desc_str = 'resize format'
class blivet.deviceaction.DeviceAction(*args, **kwargs)

Bases: ObjectID

An action that will be carried out in the future on a Device.

These classes represent actions to be performed on devices or filesystems.

The operand Device instance will be modified according to the action, but no changes will be made to the underlying device or filesystem until the DeviceAction instance’s execute method is called. The DeviceAction instance’s cancel method should reverse any modifications made to the Device instance’s attributes.

If the Device instance represents a pre-existing device, the constructor should call any methods or set any attributes that the action will eventually change. Device/DeviceFormat classes should verify that the requested modifications are reasonable and raise an exception if not.

Only one action of any given type/object pair can exist for any given device at any given time. This is enforced by the DeviceTree.

Basic usage:

a = DeviceAction(dev) a.execute()

OR

a = DeviceAction(dev) a.cancel()

XXX should we back up the device with a deep copy for forcibly

cancelling actions?

The downside is that we lose any checking or verification that would get done when resetting the Device instance’s attributes to their original values.

The upside is that we would be guaranteed to achieve a total reversal. No chance of, eg: resizes ending up altering Device size due to rounding or other miscalculation.

apply()

apply changes related to the action to the device(s)

cancel()

cancel the action

execute(callbacks=None)

Perform the action.

Parameters:

callbacks – callbacks to be run when matching actions are executed (see do_it())

property format

Return an attribute of instance, which is of type owner.

property is_add

Return an attribute of instance, which is of type owner.

property is_configure

Return an attribute of instance, which is of type owner.

property is_container

Return an attribute of instance, which is of type owner.

property is_create

Return an attribute of instance, which is of type owner.

property is_destroy

Return an attribute of instance, which is of type owner.

property is_device

Return an attribute of instance, which is of type owner.

property is_format

Return an attribute of instance, which is of type owner.

property is_grow

Return an attribute of instance, which is of type owner.

property is_remove

Return an attribute of instance, which is of type owner.

property is_resize

Return an attribute of instance, which is of type owner.

property is_shrink

Return an attribute of instance, which is of type owner.

obj = 0
property object_string

String indicating if this action’s operand is device or format.

property object_type_string

String representing the type of the operand device or format.

obsoletes(action)

Return True is self obsoletes action.

DeviceAction instances obsolete other DeviceAction instances with lower id and same device.

requires(action)

Return True if self requires action.

property resize_string

String representing the direction of a resize action.

type = 0
property type_desc

Return an attribute of instance, which is of type owner.

type_desc_str = ''
property type_string

String indicating if this action is a create, destroy or resize.

blivet.deviceaction.action_object_from_string(type_string)
blivet.deviceaction.action_type_from_string(type_string)
blivet.deviceaction.resize_type_from_string(type_string)

blivet.devicefactory module

class blivet.devicefactory.BTRFSFactory(storage, **kwargs)

Bases: DeviceFactory

BTRFS subvolume

Parameters:
  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

child_factory_class

alias of PartitionSetFactory

child_factory_fstype = 'btrfs'
property container_list

List of containers of the appropriate type for this class.

class blivet.devicefactory.DeviceFactory(storage, **kwargs)

Bases: object

Class for creation of devices based on a top-down specification

DeviceFactory instances can be combined/stacked to create more complex device stacks like lvm with md pvs.

Simplified call trace for creation of a new LV in a new VG with partition PVs:

LVMFactory.configure
    PartitionSetFactory.configure   # set up PVs on partitions
    LVMFactory._create_container    # create container device (VG)
    LVMFactory._create_device       # create leaf device (LV)

Simplified call trace for creation of a new LV in a new VG with a single MD PV with member partitions on multiple disks:

LVMOnMDFactory.configure
    MDFactory.configure
        PartitionSetFactory.configure   # create md partitions
        MDFactory._create_device        # create PV on MD array
    LVMFactory._create_container        # create VG
    LVMFactory._create_device           # create LV

The code below will create a volume group with the name “data” just large enough to contain a new logical volume named “music” with a size of 10000 MB. It will make one physical volume partition on each disk in “disks” that has space. If the resulting volume group is not large enough to contain a logical volume of the specified size, the logical volume will be created with a size that is as close as possible to the requested size. If there is already a non-existent volume group named “data” in the Blivet instance’s device tree, that volume group will be used instead of creating a new one. If the already-defined “data” volume group exists on disk its size will not be changed, but if it has not been written to disk it will be adjusted to hold the new logical volume:

import blivet

_blivet = blivet.Blivet()
_blivet.reset()
disks = _blivet.partitioned

# Create a new LV "music" to a VG named "data", which may or may not
# exist. If the VG exists, the LV will be allocated from free space
# in the VG. If the VG does not exist, one will be created using new
# PVs on each of the specified disks. No free space is maintained in
# new VGs by default.
factory = blivet.devicefactory.LVMFactory(_blivet,
                                          Size("10000 MB"),
                                          disks,
                                          fstype="xfs",
                                          label="music",
                                          name="music",
                                          container_name="data")
factory.configure()
music_lv = factory.device


# Now add another LV to the "data" VG, adjusting the size of a non-
# existent "data" VG so that it can contain the new LV.
factory = blivet.devicefactory.LVMFactory(_blivet,
                                          Size("20000 MB"),
                                          disks,
                                          fstype="xfs",
                                          label="videos",
                                          name="videos",
                                          container_name="data")
factory.configure()

# Now change the size of the "music" LV and adjust the size of the
# "data" VG accordingly.
factory = blivet.devicefactory.LVMFactory(_blivet,
                                          Size("15000 MB"),
                                          disks,
                                          device=music_lv)
factory.configure()

# Write the new devices to disk and create the filesystems they
# contain.
_blivet.do_it()

Some operations (on non-existent devices) these classes do support:

  • create a device and a container to hold it

  • create a device within a defined container

  • create a device within an existing (on disk) container

  • change the set of disks from which partitions used by a factory can be allocated

  • change the size of a defined (but non-existent) device

  • toggle encryption of a leaf device or container member devices

Some operations these classes do not support:

  • any modification to an existing leaf device

  • change an existing container’s member device set

  • resize or rename an existing container

  • move a device from one container to another

  • change the type of a defined device

  • change the container member device type of a defined device

Parameters:
  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

child_factory_class = None
child_factory_fstype = None
configure()

Configure the factory’s device(s).

Keyword arguments:

An example of the parent_factory is the LVMOnMDFactory creating and then using an MDFactory to manage the volume group’s single MD PV.

Another example is the MDFactory creating and then using a PartitionSetFactory to manage the set of member partitions.

property container_list

List of containers of the appropriate type for this class.

property container_raid_level
property devices

A list of this factory’s product devices.

property encrypted
get_container(device=None, name=None, allow_existing=False)

Return the best choice of container for this factory.

Keyword arguments:

device – a defined factory device name – a specific container name to look for allow_existing – whether to allow selection of preexisting

containers

property raid_level
property raw_device

If self.device is encrypted, this is its backing device.

size_set_class

alias of TotalSizeSet

class blivet.devicefactory.LVMFactory(storage, **kwargs)

Bases: DeviceFactory

Factory for creating LVM logical volumes with partition PVs.

Parameters:
  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

child_factory_class

alias of PartitionSetFactory

child_factory_fstype = 'lvmpv'
property container_list

List of containers of the appropriate type for this class.

size_set_class

alias of TotalSizeSet

property vg
class blivet.devicefactory.LVMThinPFactory(storage, **kwargs)

Bases: LVMFactory

Factory for creating LVM using thin provisioning.

This class will be very similar to LVMFactory except that there are two layers of container: vg and thin pool (lv). We could make a separate factory class for creating and managing the thin pool, but we haven’t used a separate factory for any of the other classes’ containers.

pv(s)
vg
pool

thinlv(s)

This is problematic in that there are two containers in this stack: the vg and thin pool.

The thin pool does not need to be large enough to contain all of the thin lvs, so that check/adjust piece must be overridden/skipped here.

XXX We aren’t going to allow overcommitting initially, so that’ll

simplify things somewhat. That means we can manage the thin pool size automatically. We will need to handle overcommit in existing thinp setups in anaconda’s UI.

Because of the argument-passing madness that would ensue from being able to pass specs for two separate containers, the initial version of this class will only support auto-sized pools.

Also, the initial version will only support one thin pool per vg.

In summary:

  • one thin pool per vg

  • pools are auto-sized by anaconda/blivet

  • thinp setups created by the installer will not overcommit

Where to manage the pool:

  • the pool will need to be adjusted on device removal, which means pool management must not be hidden in device management routines

Parameters:
  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

get_pool()
property pool_list
class blivet.devicefactory.LVMVDOFactory(storage, **kwargs)

Bases: LVMFactory

Factory for creating LVM VDO volumes.

Parameters:
  • pool_name (str) – name for the VDO pool, if not specified unique name will be generated

  • virtual_size – size for the VDO volume, usually bigger than pool size, if not specified physical size (pool size) will be used

  • compression (bool) – whether to enable compression (defaults to True)

  • deduplication (bool) – whether to enable deduplication (defaults to True)

  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

class blivet.devicefactory.MDFactory(storage, **kwargs)

Bases: DeviceFactory

Factory for creating MD RAID devices.

Parameters:
  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

child_factory_class

alias of PartitionSetFactory

child_factory_fstype = 'mdmember'
property container_list

List of containers of the appropriate type for this class.

get_container(device=None, name=None, allow_existing=False)

Return the best choice of container for this factory.

Keyword arguments:

device – a defined factory device name – a specific container name to look for allow_existing – whether to allow selection of preexisting

containers

size_set_class

alias of SameSizeSet

class blivet.devicefactory.PartitionFactory(storage, **kwargs)

Bases: DeviceFactory

Factory class for creating a partition.

Parameters:
  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

get_container(device=None, name=None, allow_existing=False)

Return the best choice of container for this factory.

Keyword arguments:

device – a defined factory device name – a specific container name to look for allow_existing – whether to allow selection of preexisting

containers

class blivet.devicefactory.PartitionSetFactory(storage, **kwargs)

Bases: PartitionFactory

Factory for creating a set of related partitions.

Create a new DeviceFactory instance.

Arguments:

storage a Blivet instance size the desired size for the device disks the set of disks to use

Keyword args:

fstype filesystem type encrypted whether to encrypt (boolean)

devices an initial set of devices

configure()

Configure the factory’s device set.

This factory class will always have a parent factory.

property devices

A list of this factory’s product devices.

class blivet.devicefactory.StratisFactory(storage, **kwargs)

Bases: DeviceFactory

Factory for creating Stratis filesystems with partition block devices.

Parameters:
  • storage (Blivet) – a Blivet instance

  • size (Size) – the desired size for the device

  • disks (list of StorageDevice) – the set of disks to use

  • fstype (str) – filesystem type

  • mountpoint (str) – filesystem mount point

  • label (str) – filesystem label text

  • raid_level (any valid RAID level descriptor) – raid level descriptor

  • encrypted (bool) – whether to encrypt (boolean)

  • name (str) – name of requested device

  • device (StorageDevice) – an already-defined but non-existent device to adjust instead of creating a new device

Note

any device passed must be of the appropriate type for the factory class it is passed to

Parameters:
  • container_name (str) – name of requested container

  • container_raid_level (any valid RAID level descriptor) – raid level for container

  • container_encrypted (bool) – whether to encrypt the container

  • container_size (Size, SIZE_POLICY_AUTO (the default), or SIZE_POLICY_MAX) – requested container size

  • min_luks_entropy (int) – minimum entropy in bits required for LUKS format creation

  • luks_version (str) – luks format version (“luks1” or “luks2”)

  • pbkdf_args (LUKS2PBKDFArgs) – optional arguments for LUKS2 key derivation function

  • luks_sector_size (int) – encryption sector size (use only with LUKS version 2)

child_factory_class

alias of PartitionSetFactory

child_factory_fstype = 'stratis'
property container_list

List of containers of the appropriate type for this class.

property pool
size_set_class

alias of TotalSizeSet

blivet.devicefactory.get_device_factory(blivet, device_type=0, **kwargs)

Return a suitable DeviceFactory instance for device_type.

blivet.devicefactory.get_device_type(device)
blivet.devicefactory.get_supported_raid_levels(device_type)

Return the supported raid levels for this device type.

Parameters:

device_type (int) – an enumeration indicating the device type

Returns:

a set of supported raid levels for this device type

Return type:

set of RAIDLevel

blivet.devicefactory.is_supported_device_type(device_type)

Return True if blivet supports this device type.

Parameters:

device_type (int) – an enumeration indicating the device type

Returns:

True if this device type is supported

Return type:

bool

blivet.devicetree module

class blivet.devicetree.DeviceTree(ignored_disks=None, exclusive_disks=None, disk_images=None)

Bases: DeviceTreeBase, PopulatorMixin, EventHandlerMixin

Parameters:
  • ignored_disks (list) – ignored disks

  • exclusive_disks (list) – exclusive didks

reset(ignored_disks=None, exclusive_disks=None, disk_images=None)

Reset the instance to its initial state.

Parameters:
  • ignored_disks (list) – ignored disks

  • exclusive_disks (list) – exclusive didks

class blivet.devicetree.DeviceTreeBase(ignored_disks=None, exclusive_disks=None)

Bases: object

A quasi-tree that represents the devices in the system.

The tree contains a list of StorageDevice instances, which does not necessarily reflect the actual state of the system’s devices. DeviceAction is used to perform modifications to the tree, except when initially populating the tree.

DeviceAction instances are registered, possibly causing the addition or removal of StorageDevice instances to/from the tree. A DeviceAction is reversible up to the time its ‘execute’ method is called.

Only one action of any given type/object pair should exist for any given device at any given time.

DeviceAction instances can only be registered for leaf devices, except for resize actions.

Parameters:
  • ignored_disks (list) – ignored disks

  • exclusive_disks (list) – exclusive didks

property actions

Return an attribute of instance, which is of type owner.

cancel_disk_actions(disks)

Cancel all actions related to the specified disk.

Parameters:

disks – list of disks

This includes actions related directly and indirectly (via container membership, for example).

property devices

List of devices currently in the tree

expand_taglist(taglist)

Expands tags in input list into devices.

Parameters:

taglist – list of strings

Returns:

set of devices

Return type:

set of strings

Raise ValueError if unknown tag encountered in taglist

Note

Returns empty set if taglist is empty

property filesystems

List of filesystems.

get_dependent_devices(dep, hidden=False)

Return a list of devices that depend on dep.

The list includes both direct and indirect dependents.

Parameters:
  • dep (StorageDevice) – the device whose dependents we are looking for

  • hidden (bool) – include hidden devices in search

get_device_by_device_id(device_id, incomplete=False, hidden=False)

Return a device with specified device id.

Parameters:
  • id (str device) – the device id to look for

  • incomplete (bool) – include incomplete devices in search

  • hidden (bool) – include hidden devices in search

Returns:

the first matching device found

Return type:

Device

get_device_by_id(id_num, incomplete=False, hidden=False)

Return a device with specified id.

Parameters:
  • id_num (int) – the id to look for

  • incomplete (bool) – include incomplete devices in search

  • hidden (bool) – include hidden devices in search

Returns:

the first matching device found

Return type:

Device

get_device_by_label(label, incomplete=False, hidden=False)

Return a device with a matching filesystem label.

Parameters:
  • label (str) – the filesystem label to match

  • incomplete (bool) – include incomplete devices in search

  • hidden (bool) – include hidden devices in search

Returns:

the first matching device found

Return type:

Device

get_device_by_name(name, incomplete=False, hidden=False)

Return a device with a matching name.

Parameters:
  • name (str) – the name to look for

  • incomplete (bool) – include incomplete devices in search

  • hidden (bool) – include hidden devices in search

Returns:

the first matching device found

Return type:

Device

get_device_by_path(path, incomplete=False, hidden=False)

Return a device with a matching path.

If there is more than one device with a matching path, prefer a leaf device to a non-leaf device.

Parameters:
  • path (str) – the path to match

  • incomplete (bool) – include incomplete devices in search

  • hidden (bool) – include hidden devices in search

Returns:

the first matching device found

Return type:

Device

get_device_by_sysfs_path(path, incomplete=False, hidden=False)

Return a list of devices with a matching sysfs path.

Parameters:
  • path (str) – the sysfs path to match

  • incomplete (bool) – include incomplete devices in search

  • hidden (bool) – include hidden devices in search

Returns:

the first matching device found

Return type:

Device

get_device_by_uuid(uuid, incomplete=False, hidden=False)

Return a list of devices with a matching UUID.

Parameters:
  • uuid (str) – the UUID to match

  • incomplete (bool) – include incomplete devices in search

  • hidden (bool) – include hidden devices in search

Returns:

the first matching device found

Return type:

Device

get_disk_actions(disks)

Return a list of actions related to the specified disk.

Parameters:

disks – list of disks

Returns:

list of related actions

Return type:

list of DeviceAction

This includes all actions on the specified disks, plus all actions on disks that are in any way connected to the specified disk via container devices.

Return disks related to disk by container membership.

:param StorageDevice disk: the disk :returns: related disks :rtype: set of StorageDevice

Note

The disk may be hidden.

hide(device)

Hide the specified device.

Parameters:

device (StorageDevice) – the device to hide

Hiding a device will cancel all actions that involve the device and will remove the device from the device list.

If the device is not a leaf device, all devices that depend on it will be hidden leaves-first until the device is a leaf device.

If a device exists, performs some special actions and places it on a list of hidden devices.

Mixes recursion and side effects, most significantly in the code that removes all the actions. However, this code is a null op in every case except the first base case that is reached, where all actions are removed. This means that when a device is removed explicitly in this function by means of a direct call to _remove_devices it is guaranteed that all actions have already been canceled.

If a device does not exist then it must have been removed by the cancellation of all the actions, so it does not need to be removed explicitly.

Most devices are considered leaf devices if they have no children, however, some devices must satisfy more stringent requirements. _remove_device() will raise an exception if the device it is removing is not a leaf device. hide() guarantees that any device that it removes will have no children, but it does not guarantee that the more stringent requirements will be enforced. Therefore, _remove_device() is invoked with the force parameter set to True, to skip the isleaf check.

property labels

Dict with label keys and Device values.

FIXME: duplicate labels are a possibility

property leaves

List of all devices upon which no other devices exist.

property mountpoints

Dict with mountpoint keys and Device values.

property names

List of devices names

recursive_remove(device, actions=True, remove_device=True, modparent=True)

Remove a device after removing its dependent devices.

:param StorageDevice device: the device to remove :keyword bool actions: whether to schedule actions for the removal :keyword bool modparent: whether to update parent device upon removal :keyword bool remove_device: whether to remove the root device

If the device is not a leaf, all of its dependents are removed recursively until it is a leaf device. At that point the device is removed, unless it is a disk. If the device is a disk, its formatting is removed but no attempt is made to actually remove the disk device.

reset(ignored_disks=None, exclusive_disks=None)

Reset the instance to its initial state.

Parameters:
  • ignored_disks (list) – ignored disks

  • exclusive_disks (list) – exclusive didks

resolve_device(devspec, blkid_tab=None, crypt_tab=None, options=None, subvolspec=None)

Return the device matching the provided device specification.

The spec can be anything from a device name (eg: ‘sda3’) to a device node path (eg: ‘/dev/mapper/fedora-root’ or ‘/dev/dm-2’) to something like ‘UUID=xyz-tuv-qrs’ or ‘LABEL=rootfs’.

Parameters:
  • devspec (str) – a string describing a block device

  • blkid_tab (BlkidTab) – blkid info

  • crypt_tab (CryptTab) – crypto info

  • options (str) – mount options

  • subvolspec (str) – btrfs subvolume specification

Returns:

the device

Return type:

StorageDevice or None

setup_all()

Run setup methods on all devices.

teardown_all()

Run teardown methods on all devices.

unhide(device)

Restore a device’s visibility.

Parameters:

device (StorageDevice) – the device to restore/unhide

Note

Actions canceled while hiding the device are not rescheduled automatically.

property uuids

Dict with uuid keys and Device values.

blivet.errors module

exception blivet.errors.AlignmentError(*args, **kwargs)

Bases: DiskLabelError

exception blivet.errors.AvailabilityError(*args, **kwargs)

Bases: StorageError

Raised if problem determining availability of external resource.

exception blivet.errors.BTRFSError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.BTRFSValueError(*args, **kwargs)

Bases: BTRFSError, ValueError

exception blivet.errors.CorruptGPTError(message, dev_name=None)

Bases: UnusableConfigurationError

suggestion = 'Either restore the disklabel to a completely working state or remove it completely.\nHint: parted can restore it or wipefs can remove it.'
exception blivet.errors.DMError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.DMRaidMemberError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.DependencyError(*args, **kwargs)

Bases: StorageError

Raised when an external dependency is missing or not available

exception blivet.errors.DeviceActionError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.DeviceCreateError(*args, **kwargs)

Bases: DeviceError

exception blivet.errors.DeviceDestroyError(*args, **kwargs)

Bases: DeviceError

exception blivet.errors.DeviceError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.DeviceFactoryError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.DeviceFormatError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.DeviceNotFoundError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.DeviceResizeError(*args, **kwargs)

Bases: DeviceError

exception blivet.errors.DeviceSetupError(*args, **kwargs)

Bases: DeviceError

exception blivet.errors.DeviceTeardownError(*args, **kwargs)

Bases: DeviceError

exception blivet.errors.DeviceTreeError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.DeviceUserDeniedFormatError(*args, **kwargs)

Bases: DeviceError

exception blivet.errors.DiskLabelCommitError(*args, **kwargs)

Bases: DiskLabelError

exception blivet.errors.DiskLabelError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.DiskLabelScanError(message, dev_name=None)

Bases: UnusableConfigurationError

suggestion = 'For some reason we were unable to locate a disklabel on a disk that the kernel is reporting partitions on. It is unclear what the exact problem is. Please file a bug at http://bugzilla.redhat.com'
exception blivet.errors.DuplicateUUIDError(message, dev_name=None)

Bases: UnusableConfigurationError, ValueError

suggestion = 'This is usually caused by cloning the device image resulting in duplication of the UUID value which should be unique. In that case you can either disconnect one of the devices or reformat it.'
exception blivet.errors.DuplicateVGError(message, dev_name=None)

Bases: UnusableConfigurationError

suggestion = "Rename one of the volume groups so the names are distinct.\nHint 1: vgrename accepts UUID in place of the old name.\nHint 2: You can get the VG UUIDs by running 'pvs -o +vg_uuid'."
exception blivet.errors.EventHandlingError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.EventManagerError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.EventParamError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.FCoEError(*args, **kwargs)

Bases: StorageError, OSError

exception blivet.errors.FSError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.FSReadLabelError(*args, **kwargs)

Bases: FSError

exception blivet.errors.FSResizeError(message, details)

Bases: FSError

exception blivet.errors.FSTabTypeMismatchError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.FSWriteLabelError(*args, **kwargs)

Bases: FSError

exception blivet.errors.FSWriteUUIDError(*args, **kwargs)

Bases: FSError

exception blivet.errors.FormatCreateError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.FormatDestroyError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.FormatResizeError(message, details)

Bases: DeviceFormatError

exception blivet.errors.FormatSetupError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.FormatTeardownError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.GPTVolUUIDError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.ISCSIError(*args, **kwargs)

Bases: StorageError, OSError

exception blivet.errors.InconsistentPVSectorSize(*args, **kwargs)

Bases: DeviceError, ValueError

exception blivet.errors.InconsistentParentSectorSize(*args, **kwargs)

Bases: InconsistentPVSectorSize, DeviceError, ValueError

exception blivet.errors.IntegrityError(*args, **kwargs)

Bases: LUKSError

exception blivet.errors.InvalidDiskLabelError(*args, **kwargs)

Bases: DiskLabelError

exception blivet.errors.InvalidMultideviceSelection(message, dev_name=None)

Bases: UnusableConfigurationError

suggestion = 'All parent devices must be selected when choosing exclusive or ignored disks for a multipath or firmware RAID device.'
exception blivet.errors.LUKSError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.LVMError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.LoopError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.MDMemberError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.MDRaidError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.MPathError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.MultipathMemberError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.NVMeError(*args, **kwargs)

Bases: StorageError, OSError

exception blivet.errors.NoDisksError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.NoParentsError(*args, **kwargs)

Bases: DeviceTreeError

exception blivet.errors.NotEnoughFreeSpaceError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.PartitioningError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.PhysicalVolumeError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.RaidError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.SinglePhysicalVolumeError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.StorageError(*args, **kwargs)

Bases: Exception

exception blivet.errors.StratisError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.SwapSpaceError(*args, **kwargs)

Bases: DeviceFormatError

exception blivet.errors.ThreadError(*args, **kwargs)

Bases: StorageError

An error occurred in a non-main thread.

exception blivet.errors.UdevError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.UnrecognizedFSTabEntryError(*args, **kwargs)

Bases: StorageError

exception blivet.errors.UnusableConfigurationError(message, dev_name=None)

Bases: StorageError

User has an unusable initial storage configuration.

suggestion = ''

blivet.fcoe module

class blivet.fcoe.FCoE

Bases: object

FCoE utility class.

This class will automatically discover and connect to EDD configured FCoE SAN’s when the startup() method gets called. It can also be used to manually configure FCoE SAN’s through the add_san() method.

As this class needs to make sure certain things like starting fcoe daemons and connecting to firmware discovered SAN’s only happens once and as it keeps a global list of all FCoE devices it is implemented as a Singleton.

Warning

Since this is a singleton class, calling deepcopy() on the instance just returns self with no copy being created.

add_san(nic, dcb=False, auto_vlan=True)

Activates FCoE SANs attached to interface specified by nic.

Returns error message, or empty string if succeeded.

startup()
write(root)
write_nic_fcoe_cfg(nic, dcb=True, auto_vlan=True, enable=True, mode=None, root='')
blivet.fcoe.has_fcoe()

blivet.flags module

class blivet.flags.Flags

Bases: object

blivet.fstab module

class blivet.fstab.FSTabEntry(spec=None, file=None, vfstype=None, mntops=None, freq=None, passno=None, comment=None, *, entry=None)

Bases: object

One processed line of fstab

property comment
property entry
property file
property freq
get_raw_mntops()

Return mount options

Returns:

comma separated string of mount options or None when not set

Return type:

str

is_valid()

Verify that this instance has enough data for valid fstab entry

Returns:

False if any of the listed values is not set; otherwise True

Return type:

bool

property mntops

Return mount options

Returns:

list of mount options or None when not set

Return type:

list of str

mntops_add(values)

Append new mount options to already existing ones

Parameters:

values (list of str) – mount options (see man fstab(5) fs_mntops)

property passno
property spec
property vfstype
class blivet.fstab.FSTabManager(src_file=None, dest_file=None)

Bases: object

Read, write and modify fstab file. This class is meant to work even without blivet. However some of its methods require blivet and will not function without it.

Initialize internal table; load the file if specified

Parameters:
  • src_file (str) – Path to fstab file which will be read

  • dest_file – Path to file which will be overwritten with results

add_entry(spec=None, file=None, vfstype=None, mntops=None, freq=None, passno=None, comment=None, *, entry=None)

Add a new entry into the table If both entry and other values are given, these values are prioritized over entry values. If mntops/freq/passno is not set uses their respective default values.

Parameters:
  • spec (str) – device specs (see man fstab(5) fs_spec)

  • file (str) – device mount path (see man fstab(5) fs_file)

  • vfstype (str) – device file system type (see man fstab(5) fs_vfstype)

  • mntops – list of mount option strings (see man fstab(5) fs_mntops)

  • freq (int) – whether to dump the filesystem (see man fstab(5) fs_freq)

  • passno (int) – fsck order or disable fsck if 0 (see man fstab(5) fs_passno)

  • comment (str) – multiline comment added to fstab before entry; each line will be prefixed with “# “

  • entry – fstab entry as an alternative input type

Type:
class:

FSTabEntry

entry_from_action(action)

Generate FSTabEntry object based on given blivet Action

Parameters:

action – action to process

Returns:

fstab entry object based on device processed by action

Return type:

class:

FSTabEntry

entry_from_device(device)

Generate FSTabEntry object based on given blivet Device

Parameters:

device – device to process

Returns:

fstab entry object based on device

Return type:

class:

FSTabEntry

find_device(devicetree, spec=None, mntops=None, blkid_tab=None, crypt_tab=None, *, entry=None)

Find a blivet device, based on spec or entry. Mount options can be used to refine the search. If both entry and spec/mntops are given, spec/mntops are prioritized over entry values.

Parameters:
  • devicetree – populated blivet.Devicetree instance

  • spec (str) – searched device specs (see man fstab(5) fs_spec)

  • mntops – list of mount option strings (see man fstab(5) fs_mntops)

  • blkid_tab – Blkidtab object

  • crypt_tab – Crypttab object

  • entry – fstab entry with its spec (and mntops) filled as an alternative input type

Type:
class:

FSTabEntry

Returns:

found device or None

Return type:

class:

~.devices.StorageDevice or None

find_entry(spec=None, file=None, *, entry=None)

Return the line of loaded fstab with given spec and/or file. If both entry and spec/file are given, spec/file are prioritized over entry values.

Parameters:
  • spec (str) – searched device specs (see man fstab(5) fs_spec)

  • file (str) – device mount path (see man fstab(5) fs_file)

  • entry – fstab entry as an alternative input type

Type:
class:

FSTabEntry

Returns:

found fstab entry object

Return type:

class:

FSTabEntry or None

get_device(devicetree, spec=None, file=None, vfstype=None, mntops=None, blkid_tab=None, crypt_tab=None, *, entry=None)

Parse an fstab entry for a device and return the corresponding device from the devicetree. If not found, try to create a new device based on given values. Raises UnrecognizedFSTabError in case of invalid or incomplete data.

Parameters:
  • devicetree – populated blivet.Devicetree instance

  • spec (str) – searched device specs (see man fstab(5) fs_spec)

  • mntops – list of mount option strings (see man fstab(5) fs_mntops)

  • blkid_tab – Blkidtab object

  • crypt_tab – Crypttab object

  • entry – fstab entry with its values filled as an alternative input type

Type:
class:

FSTabEntry

Returns:

found device

Return type:

class:

~.devices.StorageDevice

read()

Read the fstab file from path stored in self.src_file. Resets currently loaded table contents.

remove_entry(spec=None, file=None, *, entry=None)

Find and remove entry from fstab based on spec/file. If both entry and spec/file are given, spec/file are prioritized over entry values.

Parameters:
  • spec (str) – device specs (see man fstab(5) fs_spec)

  • file (str) – device mount path (see man fstab(5) fs_file)

  • entry – fstab entry as an alternative input type

Type:
class:

FSTabEntry

update(action, bae_entry)

Update fstab based on action type and device. Does not commit changes to a file.

Parameters:
  • action – just executed blivet action

  • bae_entry – fstab entry based on action.device before action.execute was called

write(dest_file=None)

Commit the self._table into the self._dest_file. Setting dest_file parameter overrides writing path with its value.

Parameters:

dest_file (str) – When set, writes fstab to the path specified in it

class blivet.fstab.FSTabManagerIterator(fstab)

Bases: object

Iterator class for FSTabManager Iteration over libmount Table entries is weird - only one iterator can run at a time. This class purpose is to mitigate that.

class blivet.fstab.FSTabOptions

Bases: object

User preferred fstab settings object intended to be attached to device.format. Set variables override otherwise automatically obtained values put into fstab.

blivet.i18n module

blivet.i18n.N_(x)
blivet.i18n.P_(x, y, z)

blivet.iscsi module

class blivet.iscsi.LoginInfo(node, logged_in)

Bases: object

class blivet.iscsi.NodeInfo(name, tpgt, address, port, iface)

Bases: object

Simple representation of node information.

property conn_info

The 5-tuple of connection info (no auth info). This form is useful for interacting with udisks.

class blivet.iscsi.TargetInfo(ipaddr, port)

Bases: tuple

Create new instance of TargetInfo(ipaddr, port)

ipaddr

Alias for field number 0

port

Alias for field number 1

blivet.iscsi.has_iscsi()
class blivet.iscsi.iSCSI

Bases: object

iSCSI utility class.

This class will automatically discover and login to iBFT (or other firmware) configured iscsi devices when the startup() method gets called. It can also be used to manually configure iscsi devices through the add_target() method.

As this class needs to make sure certain things like starting iscsid and logging in to firmware discovered disks only happens once and as it keeps a global list of all iSCSI devices it is implemented as a Singleton.

Warning

Since this is a singleton class, calling deepcopy() on the instance just returns self with no copy being created.

active_nodes(target=None)

Nodes logged in to

add_target(ipaddr, port='3260', user=None, pw=None, user_in=None, pw_in=None, target=None, iface=None, discover_user=None, discover_pw=None, discover_user_in=None, discover_pw_in=None)

Connect to iSCSI server specified by IP address and port and add all targets found on the server and authenticate if necessary. If the target parameter is set, connect only to this target.

NOTE: the iSCSI target can have two sets of different authentication

credentials - one for discovery and one for logging into nodes

Parameters:
  • ipaddr (str) – target IP address

  • port (str) – target port

  • user (str or NoneType) – CHAP username for node login

  • pw (str or NoneType) – CHAP password for node login

  • user_in – reverse CHAP username for node login

  • pw_in (str or NoneType) – reverse CHAP password for node login

  • target (str or NoneType) – only add this target (if present)

  • iface (str or NoneType) – interface to use

  • discover_user (str or NoneType) – CHAP username for discovery

  • discover_pw (str or NoneType) – CHAP password for discovery

  • discover_user_in – reverse CHAP username for discovery

  • discover_pw_in (str or NoneType) – reverse CHAP password for discovery

property available
create_interfaces(ifaces)
delete_interfaces()
discover(ipaddr, port='3260', username=None, password=None, r_username=None, r_password=None)

Discover iSCSI nodes on the target available for login.

If we are logged in a node discovered for specified target do not do the discovery again as it can corrupt credentials stored for the node (set_auth and get_auth are using database in /var/lib/iscsi/nodes which is filled by discovery). Just return nodes obtained and stored in the first discovery instead.

Returns list of nodes user can log in.

get_node(name, address, port, iface)
get_node_disks(node, storage)
property initiator
property initiator_set

True if initiator is set at our level.

log_into_node(node, username=None, password=None, r_username=None, r_password=None)
Parameters:
  • node (NodeInfo) – node to log into

  • username (str) – username to use when logging in

  • password (str) – password to use when logging in

  • r_username (str) – r_username to use when logging in

  • r_password (str) – r_password to use when logging in

property mode
stabilize()
startup()
write(root, storage=None)
class blivet.iscsi.iSCSIDependencyGuard(exn_cls=<class 'blivet.errors.DependencyError'>)

Bases: DependencyGuard

error_msg = 'UDisks iSCSI functionality not available'
blivet.iscsi.iscsi = <blivet.iscsi.iSCSI object>

An instance of iSCSI

blivet.mounts module

class blivet.mounts.MountsCache

Bases: object

Cache object for system mountpoints; checks /proc/mounts and /proc/self/mountinfo for up-to-date information.

get_mountpoints(devspec, subvolspec=None)

Get mountpoints for selected device

Parameters:
  • devscpec – device specification, eg. “/dev/vda1”

  • subvolspec (object (may be NoneType)) – btrfs subvolume specification, eg. ID or name

Returns:

list of mountpoints (path)

Return type:

list of str or empty list

Note

Devices can be mounted on multiple paths, and paths can have multiple devices mounted to them (hiding previous mounts). Callers should take this into account.

is_mountpoint(path)

Check to see if a path is already mounted

Parameters:

path (str) – Path to check

blivet.nvme module

class blivet.nvme.NVMe

Bases: object

NVMe utility class.

Warning

Since this is a singleton class, calling deepcopy() on the instance just returns self with no copy being created.

available()
startup()
write(root, overwrite=True)
blivet.nvme.nvme = <blivet.nvme.NVMe object>

An instance of NVMe

blivet.partitioning module

class blivet.partitioning.Chunk(length, requests=None)

Bases: object

A free region from which devices will be allocated

Parameters:
  • length (int) – the length of the chunk (units vary with subclass)

  • requests (list of Request) – list of requests to add

add_request(req)

Add a request to this chunk.

Parameters:

req (Request) – the request to add

property done

True if we are finished growing all requests in this chunk.

grow_requests(uniform=False)

Calculate growth amounts for requests in this chunk.

Parameters:

uniform (bool) – grow requests uniformly instead of proportionally

The default mode of growth is as follows: given a total number of available units, requests receive an allotment proportional to their base sizes. That means a request with base size 1000 will grow four times as fast as a request with base size 250.

Under uniform growth, all requests receive an equal portion of the free units.

property growth

Sum of growth for all requests in this chunk.

property has_growable

True if this chunk contains at least one growable request.

length_to_size(length)
max_growth(req)
reclaim(request, amount)

Reclaim units from a request and return them to the pool.

Parameters:
  • request (Request) – the request to reclaim units from

  • amount (int) – number of units to reclaim from the request

Raises:

ValueError

Returns:

None

property remaining

Number of requests still being grown in this chunk.

size_to_length(size)
sort_requests()
trim_over_grown_request(req, base=None)

Enforce max growth and return extra units to the pool.

Parameters:
  • req (Request) – the request to trim

  • base (int) – base unit count to adjust if req is done growing

Returns:

the new base or None if no base was given

Return type:

int or None

class blivet.partitioning.DiskChunk(geometry, requests=None)

Bases: Chunk

A free region on disk from which partitions will be allocated

Parameters:
  • geometry (parted.Geometry) – the free region this chunk represents

  • requests (list of PartitionRequest) – list of requests to add initially

Note

We will limit partition growth based on disklabel limitations for partition end sector, so a 10TB disk with an msdos disklabel will be treated like a 2TiB disk.

Note

If you plan to allocate aligned partitions you should pass in an aligned geometry instance.

add_request(req)

Add a request to this chunk.

Parameters:

req (PartitionRequest) – the request to add

length_to_size(length)
max_growth(req)

Return the maximum possible growth for a request.

Parameters:

req (PartitionRequest) – the request

size_to_length(size)
sort_requests()
class blivet.partitioning.LVRequest(lv)

Bases: Request

Parameters:

lv (LVMLogicalVolumeDevice) – the logical volume being requested

property reserve_request

Requested reserved fixed extra space for the request (in sectors)

class blivet.partitioning.PartitionRequest(partition)

Bases: Request

Parameters:

partition (PartitionDevice) – the partition being requested

class blivet.partitioning.Request(device)

Bases: object

A partition request.

Request instances are used for calculating how much to grow partitions.

Parameters:

device (StorageDevice) – the device being requested

property growable

True if this request is growable.

property id

The id of the Device instance this request corresponds to.

property reserve_request

Requested reserved fixed extra space for the request (in sectors)

class blivet.partitioning.SameSizeSet(devices, size, grow=False, max_size=None)

Bases: object

Set of device requests with a common target size.

Parameters:
  • devices (list of PartitionDevice) – the set of devices

  • size (Size) – target size for each device/request

  • grow (bool) – whether the devices can be grown

  • max_size (Size) – the maximum size for growable devices

class blivet.partitioning.ThinPoolChunk(pool, requests=None)

Bases: VGChunk

A free region in an LVM thin pool from which LVs will be allocated

Parameters:
  • pool (LVMLogicalVolumeDevice) – the thin pool whose free space this chunk represents

  • requests (list of LVRequest) – list of requests to add initially

class blivet.partitioning.TotalSizeSet(devices, size)

Bases: object

Set of device requests with a target combined size.

This will be handled by growing the requests until the desired combined size has been achieved.

Parameters:
  • devices (list of PartitionDevice) – the set of devices

  • size (Size) – the target combined size

allocate(amount)
deallocate(amount)
property needed
class blivet.partitioning.VGChunk(vg, requests=None)

Bases: Chunk

A free region in an LVM VG from which LVs will be allocated

Parameters:
  • vg (LVMVolumeGroupDevice) – the volume group whose free space this chunk represents

  • requests (list of LVRequest) – list of requests to add initially

add_request(req)

Add a request to this chunk.

Parameters:

req (LVRequest) – the request to add

length_to_size(length)
size_to_length(size)
sort_requests()
blivet.partitioning.add_partition(disklabel, free, part_type, size, start=None, end=None)

Add a new partition to a disk.

Parameters:
  • disklabel (DiskLabel) – the disklabel to add the partition to

  • free (parted.Geometry) – the free region in which to place the new partition

  • part_type (a parted.PARTITION_* constant) – the partition type

  • size (Size) – size of the new partition

  • start (int) – starting sector for the partition

  • end (int) – ending sector for the partition

Raises:

PartitioningError

Returns:

the newly added partitions

Return type:

parted.Partition

Note

The new partition will be aligned using the kernel-provided optimal alignment unless a start sector is provided.

blivet.partitioning.align_size_for_disklabel(size, disklabel)
blivet.partitioning.allocate_partitions(storage, disks, partitions, freespace, boot_disk=None)

Allocate partitions based on requested features.

Parameters:
  • storage (Blivet) – a Blivet instance

  • disks (list of StorageDevice) – list of usable disks

  • partitions (list of PartitionDevice) – list of partitions

  • freespace (list of parted.Geometry) – list of free regions on disks

  • boot_disk – optional parameter, the disk the bootloader is on

Raises:

PartitioningError

Returns:

None

Non-existing partitions are sorted according to their requested attributes, and then allocated.

The basic approach to sorting is that the more specifically- defined a request is, the earlier it will be allocated. See partitionCompare() for details of the sorting criteria.

The PartitionDevice instances will have their name and parents attributes set once they have been allocated.

blivet.partitioning.do_partitioning(storage, boot_disk=None)

Allocate and grow partitions.

When this function returns without error, all PartitionDevice instances must have their parents set to the disk they are allocated on, and their parted_partition attribute set to the appropriate parted.Partition instance from their containing disk. All req_xxxx attributes must be unchanged.

Parameters:
  • storage (Blivet) – Blivet instance

  • boot_disk – optional parameter, the disk the bootloader is on

Raises:

PartitioningError

Returns:

None

blivet.partitioning.get_best_free_space_region(disk, part_type, req_size, start=None, boot=None, best_free=None, grow=None, alignment=None)

Return the “best” free region on the specified disk.

For non-boot partitions, we return the largest free region on the disk. For boot partitions, we return the first region that is large enough to hold the partition.

Partition type (parted’s PARTITION_NORMAL, PARTITION_LOGICAL) is taken into account when locating a suitable free region.

For locating the best region from among several disks, the keyword argument best_free allows the specification of a current “best” free region with which to compare the best from this disk. The overall best region is returned.

Parameters:
  • disk (parted.Disk) – the disk

  • part_type (one of parted's PARTITION_* constants) – the type of partition we want to allocate

  • req_size (Size) – the requested size of the partition in MiB

  • start (int) – requested start sector for the partition

  • boot (bool) – whether this will be a bootable partition

  • best_free (parted.Geometry) – current best free region for this partition

  • grow (bool) – indicates whether this is a growable request

  • alignment (parted.Alignment) – disk alignment requirements

blivet.partitioning.get_disk_chunks(disk, partitions, free)

Return a list of Chunk instances representing a disk.

Parameters:
  • disk (StorageDevice) – the disk

  • partitions (list of PartitionDevice) – list of partitions

  • free (list of parted.Geometry) – list of free regions

Returns:

list of chunks representing the disk

Return type:

list of DiskChunk

Partitions and free regions not on the specified disk are ignored.

Chunks contain an aligned version of the free region’s geometry.

blivet.partitioning.get_free_regions(disks, align=False)

Return a list of free regions on the specified disks.

Parameters:
  • disks (list of Disk) – list of disks

  • align (bool) – align the region length to disk grain_size

Returns:

list of free regions

Return type:

list of parted.Geometry

Only free regions guaranteed to contain at least one aligned sector for both the start and end alignments in the DiskLabel are returned.

blivet.partitioning.get_next_partition_type(disk, no_primary=None)

Return the type of partition to create next on a disk.

Return a parted partition type value representing the type of the next partition we will create on this disk.

If there is only one free primary partition and we can create an extended partition, we do that.

If there are free primary slots and an extended partition we will recommend creating a primary partition. This can be overridden with the keyword argument no_primary.

Parameters:
  • disk (parted.Disk) – the disk from which a partition may be allocated

  • no_primary – refuse to return parted.PARTITION_NORMAL

Returns:

the chosen partition type

Return type:

a parted PARTITION_* constant

blivet.partitioning.grow_lvm(storage)

Grow LVs according to the sizes of the PVs.

Strategy for growth involving thin pools:
  • Applies to device factory class as well.

  • Overcommit is not allowed.

  • Pool lv’s base size includes sizes of thin lvs within it.

  • Pool is grown along with other non-thin lvs.

  • Thin lvs within each pool are grown separately using the ThinPoolChunk class.

blivet.partitioning.grow_partitions(disks, partitions, free, size_sets=None)

Grow all growable partition requests.

Partitions have already been allocated from chunks of free space on the disks. This function does not modify the ordering of partitions or the free chunks from which they are allocated.

Free space within a given chunk is allocated to each growable partition allocated from that chunk in an amount corresponding to the ratio of that partition’s base size to the sum of the base sizes of all growable partitions allocated from the chunk.

Parameters:
  • disks (list of StorageDevice) – all usable disks

  • partitions (list of PartitionDevice) – all partitions

  • free (list of parted.Geometry) – all free regions on disks

  • size_sets (list of TotalSizeSet or SameSizeSet) – list of size-related partition sets

Returns:

None

blivet.partitioning.lv_compare(lv1, lv2)

More specifically defined lvs come first.

< 1 => x < y

0 => x == y

> 1 => x > y

blivet.partitioning.manage_size_sets(size_sets, chunks)
blivet.partitioning.partition_compare(part1, part2)

More specifically defined partitions come first.

< 1 => x < y

0 => x == y

> 1 => x > y

Parameters:
  • part1 (devices.PartitionDevice) – the first partition

  • part2 (devices.PartitionDevice) – the other partition

Returns:

see above

Return type:

int

blivet.partitioning.remove_new_partitions(disks, remove, all_partitions)

Remove newly added partitions from disks.

Remove all non-existent partitions from the disks in blivet’s model.

Param:

disks: list of partitioned disks

Parameters:
  • remove (list of PartitionDevice) – list of partitions to remove

  • all_partitions (list of PartitionDevice) – list of all partitions on the disks

Returns:

None

Return type:

NoneType

blivet.partitioning.resolve_disk_tags(disks, tags)

Resolve disk tags to a disk list.

Parameters:
  • disks (list of StorageDevice) – available disks

  • tags (list of str) – tags to select disks based on

If tags contains multiple values it is interpreted as “include disks containing any of these tags”.

blivet.partitioning.sectors_to_size(sectors, sector_size)

Convert length in sectors to size.

Parameters:
  • sectors (int) – sector count

  • sector_size (Size) – sector size

Returns:

the size

Return type:

Size

blivet.partitioning.size_to_sectors(size, sector_size)

Convert size to length in sectors.

Parameters:
  • size (Size) – size

  • sector_size (Size) – sector size in bytes

Returns:

sector count

Return type:

int

blivet.partitioning.update_extended_partitions(storage, disks)

Reconcile extended partition changes with the DeviceTree.

Parameters:
  • storage (Blivet) – the Blivet instance

  • disks (list of StorageDevice) – list of disks

Returns:

None

Return type:

NoneType

blivet.safe_dbus module

Module providing thread-safe and mainloop-safe DBus operations.

exception blivet.safe_dbus.DBusCallError

Bases: SafeDBusError

Class for the errors related to calling methods over DBus.

exception blivet.safe_dbus.DBusPropertyError

Bases: DBusCallError

Class for the errors related to getting property values over DBus.

exception blivet.safe_dbus.SafeDBusError

Bases: Exception

Class for exceptions defined in this module.

blivet.safe_dbus.call_sync(service, obj_path, iface, method, args, connection=None, fds=None, timeout=-1)

Safely call a given method on a given object of a given service over DBus passing given arguments. If a connection is given, it is used, otherwise a new connection is established. Safely means that it is a synchronous, thread-safe call not using any main loop.

Parameters:
  • service (str) – DBus service to use

  • obj_path (str) – object path of the object to call method on

  • iface (str) – interface to use

  • method (str) – name of the method to call

  • args (GVariant) – arguments to pass to the method

  • connection (Gio.DBusConnection) – connection to use (if None, a new connection is established)

  • fds – list of file descriptors for the call

  • timeout (int) – timeout in milliseconds for the call (-1 for default timeout)

Type:

Gio.UnixFDList

Returns:

unpacked value returned by the method

Return type:

tuple with elements that depend on the method

Raises:

DBusCallError – if some DBus related error appears

blivet.safe_dbus.check_object_available(service, obj_path, iface=None)
blivet.safe_dbus.get_new_session_connection()

Get a connection handle for the per-user-login-session message bus.

!!! RUN THIS EARLY !!! like, before any other threads start. Connections to the session bus must be made with the effective UID of the login user, which in live installs is not the UID of anaconda. This means we need to call seteuid in this method, and doing that after threads have started will probably do something weird.

Live installs use consolehelper to run as root, which sets the original UID in $USERHELPER_UID.

Returns:

the session connection handle

Return type:

Gio.DBusConnection

Raises:
  • DBusCallError – if some DBus related error appears

  • OSError – if unable to set the effective UID

blivet.safe_dbus.get_new_system_connection()

Return a new connection to the system bus.

blivet.safe_dbus.get_properties_sync(service, obj_path, iface, connection=None)

Get all properties of a given object provided by a given service.

Parameters:
  • service (str) – DBus service to use

  • obj_path (str) – object path

  • iface (str) – interface to use

  • connection (Gio.DBusConnection) – connection to use (if None, a new connection is established)

Returns:

unpacked value of the property

Return type:

tuple with elements that depend on the type of the property

Raises:

DBusCallError – when the internal dbus_call_safe_sync invocation raises an exception

blivet.safe_dbus.get_property_sync(service, obj_path, iface, prop_name, connection=None)

Get value of a given property of a given object provided by a given service.

Parameters:
  • service (str) – DBus service to use

  • obj_path (str) – object path

  • iface (str) – interface to use

  • prop_name (str) – name of the property

  • connection (Gio.DBusConnection) – connection to use (if None, a new connection is established)

Returns:

unpacked value of the property

Return type:

tuple with elements that depend on the type of the property

Raises:
  • DBusCallError – when the internal dbus_call_safe_sync invocation raises an exception

  • DBusPropertyError – when the given object doesn’t have the given property

blivet.size module

class blivet.size.Size(spec=None)

Bases: Size

Common class to represent storage device and filesystem sizes. Can handle parsing strings such as 45MB or 6.7GB to initialize itself, or can be initialized with a numerical size in bytes. Also generates human readable strings to a specified number of decimal places.

convert_to(spec=None)

Return the size in the units indicated by the specifier.

Parameters:

spec (a units specifier or Size) – a units specifier

Returns:

a numeric value in the units indicated by the specifier

Return type:

Decimal

Raises:

ValueError – if Size unit specifier is non-positive

New in version 1.6: spec parameter may be Size as well as units specifier.

ensure_percent_reserve(percent)

Get a new size with given space reserve.

Parameters:

percent – number of percent to reserve

Returns:

a new size with :param:`percent` space reserve

Return type:

Size

Best described with an example: >>> Size(“80 GiB”).ensure_percent_reserve(20) Size (100 GiB)

This method returns a new size in which there’s a :param:`percent`% reserve (on top of the original size). In other words:

with_reserve - orig_size == with_reserve * (percent / 100)

except that due to float arithmetics the numbers are unlikely to be exactly equal.

human_readable(min_unit=0, max_places=2, xlate=True)

Return a string representation of this size with appropriate size specifier and in the specified number of decimal places. Values are always represented using binary not decimal units. For example, if the number of bytes represented by this size is 65531, expect the representation to be something like 64.00 KiB, not 65.53 KB.

Parameters:
  • min_unit (one of the B, KiB, MiB,... (binary) units from this module or str ("B", "KiB",...)) – the smallest unit the returned representation should use

  • max_places (an integer type or NoneType) – number of decimal places to use

  • xlate (bool) – If True, translate for current locale

Returns:

a representation of the size

Return type:

str

round_to_nearest(size, rounding)

Rounds to nearest unit specified as a named constant or a Size.

Parameters:
  • size (a named constant like KiB, or any non-negative Size) – a size specifier

  • rounding (one of ROUND_UP, ROUND_DOWN, or ROUND_HALF_UP) – which direction to round

Returns:

Size rounded to nearest whole specified unit

Return type:

Size

If size is Size(0), returns Size(0).

blivet.size.unit_str(unit, xlate=False)

Return a string representation of unit.

Parameters:
  • unit – a named unit, e.g., KiB

  • xlate (bool) – if True, translate to current locale

Return type:

some kind of string type

Returns:

string representation of unit

blivet.storage_log module

blivet.storage_log.function_name_and_depth()
blivet.storage_log.log_exception_info(log_func=<bound method Logger.debug of <Logger blivet (WARNING)>>, fmt_str=None, fmt_args=None, ignored=True)

Log detailed exception information.

Parameters:
  • log_func – the desired logging function

  • fmt_str (str) – a format string for any additional message

  • fmt_args (a list of str) – arguments for the format string

  • ignored (bool) – True if no action is taken regarding the exception

Note: the logging function indicates the severity level of this exception according to the calling function. log.debug, the default, is the lowest level.

Note: If the ignored flag is set, each line of the exception information is prepended with an ‘IGNORED’ prefix.

blivet.storage_log.log_method_call(d, *args, **kwargs)
blivet.storage_log.log_method_return(d, retval)

blivet.threads module

class blivet.threads.SynchronizedABCMeta(name, bases, dct)

Bases: SynchronizedMeta, ABCMeta

class blivet.threads.SynchronizedMeta(name, bases, dct)

Bases: type

Metaclass that wraps all methods with the exclusive decorator.

To prevent specific methods from being wrapped, add the method name(s) to a class attribute called _unsynchronized_methods (list of str).

blivet.threads.clear_thread_exception()
blivet.threads.exclusive(m)

Run a callable while holding the global lock.

blivet.threads.get_thread_exception()
blivet.threads.save_thread_exception(thread, exc_info)

blivet.tsort module

exception blivet.tsort.CyclicGraphError

Bases: Exception

blivet.tsort.create_graph(items, edges)

Create a graph based on a list of items and a list of edges.

Arguments:

items - an iterable containing (hashable) items to sort edges - an iterable containing (parent, child) edge pair tuples

Return Value:

The return value is a dictionary representing the directed graph. It has three keys:

items is the same as the input argument of the same name edges is the same as the input argument of the same name incoming is a dict of incoming edge count hashed by item

blivet.tsort.main()
blivet.tsort.tsort(graph)

blivet.udev module

blivet.udev.device_dm_subsystem_match(info, subsystem)

Return True if the device matches a given device-mapper subsystem.

blivet.udev.device_get_bus(udev_info)

Get the bus a device is connected to the system by.

blivet.udev.device_get_by_path(info)
blivet.udev.device_get_dasd_bus_id(info)

Return the CCW bus ID of the dasd device.

blivet.udev.device_get_dasd_flag(info, flag=None)

Return the specified flag for the dasd device.

blivet.udev.device_get_devname(info)
blivet.udev.device_get_disklabel_type(info)

Return the type of disklabel on the device or None.

blivet.udev.device_get_disklabel_uuid(info)
blivet.udev.device_get_fcoe_identifier(info)
blivet.udev.device_get_fcoe_nic(info)
blivet.udev.device_get_format(udev_info)

Return a device’s format type as reported by udev.

blivet.udev.device_get_format_version(udev_info)

Return a device’s format version as reported by udev.

blivet.udev.device_get_holders(info)

Return a list of udev device objects representing this device’s holders.

blivet.udev.device_get_iscsi_address(info)
blivet.udev.device_get_iscsi_initiator(info)
blivet.udev.device_get_iscsi_lun(info)
blivet.udev.device_get_iscsi_name(info)
blivet.udev.device_get_iscsi_nic(info)
blivet.udev.device_get_iscsi_port(info)
blivet.udev.device_get_iscsi_session(info)
blivet.udev.device_get_label(udev_info)

Get the label from the device’s format as reported by udev.

blivet.udev.device_get_lv_attr(info)
blivet.udev.device_get_lv_name(info)
blivet.udev.device_get_lv_size(info)
blivet.udev.device_get_lv_type(info)
blivet.udev.device_get_lv_uuid(info)
blivet.udev.device_get_lv_vg_name(info)
blivet.udev.device_get_major(info)
blivet.udev.device_get_md_container(info)
Parameters:

info (dict) – dictionary of name-value pairs as strings

Return type:

str or NoneType

blivet.udev.device_get_md_device_uuid(info)

Returns the uuid of a device which is a member of an md array.

Parameters:

info (dict) – dictionary of name-value pairs as strings

Returns:

the uuid of this device (which is a member of an md array)

Return type:

str or NoneType

blivet.udev.device_get_md_devices(info)

Returns the number of active devices in this device’s array.

Active devices are devices that are not spares or failed.

Parameters:

info (dict) – dictionary of name-value pairs as strings

Returns:

the number of devices belonging to this device’s md array

Return type:

int

Raises:

KeyError, ValueError

blivet.udev.device_get_md_level(info)

Returns the RAID level of the array of which this device is a member.

Parameters:

info (dict) – dictionary of name-value pairs as strings

Returns:

the RAID level of this device’s md array

Return type:

str or NoneType

blivet.udev.device_get_md_metadata(info)

Return the metadata version number.

Parameters:

info (dict) – dictionary of name-value pairs as strings

Returns:

the metadata version number of the md array

Return type:

str or NoneType

blivet.udev.device_get_md_name(info)

Returns the name of the array of which this device is a member.

Parameters:

info (dict) – dictionary of name-value pairs as strings

Returns:

the name of this device’s md array

Return type:

str or NoneType

blivet.udev.device_get_md_uuid(info)

Returns the uuid of the array of which this device is a member.

Parameters:

info (dict) – dictionary of name-value pairs as strings

Returns:

the UUID of this device’s md array

Return type:

str

Raises:

KeyError

blivet.udev.device_get_minor(info)
blivet.udev.device_get_model(udev_info)

Get the model of the device as reported by udev.

blivet.udev.device_get_name(udev_info)

Return the best name for a device based on the udev db data.

blivet.udev.device_get_parents(info)

Return a list of udev device objects representing this device’s parents.

blivet.udev.device_get_part_size(udev_info)

Get size for specified partition as reported by udev.

blivet.udev.device_get_partition_disk(info)

Return the (friendly) name of the given partition’s disk.

blivet.udev.device_get_partition_uuid(info)
blivet.udev.device_get_path(info)
blivet.udev.device_get_pv_pe_start(info)
blivet.udev.device_get_serial(udev_info)

Get the serial number/UUID from the device as reported by udev.

Get an array of symbolic links for a device.

Parameters:

info – a pyudev.Device instance

Returns:

list of symbolic links

Return type:

list of str

blivet.udev.device_get_sysfs_path(info)
blivet.udev.device_get_uuid(udev_info)

Get the UUID from the device’s format as reported by udev.

Parameters:

udev_info (dict) – dictionary of name-value pairs as strings

Returns:

a UUID or None

Return type:

str or NoneType

blivet.udev.device_get_vendor(udev_info)

Get the vendor of the device as reported by udev.

blivet.udev.device_get_vg_extent_count(info)
blivet.udev.device_get_vg_extent_size(info)
blivet.udev.device_get_vg_free(info)
blivet.udev.device_get_vg_free_extents(info)
blivet.udev.device_get_vg_name(info)
blivet.udev.device_get_vg_pv_count(info)
blivet.udev.device_get_vg_size(info)
blivet.udev.device_get_vg_uuid(info)
blivet.udev.device_get_wwn(udev_info)

Return the WWID as reported by udev without ‘0x’ prefix.

blivet.udev.device_get_zfcp_attribute(info, attr=None)

Return the value of the specified attribute of the zfcp device.

blivet.udev.device_is_biosraid_member(info)
blivet.udev.device_is_cciss(info)

Return True if the device is a CCISS device.

blivet.udev.device_is_cdrom(info)

Return True if the device is an optical drive.

blivet.udev.device_is_dasd(info)

Return True if the device is a dasd device.

blivet.udev.device_is_disk(info)

Return True if the device is a disk.

Unfortunately, since so many things are represented as disks by udev/sysfs, we have to define what is a disk in terms of what is not a disk.

blivet.udev.device_is_dm(info)

Return True if the device is a device-mapper device.

blivet.udev.device_is_dm_anaconda(info)

Return True if the device is an anaconda disk image.

blivet.udev.device_is_dm_bitlk(info)

Return True if the device is a mapped BITLK device.

blivet.udev.device_is_dm_crypt(info)

Return True if the device is a mapped dm-crypt device.

blivet.udev.device_is_dm_integrity(info)

Return True if the device is a mapped integrity device.

blivet.udev.device_is_dm_livecd(info)

Return True if the device is a livecd OS image.

blivet.udev.device_is_dm_luks(info)

Return True if the device is a mapped LUKS device.

blivet.udev.device_is_dm_lvm(info)

Return True if the device is an LVM logical volume.

blivet.udev.device_is_dm_mpath(info)

Return True if the device is a multipath device.

blivet.udev.device_is_dm_partition(info)
blivet.udev.device_is_dm_raid(info)

Return True if the device is a dmraid array device.

blivet.udev.device_is_dm_stratis(info)

Return True if the device is a Stratis pool or filesystem.

blivet.udev.device_is_fcoe(info)
blivet.udev.device_is_hidden(info)
blivet.udev.device_is_iscsi(info)
blivet.udev.device_is_loop(info)

Return True if the device is a loop device.

blivet.udev.device_is_md(info)

Return True if the device is a mdraid array device.

blivet.udev.device_is_nvme_fabrics(info)
blivet.udev.device_is_nvme_namespace(info)
blivet.udev.device_is_partition(info)
blivet.udev.device_is_partoff_iscsi(info)
blivet.udev.device_is_private(info)
blivet.udev.device_is_stratis_filesystem(info)
blivet.udev.device_is_stratis_private(info)
blivet.udev.device_is_sw_iscsi(info)
blivet.udev.device_is_zfcp(info)

Return True if the device is a zfcp device.

blivet.udev.device_to_dict(device)
blivet.udev.get_device(sysfs_path=None, device_node=None)
blivet.udev.get_devices(subsystem='block')
blivet.udev.ignored_device_names = []

device name regexes to ignore; this should be empty by default

blivet.udev.resolve_devspec(devspec, sysname=False)
blivet.udev.resolve_glob(glob)
Parameters:

glob (str) – glob to match device names against

Returns:

list of udev info objects matching :param:`glob`

Note

This function matches device names (“sda”), not paths (“/dev/sda”).

blivet.udev.running_in_chroot()

Mimic running_in_chroot() logic from systemd. Simplifications:

  • can’t be running as PID 1, so skip the checks

  • don’t have statfs() call, so can’t check for fake /proc

Returns:

True if we detect a chroot environment, False otherwise

Return type:

bool

blivet.udev.settle(quiet=False)

Wait for the udev queue to settle.

Parameters:

quiet (bool) – bypass blivet.util.run_program()

blivet.udev.trigger(subsystem=None, action='add', name=None)

blivet.util module

class blivet.util.DependencyGuard(exn_cls=<class 'blivet.errors.DependencyError'>)

Bases: object

check_avail(onetime=False)
abstract property error_msg

Error message to report when a dependency is missing

class blivet.util.EvalMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

always = 2
onetime = 1
class blivet.util.ObjectID(*args, **kwargs)

Bases: object

This class is meant to be extended by other classes which require an ID which is preserved when an object copy is made. The value returned by the builtin function id() is not adequate: that value represents object identity so it is not in general preserved when the object is copied.

The name of the identifier property is id, its type is int.

The id is set during creation of the class instance to a new value which is unique for the object type. Subclasses can use self.id during __init__.

class blivet.util.Path(path, *args, **kwds)

Bases: str

Path(path, root=None) provides a filesystem path object, which automatically normalizes slashes, assumes appends are what you always hoped os.path.join() was (but with out the weird slash games), and can easily handle paths with a root directory other than /

glob()

Similar to glob.glob(), except it takes the Path’s root into account when globbing and returns path objects with the same root, so you don’t have to think about that part.

newroot(newroot=None)

Change the root directory of this Path

property normpath
property ondisk

Path.ondisk evaluates as the real filesystem path of the path, including the path’s root in the data.

property path
property realpath
property root
startswith(prefix[, start[, end]]) bool

Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.

blivet.util.available_memory()

Return the amount of system RAM that is currently available.

Return type:

Size

blivet.util.canonicalize_UUID(a_uuid)

Converts uuids to canonical form.

Parameters:

a_uuid (str) – the UUID

Returns:

a canonicalized UUID

Return type:

str

mdadm’s UUIDs are actual 128 bit uuids, but it formats them strangely. This converts the uuids to canonical form. Example:

mdadm UUID: ‘3386ff85:f5012621:4a435f06:1eb47236’

canonical UUID: ‘3386ff85-f501-2621-4a43-5f061eb47236’

If the UUID is already in canonical form, the conversion is equivalent to the identity.

blivet.util.capture_output(*args, **kwargs)
blivet.util.capture_output_binary(*args, **kwargs)
blivet.util.compare(first, second)

Compare two objects.

Parameters:
  • first – first object to compare

  • second – second object to compare

Returns:

0 if first == second, 1 if first > second, -1 if first < second

Return type:

int

This method replaces Python 2 cmp() built-in-function.

blivet.util.create_sparse_file(path, size)

Create a sparse file.

Parameters:

path (str) – the full path to the file

:param Size size: the size of the file :returns: None

blivet.util.create_sparse_tempfile(name, size)

Create a temporary sparse file.

Parameters:

name (str) – suffix for filename

:param Size size: the file size :returns: the path to the newly created file

blivet.util.dedup_list(alist)

Deduplicates the given list by removing duplicates while preserving the order

blivet.util.default_namedtuple(name, fields, doc='')

Create a namedtuple class

The difference between a namedtuple class and this class is that default values may be specified for fields and fields with missing values on initialization being initialized to None.

Parameters:
  • name (str) – name of the new class

  • fields (list of str or (str, object) objects) – field descriptions - an iterable of either “name” or (“name”, default_value)

  • doc (str) – the docstring for the new class (should at least describe the meanings and types of fields)

Returns:

a new default namedtuple class

Return type:

type

blivet.util.deprecated(version, message)

Decorator to deprecate a function or method via warning and docstring.

Parameters:
  • version (str) – version in which the deprecation is effective

  • message (str) – message suggesting a preferred alternative

Note

At the point this decorator gets applied to a method in a class the method is just a function. It becomes a method later.

The docstring manipulation is performed only once for each decorated function/method, but the warning is issued every time the decorated function is called.

blivet.util.detect_virt()

Return True if we are running in a virtual machine.

blivet.util.get_cow_sysfs_path(dev_path, dev_sysfsPath)

Return sysfs path of cow device for a given device.

blivet.util.get_current_entropy()
blivet.util.get_kernel_module_parameter(module, parameter)

Return the value of a given kernel module parameter

Parameters:
  • module (str) – a kernel module

  • parameter (str) – a module parameter

Returns:

the value of the given kernel module parameter or None

Return type:

str

blivet.util.get_mount_device(mountpoint)

Given a mountpoint, return the device node path mounted there.

blivet.util.get_mount_paths(dev)

Given a device node path, return a list of all active mountpoints.

Parameters:

dev (str) – Device path

Returns:

A list of mountpoints or []

Return type:

list

blivet.util.get_option_value(opt_name, options)

Return the value of a named option in the specified options string.

blivet.util.get_path_by_sysfs_path(sysfs_path, dev_type='block')

Return device path for a given device sysfs path.

blivet.util.get_sysfs_attr(path, attr, root=None)
blivet.util.get_sysfs_path_by_name(dev_node, class_name='block')

Return sysfs path for a given device.

For a device node (e.g. /dev/vda2) get the respective sysfs path (e.g. /sys/class/block/vda2). This also has to work for device nodes that are in a subdirectory of /dev like ‘/dev/cciss/c0d0p1’.

blivet.util.indent(text, spaces=4)

Indent text by a specified number of spaces.

Parameters:
  • text (str) – the text to indent

  • spaces (int) – the number of spaces to indent text

It would be nice if we could use textwrap.indent for this but, since it does not exist in python2, I prefer to just use this.

blivet.util.insert_colons(a_string)

Insert colon between every second character.

E.g. creates ‘al:go:ri:th:ms’ from ‘algoritms’. Useful for formatting MAC addresses and wwids for output.

blivet.util.join_paths(*paths)

Joins filesystem paths without any consideration of slashes or whatnot and then normalizes repeated slashes.

blivet.util.lsmod()

Returns list of names of all loaded modules.

blivet.util.makedirs(path)
blivet.util.match_path_context(path, mode=0)

Return the default SELinux context for the given path.

blivet.util.mount(device, mountpoint, fstype, options=None)
blivet.util.natural_sort_key(device)

Sorting key for devices which makes sure partitions are sorted in natural way, e.g. ‘sda1, sda2, …, sda10’ and not like ‘sda1, sda10, sda2, …’

blivet.util.normalize_path_slashes(path)

Normalize the slashes in a filesystem path. Does not actually examine the filesystem in any way.

blivet.util.numeric_type(num)

Verify that a value is given as a numeric data type.

Return the number if the type is sensible or raise ValueError if not.

blivet.util.power_of_two(value)

Checks whether value is a power of 2 greater than 1.

Parameters:

value (any) – a value

Returns:

True if the value is a power of 2

Return type:

bool

blivet.util.read_file(filename, mode='r')
blivet.util.requires_property(prop_name, val=True)

Function returning a decorator that can be used to guard methods and properties with evaluation of the given property.

Parameters:
  • prop_name (str) – property to evaluate

  • val (Object (anything)) – guard value of the :param:`prop_name`

blivet.util.reset_file_context(path, root=None, mode=0)

Restore the SELinux context of a file to its default value.

Arguments:

path filename string

Keyword Arguments:

root an optional chroot string mode an optional mode to use

Return Value:

If successful, returns the file’s new/default context.

blivet.util.run_program(*args, **kwargs)
blivet.util.run_program_and_capture_output(*args, **kwargs)
blivet.util.run_program_and_capture_output_binary(*args, **kwargs)
blivet.util.set_file_context(path, context, root=None)

Set the SELinux file context of a file.

Arguments:

path filename string context context string

Keyword Arguments:

root an optional chroot string

Return Value:

True if successful, False if not.

blivet.util.set_up_console_log(log_names=None)
blivet.util.set_up_logging(log_dir='/tmp', log_prefix='blivet', console_logs=None)

Configure the blivet logger to write out a log file.

Parameters:
  • log_dir (str) – path to directory where log files are

  • log_prefix (str) – prefix for log file names

  • console_logs (list) – list of log names to output on the console

blivet.util.sha256_file(filename)
blivet.util.sparsetmpfile(name, size)

Context manager that creates a sparse tempfile and then unlinks it.

Parameters:

name (str) – suffix for filename

:param Size size: the file size

Yields the path to the newly created file on __enter__.

blivet.util.total_memory()

Return the amount of system RAM.

Returns total system RAM in kB (given to us by /proc/meminfo).

Return type:

Size

blivet.util.umount(mountpoint)
blivet.util.variable_copy(obj, memo, omit=None, shallow=None, duplicate=None)

A configurable copy function. Any attributes not specified in omit, shallow, or duplicate are copied using copy.deepcopy().

Parameters:
  • obj (object) – a python object to be copied.

  • memo (dict) – a dictionary of already copied items

  • omit (iterable of str) – a list of names of attributes not to copy

  • shallow (iterable of str) – a list of names of attributes to shallow copy

  • duplicate (iterable of str) – a list of names of attributes to duplicate

Note that all attributes in duplicate must implement a duplicate() method that does what is expected of it. Attributes with type pyparted.Disk are known to do so.

A shallow copy is implemented by calling copy.copy().

blivet.zfcp module

class blivet.zfcp.ZFCPDevice(devnum, wwpn, fcplun)

Bases: ZFCPDeviceFullPath

Class derived from ZFCPDeviceFullPath to reserve backward compatibility for applications using the ZFCPDevice class. ZFCPDeviceFullPath should be used instead in new code.

class blivet.zfcp.ZFCPDeviceAutoLunScan(devnum)

Bases: ZFCPDeviceBase

Class for zFCP devices configured in NPIV mode and zFCP auto LUN scan not disabled. Only a zFCP device number is needed for such devices.

offline_device()

Remove the zFCP device from the system.

Returns:

True if success

Raises:

ValueError if the device cannot be brought offline

online_device()

Initialize the device and make its storage block device(s) ready to use.

Returns:

True if success

Raises:

ValueError if the device cannot be initialized

class blivet.zfcp.ZFCPDeviceBase(devnum)

Bases: ABC

An abstract base class for zFCP storage devices.

offline_scsi_device()

Find SCSI devices associated to the zFCP device and remove them from the system.

online_device()

Initialize the device and make its storage block device(s) ready to use.

Returns:

True if success

Raises:

ValueError if the device cannot be initialized

class blivet.zfcp.ZFCPDeviceFullPath(devnum, wwpn, fcplun)

Bases: ZFCPDeviceBase

A class for zFCP devices where zFCP auto LUN scan is not available. Such devices have to be specified by a device number, WWPN and LUN.

offline_device()

Remove the zFCP device from the system.

online_device()

Initialize the device and make its storage block device(s) ready to use.

Returns:

True if success

Raises:

ValueError if the device cannot be initialized

blivet.zfcp.has_auto_lun_scan(device_id)

Return True if the given zFCP device ID is configured in NPIV (N_Port ID Virtualization) mode and zFCP auto LUN scan is not disabled.

Returns:

True or False

blivet.zfcp.logged_write_line_to_file(fn, value)
class blivet.zfcp.zFCP

Bases: object

ZFCP utility class.

This class will automatically online to ZFCP drives configured in /tmp/fcpconfig when the startup() method gets called. It can also be used to manually configure ZFCP devices through the add_fcp() method.

As this class needs to make sure that /tmp/fcpconfig configured drives are only onlined once and as it keeps a global list of all ZFCP devices it is implemented as a Singleton.

add_fcp(devnum, wwpn=None, fcplun=None)
read_config()
shutdown()
startup()
write(root)

Module contents

blivet.log_bd_message(level, msg)