Skip to content

Commit

Permalink
Added Eucalyptus support + refactoring
Browse files Browse the repository at this point in the history
- 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 <scott.moser@canonical.com>
  • Loading branch information
alonswartz committed Jun 14, 2010
1 parent 32aba62 commit fc3a6de
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 27 deletions.
5 changes: 4 additions & 1 deletion 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"
18 changes: 9 additions & 9 deletions cmd_manual.py
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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):
Expand Down
33 changes: 23 additions & 10 deletions cmd_udev.py
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions debian/control
Expand Up @@ -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.

7 changes: 5 additions & 2 deletions 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:

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ebsmount.conf
Expand Up @@ -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
2 changes: 1 addition & 1 deletion utils.py
Expand Up @@ -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()

Expand Down

0 comments on commit fc3a6de

Please sign in to comment.