Skip to main content

A Linux system administration automation toolset

Project description


A Linux system administration automation toolset.

Abstracts common CLIs into python functions and classes.

Current command modules:
- blockdevice
- btrfs
- encryption (cryptsetup)
- drbd
- lvm
- xen


Start all Xen DomUs

from pybofh import xen

for domu in xen.allDomus():
if not xen.isDomuRunning(domu):
xen.startDomu( domu )


Site-specific configuration

Customize `` to match your local environment

Atomic operations

Having a automated administration tool that leaves a talk half-finished is worse than having no automated administration tool.

`pybofh` supports context managers:

TMP_MNTS= ["/media/tmp", "/media/tmp2"]
mountpool= blockdevice.MountPool( TMP_MNTS )
with mountpool.mount( '/dev/sda1' ) as sda1_mountpoint:
#/dev/sda1 is now mounted
with mountpoint.mount( '/dev/sda2') as sda2_mountpoint:
#/dev/sda2 is now mounted
with mountpoint.mount( '/dev/sda3') as sda3_mountpoint:
#fails, no more mountpoints available
#/dev/sda1 and /dev/sda2 are now unmounted

But, of course, not all operations make sense as a context manager. Take, for example, creating a new VM from disk on LVM:

lvm.createLV("my_vg", "my_vm", "10gb")
blockdevice.create_filesystem( '/dev/my_vg/my_vm')

What happens if `create_filesystem` fails? You'll may be left with a inconsistent filesystem on the LV. Worse, once you fix the problem and try to run this again, `createLV` will fail, because the LV is already there, so you'll have to either create the VM manually or fix your script.

A context manager makes no sense in this case: you don't want to delete the LV if all operations succeed. You have to keep track of the operations you performed, and rollback if something fails. You could do that by hand, of course, but that's no fun:

with Atomic() as atomic:
atomic.lvm.createLV("my_vg", "my_vm", "10gb")
blockdevice.create_filesystem( '/dev/my_vg/my_vm')

Now, the LV will be deleted only *if **any** operation inside the context manager fails*. If you have multiple `atomic` calls, it will keep track of them, and rollback them in the reverse order they were executed on.

While `Atomic` pre-packages some knowledge, `AtomicOperationSequence` is operation agnostic - it works by defining rollback functions:

def f1():
print "f1 executed"

def reverse(f, args, kwargs):
if f==f1:
print "f1 reversed"

with AtomicOperationSequence(reverse) as atomic:


pybofh? What kind of name is that?
It's a tribute to the [Bastard Operator From Hell]( stories

Where does development happen?

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pybofh, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size pybofh-0.2.1.tar.gz (44.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page