From fc3a6ded268a3f30cac4897531373b4fe8d867f6 Mon Sep 17 00:00:00 2001 From: Alon Swartz Date: Mon, 14 Jun 2010 15:25:05 +0300 Subject: [PATCH] Added Eucalyptus support + refactoring - supported EBS devices in Eucaluptus (tested on Ubuntu Maverick alpha) - removed hardcoded device path, moved to /etc/ebsmount.conf - refactored device path test, we no longer use it in the mountpath - Thanks to Scott Moser --- 85-ebsmount.rules.in | 5 ++++- cmd_manual.py | 18 +++++++++--------- cmd_udev.py | 33 +++++++++++++++++++++++---------- debian/control | 8 ++++---- docs/README | 7 +++++-- ebsmount.conf | 2 ++ utils.py | 2 +- 7 files changed, 48 insertions(+), 27 deletions(-) diff --git a/85-ebsmount.rules.in b/85-ebsmount.rules.in index d4fea26..bd4c260 100644 --- a/85-ebsmount.rules.in +++ b/85-ebsmount.rules.in @@ -1,6 +1,9 @@ # udev rules to trigger ebsmount-udev on ebs attach|detach +# Amazon EC2 KERNEL=="sd[f-p]", SUBSYSTEM=="block", ATTRS{devtype}=="vbd", ACTION=="add", RUN+="@PATH_BIN@/ebsmount-udev add" - KERNEL=="sd[f-p]", SUBSYSTEM=="block", ACTION=="remove", RUN+="@PATH_BIN@/ebsmount-udev remove" +# Eucalyptus +KERNEL=="vd[a-z]*", SUBSYSTEM=="block", ACTION=="add", RUN+="@PATH_BIN@/ebsmount-udev add" +KERNEL=="vd[a-z]*", SUBSYSTEM=="block", ACTION=="remove", RUN+="@PATH_BIN@/ebsmount-udev remove" diff --git a/cmd_manual.py b/cmd_manual.py index 33abd2a..f70cf1f 100755 --- a/cmd_manual.py +++ b/cmd_manual.py @@ -5,7 +5,7 @@ Arguments: - device EBS device to mount (e.g., /dev/sdf) + device EBS device to mount (e.g., /dev/sdf, /dev/vda) Options: @@ -32,16 +32,17 @@ def fatal(s): print >> sys.stderr, "error: " + str(s) sys.exit(1) -def _get_physdevpath(devname): - """ugly hack to get the physical device path of first parent""" +def _expected_devpath(devname, devpaths): + """ugly hack to test expected structure of devpath""" raw_output = executil.getoutput('udevadm info -a -n %s' % devname) for line in raw_output.splitlines(): line = line.strip() - if line.startswith("looking at parent device '/devices/xen/vbd-"): - return line.split()[-1].strip(":").strip("'") + for devpath in devpaths: + if line.startswith("looking at parent device '%s" % devpath): + return True - return None + return False def main(): try: @@ -64,9 +65,8 @@ def main(): if not os.path.exists(devname): fatal("%s does not exist" % devname) - physdevpath = _get_physdevpath(devname) - if not physdevpath: - fatal("failed lookup of physdevpath") + if not _expected_devpath(devname, config.devpaths.split()): + fatal("devpath not of expected structure, or failed lookup") if filesystem: if is_mounted(devname): diff --git a/cmd_udev.py b/cmd_udev.py index bff7d37..408a506 100755 --- a/cmd_udev.py +++ b/cmd_udev.py @@ -7,10 +7,16 @@ action action trigger (add | remove) -Environment variables: +Environment variables (Amazon EC2): DEVNAME (required: e.g., /dev/sdf) PHYSDEVPATH (required: e.g., /devices/xen/vbd-2160) + +Environment variables (Eucalyptus): + + DEVNAME (required: e.g., /dev/vda) + DEVPATH (required: e.g., /devices/virtio-pci/virtio0/block/vda) + """ import os @@ -31,6 +37,13 @@ def fatal(s): print >> sys.stderr, "error: " + str(s) sys.exit(1) +def _expected_devpath(devpath, devpaths): + for s in devpaths: + if devpath.startswith(s): + return True + + return False + def main(): if not len(sys.argv) == 2: usage() @@ -39,26 +52,26 @@ def main(): fatal('ebsmount is not enabled (%s)' % config.CONF_FILE) action = sys.argv[1] - DEVNAME = os.getenv('DEVNAME', None) - PHYSDEVPATH = os.getenv('PHYSDEVPATH', None) + devname = os.getenv('DEVNAME', None) + devpath = os.getenv('PHYSDEVPATH', os.getenv('DEVPATH', None)) if not action in ('add', 'remove'): usage('action must be one of: add, remove') - if not DEVNAME: + if not devname: usage('DEVNAME is required') - if not PHYSDEVPATH: - usage('PHYSDEVPATH is required') + if not devpath: + usage('PHYSDEVPATH or DEVPATH is required') - if not PHYSDEVPATH.startswith('/devices/xen/vbd-'): - usage('PHYSDEVPATH is not of the expected structure') + if not _expected_devpath(devpath, config.devpaths.split()): + usage('PHYSDEVPATH/DEVPATH is not of the expected structure') # log trigger - log(DEVNAME, "received %s trigger" % action) + log(devname, "received %s trigger" % action) func = getattr(ebsmount, 'ebsmount_' + action) - func(DEVNAME, config.mountdir) + func(devname, config.mountdir) if __name__=="__main__": main() diff --git a/debian/control b/debian/control index 0a2bf53..475e898 100644 --- a/debian/control +++ b/debian/control @@ -9,8 +9,8 @@ Package: ebsmount Architecture: all Depends: python (>= 2.4), udev, turnkey-pylib Section: misc -Description: Automatically mount EC2 EBS (Elastic Block Storage) devices - Automatically mounts EBS devices when they are attached, supports - formatted devices as well as partitions, uniquely identifiable mount - points, and hooking scripts execution upon mount. +Description: Automatically mount EC2/Eucalyptus EBS devices + Automatically mounts EBS (Elastic Block Storage) devices when they are + attached, supports formatted devices as well as partitions, uniquely + identifiable mount points, and hooking scripts execution upon mount. diff --git a/docs/README b/docs/README index 7c60864..ab443d9 100644 --- a/docs/README +++ b/docs/README @@ -1,5 +1,5 @@ -EBSmount: Automatically mount EC2 EBS (Elastic Block Storage) devices -===================================================================== +EBSmount: Automatically mount EC2/Eucalyptus EBS devices +======================================================== EBSmount has 2 commands: @@ -8,6 +8,7 @@ EBSmount has 2 commands: Features: + - Supports Amazon EC2 and Eucalyptus EBS devices - Automatically mounts EBS devices when they are attached (via udev) - Supports formatted devices, as well as partitions - Ignores unformatted devices and unsupported filesystems @@ -33,6 +34,8 @@ Default configuration (/etc/ebsmount.conf): FILESYSTEMS=ext2 ext3 LOGFILE=/var/log/ebsmount.log + DEVPATHS=/devices/xen/vbd- /devices/virtio-pci/virtio + Unique mountpoints: - Every EBS filesystem is mounted to its own uniquely identifiable diff --git a/ebsmount.conf b/ebsmount.conf index a098b27..5e8bf5f 100644 --- a/ebsmount.conf +++ b/ebsmount.conf @@ -5,3 +5,5 @@ MOUNTDIR=/media/ebs MOUNTOPTIONS=noatime FILESYSTEMS=ext2 ext3 LOGFILE=/var/log/ebsmount.log + +DEVPATHS=/devices/xen/vbd- /devices/virtio-pci/virtio diff --git a/utils.py b/utils.py index f029394..3ed2152 100644 --- a/utils.py +++ b/utils.py @@ -6,7 +6,7 @@ class EBSMountConf(ConfFile): CONF_FILE = os.getenv('EBSMOUNT_CONF', '/etc/ebsmount.conf') - REQUIRED = ['enabled', 'mountdir', 'mountoptions', 'filesystems', 'logfile'] + REQUIRED = ['enabled', 'mountdir', 'mountoptions', 'filesystems', 'logfile', 'devpaths'] config = EBSMountConf()