diff --git a/image_creator/disk.py b/image_creator/disk.py index aebddc2655780aaf828a372d07582453f324db10..0d5ed484e0325f57abb58ae3ef4d661b48d77dfa 100644 --- a/image_creator/disk.py +++ b/image_creator/disk.py @@ -9,8 +9,7 @@ import re import sys import guestfs -from pbs import dmsetup -from pbs import blockdev +import pbs from pbs import dd @@ -18,6 +17,26 @@ class DiskError(Exception): pass +def find_sbin_command(command, exception): + search_paths = ['/usr/local/sbin', '/usr/sbin', '/sbin'] + for fullpath in map(lambda x: "%s/%s" % (x, command), search_paths): + if os.path.exists(fullpath) and os.access(fullpath, os.X_OK): + return pbs.Command(fullpath) + continue + raise exception + + +try: + from pbs import dmsetup +except pbs.CommandNotFound as e: + dmsetup = find_sbin_command('dmsetup', e) + +try: + from pbs import blockdev +except pbs.CommandNotFound as e: + blockdev = find_sbin_command('blockdev', e) + + class Disk(object): """This class represents a hard disk hosting an Operating System