Package: simplezfs
A thin wrapper around ZFS from theOpenZFSproject.The library aims at providing a simple, low-level interface for working with ZFS, either by wrapping thezfs(8)andzpool(8)CLI utilities or by accessing the native python API.It does not provide a high-level interface, however, and does not aim to. It also tries to keep as little state as
possible.Two interface classes make up the API,ZFSandZPool, which are wrappers around the functionality of the CLI
tools of the same name. They come with two implementations:The CLI implementation wraps the executablesThe Native implementation uses the native API released with OpenZFS 0.8.In this early stage, the native implementation has not been written.StatusThe table gives a rough overview over features and their implementation state. For the PE Helper, functions where it is
of no use are left empty (usezfs allowfor those). Recursive is used to denote if it can destroy the dataset with
dependent datasets, for example a fileset with its associated snapshots.APITopicFeatureCLINativePE HelperRecursiveZFSPropertiesRead nativeYesNoWrite nativeYesNoRead metadataYesNoWrite metadataYesNoDatasetsList datasetsYesNoCheck existanceYesNoCreate FilesetYesNoYesCreate VolumeNoNoCreate SnapshotNoNoNoCreate BookmarkNoNoDestroy FilesetYesNoYesYes (Snaps)Destroy VolumeNoNoNoDestroy SnapshotNoNoNoDestroy BookmarkNoNoNoZPoolStorageList poolsNoNoRead structureYesNoReplace diskNoNoNoDestroyNoNoNoCreateNoNoNoPropertiesRead nativeNoNoWrite nativeNoNoNoRead metadataNoNoWrite metadataNoNoUsageOne can either get a concrete implementation by callingZFSCli/ZFSNativeorZPoolCli/ZPoolNative, or
more conveniently use the functionsget_zfs(implementation_name)orget_zpool(implementation_name).
First, get an instance:>>>fromsimplezfsimportget_zfs>>>zfs=get_zfs('cli')# or "native" for the native API>>>zfs<simplezfs.zfs_cli.ZFSCli object at 0x7ffbca7fb9e8>>>>>>>fordsinzfs.list_datasets():...print(ds.name)...tank
tank/system
tank/system/rootfsCompatibilityThe library is written withPython3.6 or higher in mind, which was in a stable release in a few of the major Linux
distributions we care about (Debian Buster, Ubuntu 18.04 LTS, RHEL 8, Gentoo).On theOpenZFSside, the code is developed on version0.8and newer, and takes some validation values from that
release. The library doesn’t make a lot of assumptions, the code should work on0.7, too. If you spot an
incompatibility, please let us know via the issue tracker.TestingAn extensive set of tests are in thetests/subfolder, it can be run usingpytestfrom the source of the
repository. At this time, only the validation functions and the ZFS Cli API are tested, the tests are non-destructive
and won’t run the actual commands but instead mock away thesubprocessinvocations and supply dummy commands to run
(usually/bin/true) should the code be changed in a way that isn’t caught by the test framework. Nevertheless, keep
in mind that if commands are run for whatever reason, they most likely result in unrecoverable data loss.It is planned to add a separate set ofdestructivetests that need to be specially activated for testing if the code
works when run against an actual Linux system. This can’t be done using most of the CI providers, as the nature of ZFS
requires having a operating system with loaded modules that may be destroyed during the test run.