snapm package¶
Module contents¶
Snapm top-level package.
-
class
snapm.Selection(name=None, uuid=None, basename=None, index=None, timestamp=None, nr_snapshots=None, mount_points=None, origin=None, mount_point=None, snapshot_name=None, snapshot_uuid=None, sched_name: Union[None, str] = None, sched_sources: Union[None, str] = None, sched_default_size_policy: Union[None, str] = None, sched_autoindex: Union[None, bool] = None, sched_gc_type: Union[None, str] = None, sched_gc_params: Union[None, str] = None, sched_enabled: Union[None, bool] = None, sched_running: Union[None, bool] = None, sched_calendarspec: Union[None, str] = None)[source]¶ Bases:
objectSelection criteria for snapshot sets and snapshots.
-
__init__(name=None, uuid=None, basename=None, index=None, timestamp=None, nr_snapshots=None, mount_points=None, origin=None, mount_point=None, snapshot_name=None, snapshot_uuid=None, sched_name: Union[None, str] = None, sched_sources: Union[None, str] = None, sched_default_size_policy: Union[None, str] = None, sched_autoindex: Union[None, bool] = None, sched_gc_type: Union[None, str] = None, sched_gc_params: Union[None, str] = None, sched_enabled: Union[None, bool] = None, sched_running: Union[None, bool] = None, sched_calendarspec: Union[None, str] = None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
__repr__()[source]¶ Format this
Selectionobject as a machine readable string.The returned string may be passed to the Selection initialiser to duplicate the original Selection.
- Returns
A machine readable string representation of this Selection object
- Return type
string
-
__str__()[source]¶ Format this
Selectionobject as a human readable string.- Returns
A human readable string representation of this Selection object
- Return type
string
-
all_attrs= ['name', 'uuid', 'basename', 'index', 'timestamp', 'nr_snapshots', 'mount_points', 'origin', 'mount_point', 'snapshot_name', 'snapshot_uuid', 'sched_name', 'sched_sources', 'sched_default_size_policy', 'sched_autoindex', 'sched_gc_type', 'sched_gc_params', 'sched_enabled', 'sched_running', 'sched_calendarspec']¶
-
basename= None¶
-
check_valid_selection(snapshot_set=False, snapshot=False, schedule=False)[source]¶ Check a Selection for valid criteria.
Check this
Selectionobject to ensure it contains only criteria that are valid for the specified object type(s).Returns
Noneif the object passes the check, or raiseValueErrorif invalid criteria exist.- Parameters
snapshot_set –
Selectionmay include SnapshotSet datasnapshot –
Selectionmay include Snapshot data
- Returns
Noneon success- Return type
NoneType- Raises
ValueErrorif excluded criteria are present
-
classmethod
from_cmd_args(cmd_args)[source]¶ Initialise Selection from command line arguments.
Construct a new
Selectionobject from the command line arguments incmd_args. Each set selection attribute fromcmd_argsis copied into the Selection. The resulting object may be passed to either theSnapshotSetorSnapshotsearch functions. (find_snapshot_sets,find_snapshots, as well as thesnapm.commandcalls that accept a selection argument.- Parameters
cmd_args – The command line selection arguments.
- Returns
A new Selection instance
- Return type
-
index= None¶
-
is_null()[source]¶ Test this Selection object for null selection criteria.
Return
Trueif thisSelectionobject matches all objects, orFalseotherwise.- Returns
Trueif this Selection is null- Return type
bool
-
is_single()[source]¶ Test this Selection object for single item selection criteria.
Returns
Trueif thisSelectionobject matches a single object orFalseotherwise.A
Selectionobject matches a single object if either thenameoruuidfields is specified.- Returns
Trueif this selection is single orFalseotherwise.- Return type
bool
-
mount_point= None¶
-
mount_points= None¶
-
name= None¶
-
nr_snapshots= None¶
-
origin= None¶
-
sched_autoindex: Union[None, bool] = None¶
-
sched_calendarspec: Union[None, str] = None¶
-
sched_default_size_policy: Union[None, str] = None¶
-
sched_enabled: Union[None, bool] = None¶
-
sched_gc_params: Union[None, str] = None¶
-
sched_gc_type: Union[None, str] = None¶
-
sched_name: Union[None, str] = None¶
-
sched_running: Union[None, bool] = None¶
-
sched_sources: Union[None, str] = None¶
-
schedule_attrs= ['sched_name', 'sched_sources', 'sched_default_size_policy', 'sched_autoindex', 'sched_gc_type', 'sched_gc_params', 'sched_enabled', 'sched_running', 'sched_calendarspec']¶
-
snapshot_attrs= ['origin', 'mount_point', 'snapshot_name', 'snapshot_uuid']¶
-
snapshot_name= None¶
-
snapshot_set_attrs= ['name', 'uuid', 'basename', 'index', 'timestamp', 'nr_snapshots', 'mount_points']¶
-
snapshot_uuid= None¶
-
timestamp= None¶
-
uuid= None¶
-
-
class
snapm.SizePolicy(source, mount, free_space, fs_used, dev_size, policy)[source]¶ Bases:
objectClass representing a configured instance of a size policy.
-
__init__(source, mount, free_space, fs_used, dev_size, policy)[source]¶ Initialise a new SizePolicy object using the supplied parameters.
- Parameters
source – The source for this SizePolicy: a mount point or block device path.
mount – The mount point path if mounted.
free_space – The free space available to provision the snapshot in bytes.
fs_used – The current file system occupancy in bytes.
dev_size – The origin device size in bytes.
policy – A size policy string.
- Returns
A SizePolicy object configured for the specified size.
-
property
size¶ Return the backing store size for a snapshot based on the policy configuration.
-
-
class
snapm.SizePolicyType(value)[source]¶ Bases:
enum.EnumEnum class representing the possible snapshot size policies.
-
FIXED= 'FIXED'¶
-
PERCENT_FREE= 'FREE'¶
-
PERCENT_SIZE= 'SIZE'¶
-
PERCENT_USED= 'USED'¶
-
-
class
snapm.SnapStatus(value)[source]¶ Bases:
enum.EnumEnum class representing snapshot status: Active, Inactive, Invalid or Reverting.
-
ACTIVE= 1¶
-
INACTIVE= 2¶
-
INVALID= 3¶
-
REVERTING= 4¶
-
-
exception
snapm.SnapmArgumentError[source]¶ Bases:
snapm._snapm.SnapmErrorAn invalid argument was passed to a snapshot manager API call.
-
exception
snapm.SnapmBusyError[source]¶ Bases:
snapm._snapm.SnapmErrorA resource needed by the current command is already in use: for e.g. a snapshot merge is in progress for a previous snapshot set.
-
exception
snapm.SnapmCalloutError[source]¶ Bases:
snapm._snapm.SnapmErrorAn error calling out to an external program.
-
exception
snapm.SnapmExistsError[source]¶ Bases:
snapm._snapm.SnapmErrorThe named snapshot set already exists.
-
exception
snapm.SnapmInvalidIdentifierError[source]¶ Bases:
snapm._snapm.SnapmErrorAn invalid identifier was given.
-
exception
snapm.SnapmLimitError[source]¶ Bases:
snapm._snapm.SnapmErrorA configured resource limit would be exceeded.
-
exception
snapm.SnapmNoProviderError[source]¶ Bases:
snapm._snapm.SnapmErrorNo snapshot provider plugin was found.
-
exception
snapm.SnapmNoSpaceError[source]¶ Bases:
snapm._snapm.SnapmErrorInsufficient space is available for the requested operation.
-
exception
snapm.SnapmNotFoundError[source]¶ Bases:
snapm._snapm.SnapmErrorThe requested object does not exist.
-
exception
snapm.SnapmParseError[source]¶ Bases:
snapm._snapm.SnapmErrorAn error parsing user input.
-
exception
snapm.SnapmPathError[source]¶ Bases:
snapm._snapm.SnapmErrorAn invalid path was supplied, for example attempting to snapshot something that is not a mount point or block device.
-
exception
snapm.SnapmPluginError[source]¶ Bases:
snapm._snapm.SnapmErrorAn error performing an action via a plugin.
-
exception
snapm.SnapmRecursionError[source]¶ Bases:
snapm._snapm.SnapmErrorA snapshot set source corresponds to a snapshot of another snapshot set.
-
exception
snapm.SnapmSizePolicyError[source]¶ Bases:
snapm._snapm.SnapmErrorAn invalid size policy was specified.
-
exception
snapm.SnapmStateError[source]¶ Bases:
snapm._snapm.SnapmErrorThe status of an object does not allow an operation to proceed.
-
exception
snapm.SnapmSystemError[source]¶ Bases:
snapm._snapm.SnapmErrorAn error when calling the operating system.
-
exception
snapm.SnapmTimerError[source]¶ Bases:
snapm._snapm.SnapmErrorAn error manipulating systemd timers.
-
class
snapm.Snapshot(name, snapset_name, origin, timestamp, mount_point, provider)[source]¶ Bases:
objectBase class for individual snapshots. Each snapshot plugin should subclass
Snapshotto provide a specific implementation.-
__init__(name, snapset_name, origin, timestamp, mount_point, provider)[source]¶ Initialise a new
Snapshotobject.- Parameters
name – The name of the snapshot.
snapset_name – The name of the
SnapshotSetthis snapshot is a part of.origin – The origin volume of the snapshot.
timestamp – The creation timestamp of the snapshot set.
mount_point – The mount point path this snapshot refers to.
provider – The plugin providing this snapshot.
-
__str__()[source]¶ Return a string representation of this
Snapshotobject.- Returns
A multi-line string describing this snapshot.
-
as_dict()¶ Return a representation of this
Snapshotas a dictionary.
-
property
autoactivate¶ The autoactivation status of this snapshot. Returns
Trueif the snapshot is automatically activated orFalseotherwise.
-
check_resize(size_policy)[source]¶ Check whether this snapshot can be resized or not by calling the provider plugin with the updated
size_policy.
-
check_revert()[source]¶ Check whether this snapshot can be reverted or not by calling the provider plugin to verify the state of the snapshot.
-
property
devpath¶ The device path for this snapshot.
-
property
free¶ The space available to this snapshot in bytes. For snapshots with fixed-size backstores this reflects the space remaining in the current backstore. For snapshots that dynamically allocate space to the snapshot it indicates the pooled space available.
-
property
index¶ The index of this snapshot, if set, or the special value
snapm.SNAPSHOT_INDEX_NONEotherwise.
-
property
mount_point¶ The mount point of this snapshot.
-
property
mounted¶ Test whether either the snapshot or origin volume for this
Snapshotis currently mounted and in use.- Returns
Trueif this snapshot or its origin is currently mounted orFalseotherwise.
-
property
name¶ The name of this snapshot.
-
property
origin¶ The origin of this snapshot.
-
property
origin_mounted¶ Test whether the origin volume for this
Snapshotis currently mounted and in use.- Returns
Trueif this snapshot’s origin is currently mounted orFalseotherwise.
-
property
origin_options¶ File system options needed to specify the origin of this snapshot.
-
rename(new_name)[source]¶ Rename a snapshot within a snapshot set.
- Parameters
new_name – The new name for the snapshot.
-
revert()[source]¶ Request to revert a snapshot and revert the content of the origin volume to its state at the time of the snapshot.
This may be deferred until the next device activation or mount operation for the respective volume.
-
property
size¶ The size of this snapshot in bytes. For snapshots with fixed-size backstores this reflects the size of the backstore. For snapshots that dynamically allocate space to the snapshot it reflects the device or volume size.
-
property
snapset_basename¶ The basename of the snapshot set this snapshot belongs to, minus any index.
-
property
snapset_name¶ The name of the snapshot set this snapshot belongs to.
-
property
snapshot_mounted¶ Test whether the snapshot volume for this
Snapshotis currently mounted and in use.- Returns
Trueif this snapshot is currently mounted orFalseotherwise.
-
property
snapshot_set¶ The
SnapshotSetthis snapshot belongs to.
-
property
source¶ The block device or mount point from which this
Snapshotwas created.
-
property
status¶ The status of this snapshot. Returns a
SnapStatusenum value representing the current state of the snapshot.
-
property
time¶ The human readable timestamp of this snapshot.
-
property
timestamp¶ The numerical timestamp of this snapshot.
-
property
uuid¶ The UUID of this snapshot.
-
-
class
snapm.SnapshotSet(name, timestamp, snapshots)[source]¶ Bases:
objectRepresentation of a set of snapshots taken at the same point in time and managed as a group.
-
__init__(name, timestamp, snapshots)[source]¶ Initialise a new
SnapshotSetobject.- Parameters
name – The name of this
SnapshotSet.timestamp – The creation timestamp of this
SnapshotSet.snapshots – A list of
Snapshotobjects to be included in this set.
-
__str__()[source]¶ Return a string representation of this
SnapshotSet.- Returns
A multi-line string describing this snapshot set.
-
activate()[source]¶ Attempt to activate all members of this
SnapshotSet.- Raises
SnapmPluginErrorif a plugin fails to perform the requested operation.
-
as_dict(members=False)¶ Backwards compatibility
-
property
autoactivate¶ The overall autoactivation status of this snapshot set. Returns
Trueif all snapshots within the set have autoactivate enabled orFalseotherwise.
-
property
basename¶ The basename of this snapshot set, minus any index.
-
property
datetime¶ The timestamp of this snapshot set as a
datetime.datetimeobject.
-
deactivate()[source]¶ Attempt to deactivate all members of this
SnapshotSet.- Raises
SnapmPluginErrorif a plugin fails to perform the requested operation.
-
delete()[source]¶ Delete the on-disk representation of this
SnapshotSet.- Raises
SnapmBusyErrorif the snapshot set is in use.SnapmPluginErrorif an error occurs deleting snapshot set members.
-
property
devices¶ The list of block devices in this snapshot set.
-
property
index¶ The index of this snapshot set, if set, or the special value
snapm.SNAPSET_INDEX_NONEotherwise.
-
json(members=False, pretty=False)[source]¶ Return a string representation of this
SnapshotSetin JSON notation.
-
property
mount_points¶ The list of mount points in this snapshot set.
-
property
mounted¶ Test whether the either the origin or snapshot volumes for this
SnapshotSetare currently mounted and in use.- Returns
Trueif any of the snapshots belonging to thisSnapshotSetare currently mounted, orFalseotherwise.
-
property
name¶ The name of this snapshot set.
-
property
nr_snapshots¶ The number of snapshots in this snapshot set.
-
property
origin_mounted¶ Test whether the origin volumes for this
SnapshotSetare currently mounted and in use.- Returns
Trueif any of the snapshots belonging to thisSnapshotSetare currently mounted, orFalseotherwise.
-
rename(new_name)[source]¶ Rename this
SnapshotSettonew_name.- Raises
SnapmErrorif a call to rename any member of the snapshot set fails.
-
resize(sources, size_policies)[source]¶ Attempt to resize the
SnapshotSetaccording to the list ofsourcesand correspondingsize_policystrings.- Raises
SnapmNoSpaceErrorif there is insufficient space available for the requested operation.
-
revert()[source]¶ Initiate a revert operation on this
SnapshotSet.- Raises
SnapmPluginErrorif a plugin fails to perform the requested operation.
-
snapshot_by_mount_point(mount_point)[source]¶ Return the snapshot corresponding to
mount_point.- Parameters
mount_point – The mount point path to search for.
- Returns
A
Snapshotobject for the given mount point.- Raises
SnapmNotFoundErrorif the specified mount point is not present in thisSnapshotSet.
-
snapshot_by_source(source)[source]¶ Return the snapshot corresponding to
source.- Parameters
source – The block device or mount point path to search for.
- Returns
A
Snapshotobject for the given source path.- Raises
SnapmNotFoundErrorif the specified source path is not present in thisSnapshotSet.
-
property
snapshot_mounted¶ Test whether the snapshot volumes for this
SnapshotSetare currently mounted and in use.- Returns
Trueif any of the snapshots belonging to thisSnapshotSetare currently mounted, orFalseotherwise.
-
property
snapshots¶ The list of snapshots in this snapshot set.
-
property
sources¶ The list of source mount points and block devices in this snapshot set.
-
property
status¶ The overall status of this snapshot set. Returns
SnapStatus.ACTIVEif all members of the set are valid and active,SnapStatus.INACTIVEif any members are inactive, orSnapStatus.INVALIDif any member of the set is invalid.
-
property
time¶ The human readable timestamp of this snapshot set.
-
property
timestamp¶ The numerical timestamp of this snapshot set.
-
property
uuid¶ The UUID of this snapshot set.
-
-
class
snapm.SubsystemFilter(name='')[source]¶ Bases:
logging.FilterFilters DEBUG records based on a set of enabled subsystem names. Non-DEBUG records or DEBUG records without a ‘subsystem’ attribute are always passed through.
-
__init__(name='')[source]¶ Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
-
-
snapm.bool_to_yes_no(value)[source]¶ Convert boolean-like to yes/no string.
Return the string “yes” if
valueevaluates toTrue, or “no” otherwise.- Parameters
value – A boolean value to interpret.
- Returns
A string value that is “yes” if
valueisTrue, or “no” otherwise.
-
snapm.get_debug_mask()[source]¶ Return the current debug mask for the
snapmpackage.- Returns
The current debug mask value
- Return type
int
-
snapm.is_size_policy(policy)[source]¶ Test whether a string is a valid size policy
- Parameters
policy – A possible policy string to test.
- Returns
Trueifpolicyis a valid size policy string orFalseotherwise.
-
snapm.parse_size_with_units(value)[source]¶ Parse a size string with optional unit suffix and return a value in bytes,
- Parameters
size – The size string to parse.
- Returns
an integer size in bytes.
- Raises
ValueErrorif the string could not be parsed as a valid size value.
Submodules¶
snapm.manager module¶
Top level interface to the snapshot manager.
-
class
snapm.manager.CalendarSpec(calendarspec: str)[source]¶ Bases:
objectClass representing systemd CalendarSpec expressions.
-
__init__(calendarspec: str)[source]¶ Validate and parse a systemd calendarspec expression into a CalendarSpec object.
- Parameters
calendarspec – A string containing an calendarspec expression.
- Raises
ValueErrorifcalendarspecis not a valid calendarspec expression.
-
__repr__()[source]¶ Return a string representation of this
CalendarSpecinstance in the form of a call to the CalendarSpec initializer.
-
_cond_refresh()[source]¶ Refresh this
CalendarSpecobject’s time-dependent properties if the currentnext_elapsevalue is in the past.
-
property
from_now¶ Return a string representation of the time remaining until this
CalendarSpecnext elapses.- Returns
The time remaining until the next elapse as a string.
- Return type
str
-
property
in_utc¶ Return the next elapse time for this
CalendarSpecobject as an instance ofdatetime.datetimein UTC.- Returns
The next elapse time as a UTC
datetimeobject.- Return type
datetime.datetime
-
property
next_elapse¶ Return the next elapse time for this
CalendarSpecobject as an instance ofdatetime.datetime.- Returns
The next elapse time as a
datetimeobject.- Return type
datetime.datetime
-
property
occurs¶ Trueif thisCalendarSpecobject’s calendar expression will occur in the future, orFalseotherwise.
-
property
original¶ The original form of this
CalendarSpecas a string.
-
-
class
snapm.manager.GcPolicy(policy_name: str, policy_type: snapm.manager._schedule.GcPolicyType, params: dict)[source]¶ Bases:
objectAn instance of a garbage collection policy.
-
__hash__= None¶
-
__init__(policy_name: str, policy_type: snapm.manager._schedule.GcPolicyType, params: dict)[source]¶ Initialise a new GcPolicy.
- Parameters
policy_type (
GcPolicyType) – The policy type.params (
dict) – A dictionary of parameters suitable forpolicy_type.
-
__repr__()[source]¶ Return a machine readable string representation of this
GcPolicy.- Returns
A machine readable string.
- Return type
str
-
__str__()[source]¶ Return a human readable string representation of this
GcPolicy.- Returns
A human readable string.
- Return type
str
-
property
enabled¶ Return
Trueif thisGcPolicyand its corresponding timer are enabled, andFalseotherwise.
-
evaluate(sets: List[snapm._snapm.SnapshotSet])[source]¶ Evaluate the list of
SnapshotSetobjects insetsagainst thisGcPolicyand return a list ofSnapshotSetobjects that should be garbage collected.- Parameters
sets (
list[SnapshotSet].) – The list ofSnapshotSetobjects to evaluate, sorted in order of increasing creation date.- Returns
A list of
SnapshotSetobjects to garbage collect.- Return type
list[SnapshotSet]
-
classmethod
from_cmd_args(cmd_args)[source]¶ Initialise garbage collection policy from command line arguments.
Construct a new
GcPolicyobject from the command line arguments incmd_args. TheGcPolicyTypeis determined by thepolicy_typeargument, and the type-specific policy parameters are initialised from the remaining arguments.- Parameters
cmd_args – The command line selection arguments.
- Returns
A new
GcPolicyinstance- Return type
GcPolicy
-
classmethod
from_dict(data)[source]¶ Instantiate a
GcPolicyobject from values indata.- Parameters
data (
dict) – A dictionary describing aGcPolicyinstance.- Returns
An instance of
GcPolicyreflecting the values indata.- Return type
GcPolicy
-
classmethod
from_json(value)[source]¶ Instantiate a
GcPolicyobject from a JSON string invalue.- Parameters
value – A JSON string describing a
GcPolicyParamsinstance.- Returns
An instance of a
GcPolicyParamssubclass reflecting the values in the JSON stringvalue.- Return type
GcPolicyParams
-
property
has_params¶ Return
Trueif thisGcPolicyobject has defined policy parameters orFalseotherwise.- Returns
Trueif parameters are set elseFalse.- Return type
bool
-
json(pretty=False)[source]¶ Return a JSON representation of this
GcPolicy.- Returns
This
GcPolicyas a JSON string.- Return type
str
-
property
name¶ This
GcPolicyinstance’s name.
-
property
params¶ This
GcPolicyinstance’sGcPolicyParamsvalue.
-
property
running¶ Return
Trueif thisGcPolicyand its corresponding timer are enabled, andFalseotherwise.
-
to_dict()[source]¶ Return a dictionary representation of this
GcPolicy.- Returns
This
GcPolicyas a dictionary.- Return type
dict
-
property
type¶ This
GcPolicyinstance’sGcPolicyTypevalue.
-
-
class
snapm.manager.GcPolicyType(value)[source]¶ Bases:
enum.EnumGarbage collection policy types enum.
-
AGE= 'Age'¶
-
ALL= 'All'¶
-
COUNT= 'Count'¶
-
TIMELINE= 'Timeline'¶
-
-
class
snapm.manager.Manager[source]¶ Bases:
objectSnapshot Manager high level interface.
-
_check_recursion(origins)[source]¶ Verify that each entry in
originscorresponds to a device that is not a snapshot belonging to another snapshot set.- Parameters
origins – A list of origin devices to check.
- Raises
SnapmRecursionErrorif an origin device is a snapshot.
-
_find_and_verify_plugins(sources, size_policies, _requested_provider=None)[source]¶ Find snapshot provider plugins for each source in
sourcesand verify that a provider exists for each source present.- Parameters
sources – A list of source mount point or block device paths.
size_policies – A dictionary mapping sources to size policies.
- Returns
A dictionary mapping sources to plugins.
-
_find_next_index(basename)[source]¶ Find the next index value for the recurring snapset with basename
basename.- Parameters
basename – The basename of the recurring snapset
- Returns
An integer index value
-
_load_plugin_config(plugin_name: str) → configparser.ConfigParser[source]¶ Load optional configuration file for plugin
plugin_name.- Parameters
plugin_name (
str) – The name of the plugin to load config for.- Returns
A (possibly empty)
ConfigParserinstance.- Return type
ConfigParser
-
_set_autoactivate(snapset, auto=False)[source]¶ Set autoactivation for
snapset.- Parameters
snapset – The
SnapshotSetobject to operate on.auto –
Trueto enable autoactivation orFalseotherwise.
-
_snapset_from_name_or_uuid(name=None, uuid=None)[source]¶ Look a snapshot set up by
nameoruuid. Returns aSnapshotSetcorresponding to eithernameoruuid`, or raises ``SnapmErroron error.- Parameters
name – The name of the snapshot set to look up.
uuid – The UUID of the snapshot set to look up.
- Returns
A
SnapshotSetcorresponding to the given name or UUID.- Raises
SnapmNotFoundErroris the name or UUID cannot be found.SnapmInvalidIdentifierErrorif the name and UUID do not match.
-
_validate_snapset_name(name)[source]¶ Validate a snapshot set name.
Returns if
nameis a valid snapshot set name or raises an appropriate exception otherwise.- Parameters
name – The snapshot set name to validate.
- Raises
SnapmExistsErrorif the name is already in use, orSnapmInvalidIdentifierErrorif the name fails validation.
-
activate_snapshot_set(name=None, uuid=None)[source]¶ Activate snapshot set by name or uuid.
- Parameters
name – The name of the snapshot set to activate.
uuid – The UUID of the snapshot set to activate.
-
activate_snapshot_sets(selection)[source]¶ Activate snapshot sets matching selection criteria
selection.- Parameters
selection – Selection criteria for snapshot sets to activate.
-
by_name= {}¶
-
by_uuid= {}¶
-
create_snapshot_set(name, source_specs, default_size_policy=None, boot=False, revert=False, autoindex=False)[source]¶ Create a snapshot set of the supplied mount points with the name
name.- Parameters
name – The name of the snapshot set.
source_specs – A list of mount point and block device paths to include in the set.
default_size_policy – A default size policy to use for the set.
boot – Create a snapshot boot entry for this snapshot set.
revert – Create a revert boot entry for this snapshot set.
autoindex – Treat name as the basename of a recurring snapshot set and generate and append an appropriate index value.
- Raises
SnapmExistsErrorif the name is already in use, orSnapmInvalidIdentifierErrorif the name fails validation.
-
create_snapshot_set_boot_entry(name=None, uuid=None)[source]¶ Create a snapshot boot entry for the specified snapshot set.
- Parameters
name – The name of the snapshot set.
uuid – The UUID of the snapshot set.
- Raises
SnapmExistsErrorif a boot entry already exists for the snapshot set.- Raises
SnapmPluginErrorif autoactivation could not be enabled.
-
create_snapshot_set_revert_entry(name=None, uuid=None)[source]¶ Create a revert boot entry for the specified snapshot set.
- Parameters
name – The name of the snapshot set.
uuid – The UUID of the snapshot set.
-
deactivate_snapshot_set(name=None, uuid=None)[source]¶ Deactivate snapshot set by name or uuid.
- Parameters
name – The name of the snapshot set to deactivate.
uuid – The UUID of the snapshot set to deactivate.
-
deactivate_snapshot_sets(selection)[source]¶ Deactivate snapshot sets matching selection criteria
selection.- Parameters
selection – Selection criteria for snapshot sets to deactivate.
-
delete_snapshot_set(name=None, uuid=None)[source]¶ Remove snapshot sets by name or UUID.
- Parameters
name (
str) – The name of the snapshot set to delete.uuid (
UUID) – The UUID of the snapshot set to delete.
-
delete_snapshot_sets(selection)[source]¶ Remove snapshot sets matching selection criteria
selection.- Parameters
selection – Selection criteria for snapshot sets to remove.
-
discover_snapshot_sets()[source]¶ Discover snapshot sets by calling into each plugin to find individual snapshots and then aggregating them together into snapshot sets.
Initialises the
snapshot_sets,by_nameandby_uuidmembers with the discovered snapshot sets.
-
find_snapshot_sets(selection=None)[source]¶ Find snapshot sets matching selection criteria.
- Parameters
selection – Selection criteria to apply.
- Returns
A list of matching
SnapshotSetobjects.
-
find_snapshots(selection=None)[source]¶ Find snapshots matching selection criteria.
- Parameters
selection – Selection criteria to apply.
- Returns
A list of matching
Snapshotobjects.
-
plugins= []¶
-
rename_snapshot_set(old_name, new_name)[source]¶ Rename snapshot set
old_nameasnew_name.- Parameters
old_name – The name of the snapshot set to be renamed.
new_name – The new name of the snapshot set.
- Raises
SnapmExistsErrorif the name is already in use, orSnapmInvalidIdentifierErrorif the name fails validation.
-
resize_snapshot_set(source_specs, name=None, uuid=None, default_size_policy=None)[source]¶ Resize snapshot set named
nameor having UUIDuuid.Request to resize each snapshot included in
source_specsaccording to the given size policy, or applydefault_size_policyif set.- Parameters
name – The name of the snapshot set to resize.
uuid – The UUID of the snapshot set to resize.
source_specs – A list of mount points and optional size policies.
default_size_policy – A default size policy to apply to the resize.
-
revert_snapshot_set(name=None, uuid=None)[source]¶ Revert snapshot set named
nameor having UUIDuuid.Request to revert each snapshot origin within each snapshot set to the state at the time the snapshot was taken.
- Parameters
name – The name of the snapshot set to revert.
uuid – The UUID of the snapshot set to revert.
-
revert_snapshot_sets(selection)[source]¶ Revert snapshot sets matching selection criteria
selection.Request to revert each snapshot origin within each snapshot set to the state at the time the snapshot was taken.
- Parameters
selection – Selection criteria for snapshot sets to revert.
-
set_autoactivate(selection, auto=False)[source]¶ Set autoactivation state for snapshot sets matching selection criteria
selection.- Parameters
selection – Selection criteria for snapshot sets to set autoactivation.
auto –
Trueto enable autoactivation orFalseotherwise.
-
snapshot_sets= []¶
-
split_snapshot_set(name, new_name, source_specs)[source]¶ Split the snapshot set named name into two snapshot sets, with new_name containing the listed sources and name containing all remaining snapshots.
If new_name is None the listed snapshot are removed from name and permanently deleted. This operation cannot be undone.
- Parameters
name – The name of the snapshot set to split
new_name – The name of the newly split off snapshot set
sources – The list of sources to include in the new snapshot set
-
-
class
snapm.manager.Schedule(name: str, sources: List[str], default_size_policy: Optional[str], autoindex: bool, calendarspec: str, gc_policy: snapm.manager._schedule.GcPolicy, boot=False, revert=False)[source]¶ Bases:
objectAn individual snapshot schedule instance with create and garbage collection timers. Tracks timer configuration, name, sources, size policies, enabled/disabled, nr snapshots, next elapse.
-
__hash__= None¶
-
__init__(name: str, sources: List[str], default_size_policy: Optional[str], autoindex: bool, calendarspec: str, gc_policy: snapm.manager._schedule.GcPolicy, boot=False, revert=False)[source]¶ Initialise a new
Scheduleinstance.- Parameters
name (
str) – The name of theSchedule.sources (
list[str]) – The source specs to include in thisSchedule.default_size_policy (
str) – The default size policy for thisSchedule.autoindex (
bool) – Enable autoindex names for thisSchedule.calendarspec (
str) – TheOnCalendarexpression for thisSchedule.policy (
GcPolicy) – The garbage collection policy for thisSchedule.
- Returns
The new
Scheduleinstance.- Return type
Schedule
-
__repr__()[source]¶ Return a machine-readable representation of this
Schedule.- Returns
A machine-readable string.
- Return type
str
-
__str__()[source]¶ Return a human-readable representation of this
Schedule.- Returns
A human-readable string.
- Return type
str
-
property
autoindex¶ The autoindex property for this
Schedule.
-
property
boot¶ Return
Trueif thisScheduleis configured to enable snapshot set boot entries when creating snapshot sets.
-
property
calendarspec¶ The OnCalendar expression for the timer associated with this
Scheduleinstance.
-
property
default_size_policy¶ The default size policy for this
Schedule.
-
property
enabled¶ Return
Trueif thisScheduleand its corresponding timer are enabled, andFalseotherwise.
-
classmethod
from_dict(data)[source]¶ Instantiate a
Scheduleobject from values indata.- Parameters
data (
dict) – A dictionary describing aScheduleinstance.- Returns
An instance of
Schedulereflecting the values indata.- Return type
GcPolicyParams
-
classmethod
from_file(sched_file)[source]¶ Initialise a new
Scheduleinstance from an on-disk JSON configuration file.- Parameters
sched_file (
str) – The path to the schedule configuration file.- Returns
A new
Scheduleinstance.- Return type
Schedule
-
gc(sets: List[snapm._snapm.SnapshotSet]) → List[str][source]¶ Apply the configured garbage collection policy for this
Schedule.
-
property
gc_policy¶ The garbage collection policy for this
Schedule.
-
json(pretty=False)[source]¶ Return a JSON representation of this
Schedule.- Returns
This
Scheduleas a JSON string.- Return type
str
-
property
name¶ The name of this
Schedule.
-
property
next_elapse¶ Return the
next_elapsetime of thisSchedule’s timer.
-
property
revert¶ Return
Trueif thisScheduleis configured to enable snapshot set revert entries when creating snapshot sets.
-
property
running¶ Return
Trueif thisScheduleand its corresponding timer are enabled, andFalseotherwise.
-
property
sources¶ The source specs value for this
Schedule.
-
snapm.manager._boot module¶
Boot integration for snapshot manager
-
class
snapm.manager._boot.BootCache[source]¶ Bases:
objectSet of caches mapping snapshot sets to boot entries and revert entries.
-
class
snapm.manager._boot.BootEntryCache(entry_arg)[source]¶ Bases:
dictCache mapping snapshot sets to boom
BootEntryinstances.Boot entries in the cache are either snapshot set boot entries or revert entries depending on the value of
entry_arg.
-
class
snapm.manager._boot.Fstab(path='/etc/fstab')[source]¶ Bases:
objectA class to read and query data from an fstab file.
This class reads an fstab-like file and provides methods to iterate over its entries and look up specific entries based on their properties.
-
class
FstabEntry(what, where, fstype, options, freq, passno)¶ Bases:
tuple-
__getnewargs__()¶ Return self as a plain tuple. Used by copy and pickle.
-
static
__new__(_cls, what, where, fstype, options, freq, passno)¶ Create new instance of FstabEntry(what, where, fstype, options, freq, passno)
-
__repr__()¶ Return a nicely formatted representation string
-
__slots__= ()¶
-
_asdict()¶ Return a new dict which maps field names to their values.
-
_field_defaults= {}¶
-
_fields= ('what', 'where', 'fstype', 'options', 'freq', 'passno')¶
-
classmethod
_make(iterable)¶ Make a new FstabEntry object from a sequence or iterable
-
_replace(**kwds)¶ Return a new FstabEntry object replacing specified fields with new values
-
freq¶ Alias for field number 4
-
fstype¶ Alias for field number 2
-
options¶ Alias for field number 3
-
passno¶ Alias for field number 5
-
what¶ Alias for field number 0
-
where¶ Alias for field number 1
-
-
__init__(path='/etc/fstab')[source]¶ Initializes the Fstab object by reading and parsing the file.
- Parameters
path (str) – The path to the fstab file. Defaults to ‘/etc/fstab’.
- Raises
SnapmNotFoundError – If the specified fstab file does not exist.
SnapmSystemError – If there is an error reading the fstab file.
-
__iter__()[source]¶ Allows iteration over the fstab entries.
- Yields
A 6-tuple for each entry in the fstab file: (what, where, fstype, options, freq, passno)
-
_read_fstab()[source]¶ Private method to read and parse the fstab file. It populates the self.entries list.
-
lookup(key, value)[source]¶ Finds and generates all entries matching a specific key-value pair.
- Params key
The field to search by. Must be one of ‘what’, ‘where’, ‘fstype’, ‘options’, ‘freq’, or ‘passno’.
- Params value
The value to match for the given key.
- Yields
A 6-tuple for each matching fstab entry.
- Raises
KeyError – If the provided key is not a valid fstab field name.
-
class
-
snapm.manager._boot.REVERT_ARG= 'snapm.revert'¶ Snapshot set revert kernel command line argument
-
snapm.manager._boot.SNAPSET_ARG= 'snapm.snapset'¶ Snapshot set kernel command line argument
-
snapm.manager._boot._DBUS_MACHINE_ID= '/var/lib/dbus/machine-id'¶ Path to the legacy system machine-id file
-
snapm.manager._boot._DEV_PREFIX= '/dev/'¶ /dev path prefix
-
snapm.manager._boot._MACHINE_ID= '/etc/machine-id'¶ Path to the system machine-id file
-
snapm.manager._boot._OS_RELEASE= '/etc/os-release'¶ Path to the system os-release file
-
snapm.manager._boot._build_snapset_mount_list(snapset)[source]¶ Build a list of command line mount unit definitions for the snapshot set
snapset. Mount points that are not part of the snapset are substituted from /etc/fstab.- Parameters
snapset – The snapshot set to build a mount list for.
-
snapm.manager._boot._build_swap_list()[source]¶ Build a list of command line swap unit definitions for the running system. Swap entries are extracted from /etc/fstab and returned as a list of “WHAT:OPTIONS” strings.
-
snapm.manager._boot._create_boom_boot_entry(version, title, tag_arg, root_device, mounts=None, swaps=None)[source]¶ Create a boom boot entry according to the passed arguments.
- Parameters
version – The UTS release name for the boot entry
title – The title for the boot entry.
tag_arg – A tag argument to be added to the kernel command line and used to associate the entry with a snapshot set name or UUID.
root_device – The root device for the entry. Passed to root=…
mounts – An optional list of mount specifications to use for the boot entry. If defined fstab=no will be appended to the generated kernel command line.
swaps – An optional list of swap specifications to use for the boot entry. Each entry should be in the format “WHAT:OPTIONS”.
-
snapm.manager._boot._create_default_os_profile()[source]¶ Create a default boom OsProfile for the running system. This uses the boom API to run the equivalent of:
boom profile create --from-host.
-
snapm.manager._boot._delete_boot_entry(boot_id)[source]¶ Delete a boom boot entry by ID.
- Parameters
boot_id – The boot identifier to delete.
-
snapm.manager._boot._find_snapset_root(snapset, origin=False)[source]¶ Find the device that backs the root filesystem for snapshot set
snapset.If the snapset does not include the root volume look the device up via the fstab.
- Parameters
snapset – The
SnapshotSetto check.origin – Always return the origin device, even if a snapshot exists for the root mount point.
-
snapm.manager._boot._get_machine_id() → Optional[str][source]¶ Return the current host’s machine-id.
Get the machine-id value for the running system by reading from
/etc/machine-idand return it as a string.- Returns
The
machine_idas a string, orNoneif not available.- Return type
Optional[str]
-
snapm.manager._boot._get_uts_release()[source]¶ Return the UTS release (kernel version) of the running system.
- Returns
A string representation of the UTS release value.
-
snapm.manager._boot.check_boom_config()[source]¶ Check for boom configuration and create the default config if not found.
-
snapm.manager._boot.create_snapset_boot_entry(snapset, title=None)[source]¶ Create a boom boot entry to boot into the snapshot set represented by
snapset.- Parameters
snapset – The snapshot set for which to create a boot entry.
title – An optional title for the boot entry. If
titleisNonethe boot entry will be titled as “Snapshot snapset_name snapset_time”.
-
snapm.manager._boot.create_snapset_revert_entry(snapset, title=None)[source]¶ Create a boom boot entry to revert the snapshot set represented by
snapset.- Parameters
snapset – The snapshot set for which to create a revert entry.
title – An optional title for the revert entry. If
titleisNonethe revert entry will be titled as “Revert snapset_name snapset_time”.
-
snapm.manager._boot.delete_snapset_boot_entry(snapset)[source]¶ Delete the boot entry corresponding to
snapset.- Parameters
snapset – The snapshot set for which to remove a boot entry.
-
snapm.manager._boot.delete_snapset_revert_entry(snapset)[source]¶ Delete the revert entry corresponding to
snapset.- Parameters
snapset – The snapshot set for which to remove a revert entry.
-
snapm.manager._boot.get_device_path(identifier: str, by_type: str) → Optional[str][source]¶ Translates a filesystem UUID or label to its corresponding device path using the blkid command.
- Param
identifier: The UUID or label of the filesystem.
- Param
by_type: The type of identifier to search for.
- Returns
The device path if found, otherwise None.
- Return type
Optional[str]
- Raises
ValueError: If ‘identifier’ is empty or ‘by_type’ is not ‘uuid’ or ‘label’.
- Raises
SnapmNotFoundError: If the ‘blkid’ command is not found on the system.
- Raises
SnapmSystemError: If the ‘blkid’ command exits with a non-zero status due to reasons other than the identifier not being found (e.g., permission issues).
- Raises
SnapmCalloutError: For any other unexpected errors during command execution or parsing.
snapm.manager._calendar module¶
Calendar event abstraction for Snapshot Manager
-
class
snapm.manager._calendar.CalendarSpec(calendarspec: str)[source]¶ Bases:
objectClass representing systemd CalendarSpec expressions.
-
__init__(calendarspec: str)[source]¶ Validate and parse a systemd calendarspec expression into a CalendarSpec object.
- Parameters
calendarspec – A string containing an calendarspec expression.
- Raises
ValueErrorifcalendarspecis not a valid calendarspec expression.
-
__repr__()[source]¶ Return a string representation of this
CalendarSpecinstance in the form of a call to the CalendarSpec initializer.
-
_cond_refresh()[source]¶ Refresh this
CalendarSpecobject’s time-dependent properties if the currentnext_elapsevalue is in the past.
-
property
from_now¶ Return a string representation of the time remaining until this
CalendarSpecnext elapses.- Returns
The time remaining until the next elapse as a string.
- Return type
str
-
property
in_utc¶ Return the next elapse time for this
CalendarSpecobject as an instance ofdatetime.datetimein UTC.- Returns
The next elapse time as a UTC
datetimeobject.- Return type
datetime.datetime
-
property
next_elapse¶ Return the next elapse time for this
CalendarSpecobject as an instance ofdatetime.datetime.- Returns
The next elapse time as a
datetimeobject.- Return type
datetime.datetime
-
property
occurs¶ Trueif thisCalendarSpecobject’s calendar expression will occur in the future, orFalseotherwise.
-
property
original¶ The original form of this
CalendarSpecas a string.
-
snapm.manager._schedule module¶
Snapshot set scheduling abstractions for Snapshot Manager.
-
class
snapm.manager._schedule.GcPolicy(policy_name: str, policy_type: snapm.manager._schedule.GcPolicyType, params: dict)[source]¶ Bases:
objectAn instance of a garbage collection policy.
-
__hash__= None¶
-
__init__(policy_name: str, policy_type: snapm.manager._schedule.GcPolicyType, params: dict)[source]¶ Initialise a new GcPolicy.
- Parameters
policy_type (
GcPolicyType) – The policy type.params (
dict) – A dictionary of parameters suitable forpolicy_type.
-
__repr__()[source]¶ Return a machine readable string representation of this
GcPolicy.- Returns
A machine readable string.
- Return type
str
-
__str__()[source]¶ Return a human readable string representation of this
GcPolicy.- Returns
A human readable string.
- Return type
str
-
property
enabled¶ Return
Trueif thisGcPolicyand its corresponding timer are enabled, andFalseotherwise.
-
evaluate(sets: List[snapm._snapm.SnapshotSet])[source]¶ Evaluate the list of
SnapshotSetobjects insetsagainst thisGcPolicyand return a list ofSnapshotSetobjects that should be garbage collected.- Parameters
sets (
list[SnapshotSet].) – The list ofSnapshotSetobjects to evaluate, sorted in order of increasing creation date.- Returns
A list of
SnapshotSetobjects to garbage collect.- Return type
list[SnapshotSet]
-
classmethod
from_cmd_args(cmd_args)[source]¶ Initialise garbage collection policy from command line arguments.
Construct a new
GcPolicyobject from the command line arguments incmd_args. TheGcPolicyTypeis determined by thepolicy_typeargument, and the type-specific policy parameters are initialised from the remaining arguments.- Parameters
cmd_args – The command line selection arguments.
- Returns
A new
GcPolicyinstance- Return type
GcPolicy
-
classmethod
from_dict(data)[source]¶ Instantiate a
GcPolicyobject from values indata.- Parameters
data (
dict) – A dictionary describing aGcPolicyinstance.- Returns
An instance of
GcPolicyreflecting the values indata.- Return type
GcPolicy
-
classmethod
from_json(value)[source]¶ Instantiate a
GcPolicyobject from a JSON string invalue.- Parameters
value – A JSON string describing a
GcPolicyParamsinstance.- Returns
An instance of a
GcPolicyParamssubclass reflecting the values in the JSON stringvalue.- Return type
GcPolicyParams
-
property
has_params¶ Return
Trueif thisGcPolicyobject has defined policy parameters orFalseotherwise.- Returns
Trueif parameters are set elseFalse.- Return type
bool
-
json(pretty=False)[source]¶ Return a JSON representation of this
GcPolicy.- Returns
This
GcPolicyas a JSON string.- Return type
str
-
property
name¶ This
GcPolicyinstance’s name.
-
property
params¶ This
GcPolicyinstance’sGcPolicyParamsvalue.
-
property
running¶ Return
Trueif thisGcPolicyand its corresponding timer are enabled, andFalseotherwise.
-
to_dict()[source]¶ Return a dictionary representation of this
GcPolicy.- Returns
This
GcPolicyas a dictionary.- Return type
dict
-
property
type¶ This
GcPolicyinstance’sGcPolicyTypevalue.
-
-
class
snapm.manager._schedule.GcPolicyParams[source]¶ Bases:
objectAbstract base class for garbage collection policy parameters.
-
__str__()[source]¶ Return a human readable string representation of this
GcPolicyParamsinstance.- Returns
A human readable string.
- Return type
str
-
evaluate(sets: List[snapm._snapm.SnapshotSet]) → List[snapm._snapm.SnapshotSet][source]¶ Evaluate the list of
SnapshotSetobjects insetsagainst this set ofGcPolicyParamsand return a list ofSnapshotSetobjects that should be garbage collected.- Parameters
sets (
list[SnapshotSet].) – The list ofSnapshotSetobjects to evaluate, sorted in order of increasing creation date.- Returns
A list of
SnapshotSetobjects to garbage collect.- Return type
list[SnapshotSet]
-
property
has_params¶ Return
Trueif thisGcPolicyParamsobject has defined parameters orFalseotherwise.- Returns
Trueif parameters are set elseFalse.- Return type
bool
-
-
class
snapm.manager._schedule.GcPolicyType(value)[source]¶ Bases:
enum.EnumGarbage collection policy types enum.
-
AGE= 'Age'¶
-
ALL= 'All'¶
-
COUNT= 'Count'¶
-
TIMELINE= 'Timeline'¶
-
-
class
snapm.manager._schedule.Schedule(name: str, sources: List[str], default_size_policy: Optional[str], autoindex: bool, calendarspec: str, gc_policy: snapm.manager._schedule.GcPolicy, boot=False, revert=False)[source]¶ Bases:
objectAn individual snapshot schedule instance with create and garbage collection timers. Tracks timer configuration, name, sources, size policies, enabled/disabled, nr snapshots, next elapse.
-
__hash__= None¶
-
__init__(name: str, sources: List[str], default_size_policy: Optional[str], autoindex: bool, calendarspec: str, gc_policy: snapm.manager._schedule.GcPolicy, boot=False, revert=False)[source]¶ Initialise a new
Scheduleinstance.- Parameters
name (
str) – The name of theSchedule.sources (
list[str]) – The source specs to include in thisSchedule.default_size_policy (
str) – The default size policy for thisSchedule.autoindex (
bool) – Enable autoindex names for thisSchedule.calendarspec (
str) – TheOnCalendarexpression for thisSchedule.policy (
GcPolicy) – The garbage collection policy for thisSchedule.
- Returns
The new
Scheduleinstance.- Return type
Schedule
-
__repr__()[source]¶ Return a machine-readable representation of this
Schedule.- Returns
A machine-readable string.
- Return type
str
-
__str__()[source]¶ Return a human-readable representation of this
Schedule.- Returns
A human-readable string.
- Return type
str
-
property
autoindex¶ The autoindex property for this
Schedule.
-
property
boot¶ Return
Trueif thisScheduleis configured to enable snapshot set boot entries when creating snapshot sets.
-
property
calendarspec¶ The OnCalendar expression for the timer associated with this
Scheduleinstance.
-
property
default_size_policy¶ The default size policy for this
Schedule.
-
property
enabled¶ Return
Trueif thisScheduleand its corresponding timer are enabled, andFalseotherwise.
-
classmethod
from_dict(data)[source]¶ Instantiate a
Scheduleobject from values indata.- Parameters
data (
dict) – A dictionary describing aScheduleinstance.- Returns
An instance of
Schedulereflecting the values indata.- Return type
GcPolicyParams
-
classmethod
from_file(sched_file)[source]¶ Initialise a new
Scheduleinstance from an on-disk JSON configuration file.- Parameters
sched_file (
str) – The path to the schedule configuration file.- Returns
A new
Scheduleinstance.- Return type
Schedule
-
gc(sets: List[snapm._snapm.SnapshotSet]) → List[str][source]¶ Apply the configured garbage collection policy for this
Schedule.
-
property
gc_policy¶ The garbage collection policy for this
Schedule.
-
json(pretty=False)[source]¶ Return a JSON representation of this
Schedule.- Returns
This
Scheduleas a JSON string.- Return type
str
-
property
name¶ The name of this
Schedule.
-
property
next_elapse¶ Return the
next_elapsetime of thisSchedule’s timer.
-
property
revert¶ Return
Trueif thisScheduleis configured to enable snapshot set revert entries when creating snapshot sets.
-
property
running¶ Return
Trueif thisScheduleand its corresponding timer are enabled, andFalseotherwise.
-
property
sources¶ The source specs value for this
Schedule.
-
snapm.manager._timers module¶
Systemd timer integration for Snapshot Manager.
-
class
snapm.manager._timers.Timer(timer_type: snapm.manager._timers.TimerType, name: str, calendarspec: Union[str, snapm.manager._calendar.CalendarSpec])[source]¶ Bases:
objectHigh-level interface for managing schedling timers.
-
__init__(timer_type: snapm.manager._timers.TimerType, name: str, calendarspec: Union[str, snapm.manager._calendar.CalendarSpec])[source]¶ Initialise a new
Timerobject from the provided arguments.- Parameters
type – A
TimerTypeenum value representing the type of timer to create.name – The name of the timer. The value is used as the instance part of the timer unit name.
calendarspec – A valid calendarspec string, or an instance of the
CalendarSpecclass representing the trigger condition for the timer.
-
disable()[source]¶ Attempt to disable this
Timerinstance. Following a successful call toTimer.disable()the systemd unit is un-configured and no longer loaded. TheTimer.statusisTimerStatus.DISABLED.- Return type
None
-
enable()[source]¶ Attempt to enable this
Timerinstance. Following a successful call toTimer.enable()the systemd unit is configured and loaded, and theTimer.statusisTimerStatus.ENABLED.- Return type
None
-
property
enabled¶ Trueif thisTimeris enabled, andFalseotherwise.- Return type
bool
-
property
from_now¶ Return a string representation of the time remaining until this
Timernext elapses.- Returns
The time remaining until the next elapse as a string.
- Return type
str
-
property
next_elapse¶ Return the next elapse time for this
Timerobject as an instance ofdatetime.datetime.- Returns
The next elapse time as a
datetimeobject.- Return type
datetime.datetime
-
property
occurs¶ Trueif thisTimerwill elapse in the future, andFalseotherwise.- Return type
bool
-
property
running¶ Trueif thisTimeris running, andFalseotherwise.- Return type
bool
-
start()[source]¶ Attempt to start this
Timerinstance. Following a successful call toTimer.start()the systemd unit is ‘active’ / ‘waiting’ and will be invoked when the next elapse time is reached. TheTimer.statusisTimerStatus.RUNNING.- Return type
None
-
property
status¶ Return a
TimerStatusinstance reflecting the status of this timer.- Return type
TimerStatus
-
snapm.command module¶
The snapm.command module provides both the snapm command line
interface infrastructure, and a simple procedural interface to the
snapm library modules.
The procedural interface is used by the snapm command line tool,
and may be used by application programs, or interactively in the
Python shell by users who do not require all the features present
in the snapm object API.
-
snapm.command.PR_PLUGIN= 4¶ Plugin report object type
-
snapm.command.PR_SCHEDULE= 8¶ Schedule report object type
-
snapm.command.PR_SNAPSET= 1¶ Snapshot set report object type
-
snapm.command.PR_SNAPSHOT= 2¶ Snapshot report object type
-
class
snapm.command.ReportObj(snapset=None, snapshot=None, plugin=None, schedule=None)[source]¶ Bases:
objectCommon report object for snapm reports
-
snapm.command._activate_cmd(cmd_args)[source]¶ Activate snapshot set command handler.
Attempt to activate the snapshot sets that match the given selection criteria.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._add_identifier_args(parser, snapset=False, snapshot=False)[source]¶ Add snapshot set or snapshot identifier command line arguments.
-
snapm.command._add_plugin_subparser(type_subparser)[source]¶ Add subparser for ‘plugin’ commands.
- Parameters
type_subparser – Command type subparser
-
snapm.command._add_schedule_subparser(type_subparser)[source]¶ Add subparser for ‘schedule’ commands.
- Parameters
type_subparser – Command type subparser
-
snapm.command._add_snapset_subparser(type_subparser)[source]¶ Add subparser for ‘snapset’ commands.
- Parameters
type_subparser – Command type subparser
-
snapm.command._add_snapshot_subparser(type_subparser)[source]¶ Add subparser for ‘snapshot’ commands.
- Parameters
type_subparser – Command type subparser
-
snapm.command._autoactivate_cmd(cmd_args)[source]¶ Autoactivation status snapshot set command handler.
Attempt to set the autoactivation status for snapshot set that match the given selection criteria.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._create_cmd(cmd_args)[source]¶ create snapshot set command handler. attempt to create the specified snapshot set.
- Parameters
cmd_args – command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._deactivate_cmd(cmd_args)[source]¶ Deactivate snapshot set command handler.
Attempt to deactivate the snapshot sets that match the given selection criteria.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._delete_cmd(cmd_args)[source]¶ Delete snapshot set command handler.
Attempt to delete the specified snapshot set.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._do_print_type(report_fields, selected, output_fields=None, opts=None, sort_keys=None, title=None)[source]¶ Print an object type report (snapshot set, snapshot)
Helper for list function that generate reports.
Format a set of snapshot set or snapshot objects matching the given criteria and format them as a report, returning the output as a string.
Selection criteria may be expressed via a Selection object passed to the call using the
selectionparameter.- Parameters
selection – A Selection object giving selection criteria for the operation
output_fields – a comma-separated list of output fields
opts – output formatting and control options
sort_keys – a comma-separated list of sort keys
- Return type
str
-
snapm.command._expand_fields(default_fields, output_fields)[source]¶ Expand output fields list from command line arguments.
-
snapm.command._generic_list_cmd(cmd_args, select, opts, manager, print_fn)[source]¶ Generic list command implementation.
Implements a simple list command that applies selection criteria and calls a print_*() API function to display results.
Callers should initialise identifier and select appropriately for the specific command arguments.
- Parameters
cmd_args – the command arguments
select – selection criteria
opts – reporting options object
print_fn – the API call to display results. The function must accept the selection, output_fields, opts, and sort_keys keyword arguments
- Returns
None
-
snapm.command._list_cmd(cmd_args)[source]¶ List snapshot sets command handler.
List the snapshot sets that match the given selection criteria as a tabular report, with one snapshot set per row.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._log_debug_command(msg, *args, **kwargs)[source]¶ A wrapper for command subsystem debug logs.
-
snapm.command._plugin_list_cmd(cmd_args)[source]¶ List available plugins.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._prune_cmd(cmd_args)[source]¶ Prune snapshot set command handler.
Attempt to prune the specified sources from the given snapshot set.
- Parameters
cmd_args – Command line arguments for the command.
- Returns
integer status code returned from
main()
-
snapm.command._rename_cmd(cmd_args)[source]¶ Rename snapshot set command handler.
Attempt to rename the specified snapshot set.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._report_obj_types= [<snapm.report.ReportObjType object>, <snapm.report.ReportObjType object>, <snapm.report.ReportObjType object>, <snapm.report.ReportObjType object>]¶ Report object types table for
snapm.commandreports
-
snapm.command._resize_cmd(cmd_args)[source]¶ Resize snapshot set command handler.
Attempt to resize the snapshots contained in the given snapshot set according to the corresponding size policy.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._revert_cmd(cmd_args)[source]¶ Revert snapshot set command handler.
Attempt to revert the specified snapshot set.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._schedule_create_cmd(cmd_args)[source]¶ Create schedule.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._schedule_delete_cmd(cmd_args)[source]¶ Delete schedule.
- Parameters
cmd_args – Command line arguments for the command.
- Returns
integer status code returned from
main()
-
snapm.command._schedule_disable_cmd(cmd_args)[source]¶ Disable schedule.
- Parameters
cmd_args – Command line arguments for the command.
- Returns
integer status code returned from
main()
-
snapm.command._schedule_edit_cmd(cmd_args)[source]¶ Edit schedule.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._schedule_enable_cmd(cmd_args)[source]¶ Enable schedule.
- Parameters
cmd_args – Command line arguments for the command.
- Returns
integer status code returned from
main()
-
snapm.command._schedule_gc_cmd(cmd_args)[source]¶ Garbage collect schedule.
- Parameters
cmd_args – Command line arguments for the command.
- Returns
integer status code returned from
main().
-
snapm.command._schedule_list_cmd(cmd_args)[source]¶ List configured schedules.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._schedule_show_cmd(cmd_args)[source]¶ List configured schedules.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._show_cmd(cmd_args)[source]¶ Show snapshot set command handler.
Show the snapshot sets that match the given selection criteria as a multi-line report.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._snapshot_activate_cmd(cmd_args)[source]¶ Activate snapshot command handler.
Attempt to activate the snapshots that match the given selection criteria.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._snapshot_autoactivate_cmd(cmd_args)[source]¶ Autoactivate snapshot command handler.
Attempt to set autoactivation status for the snapshots that match the given selection criteria.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._snapshot_deactivate_cmd(cmd_args)[source]¶ Deactivate snapshot command handler.
Attempt to deactivate the snapshots that match the given selection criteria.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._snapshot_list_cmd(cmd_args)[source]¶ List snapshots command handler.
List the snapshot that match the given selection criteria as a tabular report, with one snapshot per row.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._snapshot_show_cmd(cmd_args)[source]¶ Show snapshots command handler.
Show the snapshots that match the given selection criteria as a multi-line report.
- Parameters
cmd_args – Command line arguments for the command
- Returns
integer status code returned from
main()
-
snapm.command._split_cmd(cmd_args)[source]¶ Split snapshot set command handler.
Attempt to split the specified sources from the first snapshot set argument into the second.
- Parameters
cmd_args – Command line arguments for the command.
- Returns
integer status code returned from
main()
-
snapm.command._str_indent(string, indent)[source]¶ Indent all lines of a multi-line string.
Indent each line of the multi line string
stringto the specified indentation level.- Parameters
string – The string to be indented
indent – The number of characters to indent by
- Returns
str
-
snapm.command.create_schedule(manager: snapm.manager._manager.Manager, name: str, sources: List[str], default_size_policy: str, autoindex: bool, calendarspec: Union[str, snapm.manager._calendar.CalendarSpec], policy: snapm.manager._schedule.GcPolicy, boot=False, revert=False)[source]¶ Create a new schedule from a list of mount point and block device source paths.
- Parameters
manager – The manager context to use.
name – The name of the new schedule.
sources – A list of mount point or block devices to snapshot.
default_size_policy – The default size policy for this snapshot set.
autoindex – Enable autoindex names for this schedule.
boot – Create a boot entry for this snapshot set.
revert – Create a revert boot entry for this snapshot set.
autoindex – Treat name as the basename of a recurring snapshot set and generate and append an appropriate index value.
-
snapm.command.create_snapset(manager, name, sources, size_policy=None, boot=False, revert=False, autoindex=False)[source]¶ Create a new snapshot set from a list of mount point and block device source paths.
- Parameters
manager – The manager context to use
name – The name of the new snapshot set
sources – A list of mount point or block devices to snapshot
size_policy – The default size policy for this snapshot set.
boot – Create a boot entry for this snapshot set.
revert – Create a revert boot entry for this snapshot set.
autoindex – Treat name as the basename of a recurring snapshot set and generate and append an appropriate index value.
-
snapm.command.delete_schedule(manager: snapm.manager._manager.Manager, name: str)[source]¶ Delete schedule by name. This disables the schedule and removes all on-disk configuration data.
- Parameters
manager – The manager context to use.
name – The name of the schedule to delete.
-
snapm.command.delete_snapset(manager, selection)[source]¶ Delete snapshot set matching selection criteria.
- Parameters
manager – The manager context to use
selection – Selection criteria for the snapshot set to remove.
-
snapm.command.disable_schedule(manager: snapm.manager._manager.Manager, name: str)[source]¶ Enable an existing schedule. This disables the systemd timer units associated with this schedule.
- Parameters
manager – The manager context to use.
name – The name of the schedule to disable.
-
snapm.command.edit_schedule(manager: snapm.manager._manager.Manager, name: str, sources: Optional[List[str]], default_size_policy: Optional[str], autoindex: bool, calendarspec: Optional[Union[str, snapm.manager._calendar.CalendarSpec]], policy: Optional[snapm.manager._schedule.GcPolicy], boot: Union[None, bool] = None, revert: Union[None, bool] = None)[source]¶ Edit an existing schedule from a list of mount point and block device source paths.
- Parameters
manager – The manager context to use.
name – The name of the new schedule.
sources – A list of mount point or block devices to snapshot.
default_size_policy – The default size policy for this snapshot set.
autoindex – Enable autoindex names for this schedule.
boot – Create a boot entry for this snapshot set.
revert – Create a revert boot entry for this snapshot set.
autoindex – Treat name as the basename of a recurring snapshot set and generate and append an appropriate index value.
-
snapm.command.enable_schedule(manager: snapm.manager._manager.Manager, name: str, start: bool)[source]¶ Enable an existing schedule. This enables the systemd timer units associated with this schedule.
- Parameters
manager – The manager context to use.
name – The name of the schedule to enable.
-
snapm.command.gc_schedule(manager: snapm.manager._manager.Manager, name: str) → List[str][source]¶ Run garbage collection for an existing schedule. This executes the configured garbage collection policy for the schedule named
name.- Parameters
manager – The manager context to use.
name – The name of the schedule to run garbage collection for.
-
snapm.command.print_plugins(manager, selection=None, output_fields=None, opts=None, sort_keys=None)[source]¶ Print plugins matching selection criteria.
Format a set of
snapm.manager.Pluginobjects matching the given criteria, and output them as a report to the file given inopts.report_file.Selection criteria are currently ignored for plugin reports.
- Parameters
selection – A Selection object giving selection criteria for the operation
output_fields – a comma-separated list of output fields
opts – output formatting and control options
sort_keys – a comma-separated list of sort keys
-
snapm.command.print_schedules(manager, selection: Union[None, snapm._snapm.Selection] = None, output_fields: Union[None, str] = None, opts: Union[None, snapm.report.ReportOpts] = None, sort_keys: [None, <class 'str'>] = None)[source]¶ Print schedules matching selection criteria.
Format a set of
snapm.manager.Scheduleobjects matching the given criteria, and output them as a report to the file given inopts.report_file.- Parameters
selection (
Selection) – ASelectionobject giving selection criteria for the operation.output_fields (
str) – A comma-separated list of output fields.opts (
ReportOpts) – Output formatting and control options.sort_keys (
str) – A comma-separated list of sort keys.
-
snapm.command.print_snapsets(manager, selection=None, output_fields=None, opts=None, sort_keys=None)[source]¶ Print snapshot sets matching selection criteria.
Format a set of
snapm.manager.SnapshotSetobjects matching the given criteria, and output them as a report to the file given inopts.report_file.Selection criteria may be expressed via a Selection object passed to the call using the
selectionparameter.- Parameters
selection – A Selection object giving selection criteria for the operation
output_fields – a comma-separated list of output fields
opts – output formatting and control options
sort_keys – a comma-separated list of sort keys
-
snapm.command.print_snapshots(manager, selection=None, output_fields=None, opts=None, sort_keys=None)[source]¶ Print snapshots matching selection criteria.
Format a set of
snapm.manager.Snapshotobjects matching the given criteria, and output them as a report to the file given inopts.report_file.Selection criteria may be expressed via a Selection object passed to the call using the
selectionparameter.- Parameters
selection – A Selection object giving selection criteria for the operation
output_fields – a comma-separated list of output fields
opts – output formatting and control options
sort_keys – a comma-separated list of sort keys
-
snapm.command.prune_snapset(manager, name, sources)[source]¶ Prune snapshots from an existing snapshot set.
Remove snapshots from an existing snapshot set named
name. The snapshot sources listed insourcesare pruned (deleted) from the named snapshot set.- Parameters
name – The name of the snapshot set to prune.
sources – The sources to prune from
name.
- Returns
A
SnapshotSetobject representing the pruned snapshot set
-
snapm.command.rename_snapset(manager, old_name, new_name)[source]¶ Rename a snapshot set from
old_nametonew_name.
-
snapm.command.resize_snapset(manager, sources, name=None, uuid=None, default_size_policy=None)[source]¶ Resize snapshot set by name or UUID.
- Parameters
manager – The manager context to use
sources – A list of mount point or block devices to snapshot
name – The name of the snapshot set to resize.
uuid – The uuid of the snapshot set to resize.
default_size_policy – The default size policy for this snapshot set.
-
snapm.command.revert_snapset(manager, name=None, uuid=None)[source]¶ Revert snapshot set matching selection criteria.
- Parameters
manager – The manager context to use
selection – Selection criteria for the snapshot set to revert.
-
snapm.command.show_schedules(manager, selection=None, _members=False, json=False)[source]¶ Show schedules matching selection criteria.
-
snapm.command.show_snapsets(manager, selection=None, members=False, json=False)[source]¶ Show snapshot sets matching selection criteria.
-
snapm.command.show_snapshots(manager, selection=None, json=False)[source]¶ Show snapshots matching selection criteria.
-
snapm.command.split_snapset(manager, name, new_name, sources)[source]¶ Split an existing snapshot set.
Split the snapshot set named
nameinto two snapshot sets, including all sources listed insourcesin the newly created snapshot set with namenew_name.- Parameters
name – The name of the snapshot set to split.
new_name – The name for the newly created snapshot set.
sources – The sources to split from
nametonew_name.
- Returns
A
SnapshotSetobject representing the snapshot set namednew_name.
snapm.report module¶
The snapm reporting module contains a set of classes for creating
simple text based tabular reports for a user-defined set of object
types and fields. No restrictions are placed on the types of object
that can be reported: users of the Report classes may define
additional object types outside the snapm package and include these
types in reports generated by the module.
The fields displayed in a specific report may be selected from the available set of fields by specifying a simple comma-separated string list of field names (in display order). In addition, custom multi-column sorting is possible using a similar string notation.
The Report module is closely based on the device-mapper
reporting engine and shares many features and behaviours with device
mapper reports.
-
class
snapm.report.Field[source]¶ Bases:
objectA
Fieldrepresents an instance of aFieldTypeincluding its associated data values.-
__init__(report, props)[source]¶ Initialise a new Field object.
Initialise a Field object and configure the supplied
reportandpropsattributes.- Parameters
report – The Report that owns this field
props – The FieldProperties object for this field
-
report_idx(value)[source]¶ Report an index value for this Field object.
Set the value for this field to the supplied
value.- Parameters
value – The index value to set
- Return type
None
-
report_num(value)[source]¶ Report a numeric value for this Field object.
Set the value for this field to the supplied
value.- Parameters
value – The numeric value to set
- Return type
None
-
report_sha(value)[source]¶ Report a SHA value for this Field object.
Set the value for this field to the supplied
value.- Parameters
value – The SHA value to set
- Return type
None
-
report_size(value)[source]¶ Report a size value for this Field object.
Set the value for this field to the supplied
value, converted to a human readable string.- Parameters
value – The size value to set in bytes.
- Return type
None
-
report_str(value)[source]¶ Report a string value for this Field object.
Set the value for this field to the supplied
value.- Parameters
value – The string value to set
- Return type
None
-
report_str_list(value)[source]¶ Report a string list value for this Field object.
Set the value for this field to the strings contained in
value.- Parameters
value – A list of strings
- Return type
None
-
report_time(value)[source]¶ Report a time value for this Field object.
Set the value for this field to the supplied
value.- Parameters
value – The time value to set
- Return type
None
-
report_uuid(value)[source]¶ Report a uuid value for this Field object.
Set the value for this field to the supplied
value.- Parameters
value – The uuid value to set
- Return type
None
-
set_value(report_string, sort_value=None)[source]¶ Report an arbitrary value for this Field object.
Set the value for this field to the supplied
value, and set the field’ssort_valueto the suppliedsort_value.- Parameters
report_string – The string value to set
sort_value – The sort value
- Return type
None
-
-
class
snapm.report.FieldProperties(field_num=None, initial_width=0, width=0, objtype=None, dtype=None, align=None, hidden=False, implicit=False, sort_key=False, sort_dir=None, compact_one=False, compacted=False, sort_posn=None)[source]¶ Bases:
objectProperties of a field instance.
-
class
snapm.report.FieldType[source]¶ Bases:
objectThe
FieldTypeclass describes the properties of a field available in aReportinstance.-
__init__(objtype, name, head, desc, width, dtype, report_fn, align=None)[source]¶ Initialise new FieldType object.
Initialise a new
FieldTypeobject with the specified properties.- Parameters
objtype – The numeric object type ID (power of two)
name – The field name used to select display fields
desc – A human-readable description of the field
width – The default (initial) field width
dtype – The Report data type of the field
report_fn – The field reporting function
align – The field alignment value
- Returns
A new ReportFieldType object
- Return type
ReportFieldType
-
-
class
snapm.report.Report[source]¶ Bases:
objectA class representing a configurable text report with multiple caller-defined fields. An optional title may be provided and the
fieldsargument must contain a list ofFieldobjects describing the required report.-
__init__(types, fields, output_fields, opts, sort_keys, title)[source]¶ Initialise Report.
Initialise a new
Reportobject with the specified fields and output control options.- Parameters
types – List of ReportObjType used in this report.
fields – A list of
Fieldfield descriptions.output_fields – An optional list of output fields to be rendered by this report.
opts – An instance of
ReportOptsor None.
- Returns
A new report object.
- Return type
Report.
-
opts= None¶
-
report_object(obj)[source]¶ Report data for object.
Add a row of data to this
Report. Thedataargument should be an object of the type understood by this report’s fields. It will be passed in turn to each field to obtain data for the current row.- Parameters
obj – the object to report on for this row.
-
-
class
snapm.report.ReportObjType[source]¶ Bases:
objectClass representing a type of object to be reported on. Instances of
ReportObjTypemust specify an identifier, a description, and a data function that will return the correct type of object from a compound object containing data objects of different types. For reports that use only a single object type thedata_fnmember may be simplylambda x: x.-
__init__(objtype, desc, prefix, data_fn)[source]¶ Initialise ReportObjType.
Initialise a new
ReportObjTypeobject with the specifiedobjtype,desc, optionalprefixanddata_fn. Theobjtypemust be an integer power of two that is unique within a given report. Thedata_fnshould accept an object as its only argument and return an object of the requested type.
-
-
class
snapm.report.ReportOpts[source]¶ Bases:
objectOptions controlling the formatting and output of a report.
-
__hash__= None¶
-
__init__(columns=80, headings=True, buffered=True, separator=' ', field_name_prefix='', unquoted=True, aligned=True, json=False, columns_as_rows=False, report_file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶ Initialise ReportOpts object.
Initialise a
ReportOptsobject to control output of aReport.- Parameters
columns – the number of columns to use for output.
headings – a boolean indicating whether to output column headings for this report.
buffered – a boolean indicating whether to buffer output from this report.
report_file – a file to which output will be sent.
- Returns
a new
ReportOptsobject.- Return type
<class ReportOpts>
-
snapm.manager.plugins module¶
Snapshot manager plugin interface.
-
class
snapm.manager.plugins.Plugin(logger, plugin_cfg)[source]¶ Bases:
objectAbstract base class for snapshot manager plugins.
-
activate_snapshot(name)[source]¶ Activate the snapshot named
name- Parameters
name – The name of the snapshot to be activated.
-
can_snapshot(source)[source]¶ Test whether this plugin can snapshot the specified mount point or block device.
- Parameters
source – The block device or mount point path to test.
- Returns
Trueif this plugin can snapshot the file system mounted atmount_point, orFalseotherwise.
-
check_create_snapshot(origin, snapset_name, timestamp, mount_point, size_policy)[source]¶ Perform pre-creation checks before creating a snapshot.
- Parameters
origin – The origin volume for the snapshot.
snapset_name – The name of the snapshot set to be created.
timestamp – The snapshot set timestamp.
mount_point – The mount point path for this snapshot.
- Raises
SnapmNoSpaceErrorif there is insufficient free space to create the snapshot.
-
check_resize_snapshot(name, origin, mount_point, size_policy)[source]¶ Check whether this snapshot can be resized to the requested
size_policy. This method returns if the resize can be satisfied and raises an exception if not.- Returns
None
- Raises
SnapmNoSpaceErrorif insufficient space is available to satisfy the requested size policy orSnapmPluginErrorif another reason prevents the snapshot from being resized.
-
check_revert_snapshot(name, origin)[source]¶ Check whether this snapshot can be reverted or not. This method returns if the current snapshot can be reverted and raises an exception if not.
- Returns
None
- Raises
NotImplementedErrorif this plugin does not support the revert operation,SnapmBusyErrorif the snapshot is already in the process of being reverted to another snapshot state orSnapmPluginErrorif another reason prevents the snapshot from being merged.
-
create_snapshot(origin, snapset_name, timestamp, mount_point, size_policy)[source]¶ Create a snapshot of
originin the snapset namedsnapset_name.- Parameters
origin – The origin volume for the snapshot.
snapset_name – The name of the snapshot set to be created.
timestamp – The snapshot set timestamp.
mount_point – The mount point path for this snapshot.
- Raises
SnapmNoSpaceErrorif there is insufficient free space to create the snapshot.
-
deactivate_snapshot(name)[source]¶ Deactivate the snapshot named
name- Parameters
name – The name of the snapshot to be deactivated.
-
delete_snapshot(name)[source]¶ Delete the snapshot named
name- Parameters
name – The name of the snapshot to be removed.
-
discover_snapshots()[source]¶ Discover snapshots managed by this plugin class.
Returns a list of objects that are a subclass of
Snapshot. :returns: A list of snapshots discovered by this plugin class.
-
name= 'plugin'¶
-
origin_from_mount_point(mount_point)[source]¶ Return a string representing the origin from a given mount point path.
- Parameters
mount_point – The mount point path.
-
rename_snapshot(old_name, origin, snapset_name, timestamp, mount_point)[source]¶ Rename the snapshot named
old_nameaccording to the provided snapshot field values.- Parameters
old_name – The original name of the snapshot to be renamed.
origin – The origin volume for the snapshot.
snapset_name – The new name of the snapshot set.
timestamp – The snapshot set timestamp.
mount_point – The mount point of the snapshot.
-
resize_snapshot(name, origin, mount_point, size_policy)[source]¶ Attempt to resize the snapshot
nameto the requestedsize_policy. This method returns if the resize can be satisfied and raises an exception if not.- Returns
None
- Raises
SnapmNoSpaceErrorif insufficient space is available to satisfy the requested size policy orSnapmPluginErrorif another reason prevents the snapshot from being resized.
-
revert_snapshot(name)[source]¶ Request to revert a snapshot and revert the content of the origin volume to its state at the time of the snapshot.
This may be deferred until the next device activation or mount operation for the respective volume.
- Parameters
name – The name of the snapshot to revert.
-
set_autoactivate(name, auto=False)[source]¶ Set the autoactivation state of the snapshot named
name.- Parameters
name – The name of the snapshot to be modified.
auto –
Trueto enable autoactivation orFalseotherwise.
-
snapshot_class¶ alias of
snapm._snapm.Snapshot
-
version= '0.1.0'¶
-
-
snapm.manager.plugins.decode_mount_point(mount_str)[source]¶ Parse the mount point component of a snapshot name.
-
snapm.manager.plugins.device_from_mount_point(mount_point)[source]¶ Convert a mount point path to a corresponding device path.
Return the device corresponding to the file system mount point
mount_pointaccording to /proc/self/mounts.
-
snapm.manager.plugins.encode_mount_point(mount_point)[source]¶ Encode mount point paths.
Encode a mount point for use in a snapshot name by replacing the path separator with ‘-‘.
-
snapm.manager.plugins.format_snapshot_name(origin, snapset_name, timestamp, mount_point)[source]¶ Format structured snapshot name.
Format a snapshot name according to the snapshot manager naming format.