summaryrefslogtreecommitdiff
path: root/ec2-run-user-data.py
diff options
context:
space:
mode:
authorSoren Hansen <soren@canonical.com>2009-08-25 23:51:16 +0200
committerSoren Hansen <soren@canonical.com>2009-08-25 23:51:16 +0200
commit59d21bb23db06e5e02cbd91ec531b1506ab97fae (patch)
tree8743a08d8e959f2a4b5648f55452aa1079218c58 /ec2-run-user-data.py
parent85f6e6168beb89436ebc20c67d329581f7155f5c (diff)
downloadvyos-cloud-init-59d21bb23db06e5e02cbd91ec531b1506ab97fae.tar.gz
vyos-cloud-init-59d21bb23db06e5e02cbd91ec531b1506ab97fae.zip
Implement EBS volume mounting
This can either be invoked by instrumenting the user-data with a mime part with content-type 'text/x-ebs-mount-description' with a body like so: device=/dev/sde:/var/lib/mysql,/etc/alfresco device=/dev/sdf:/other/things or by using the appliance config XML format like so: <appliance> <storage device="/dev/sde"> <path>/var/lib/mysql</path> <path>/etc/alfresco</path> </storage> <storage device="/dev/sdf"> <path>/other/things</path> </appliance> </appliance> In either case, if the volume does not yet have a filesystem, one will be created. For each path that is to live on the volume, a directory is created, and populated with the data currently in the target directory (e.g. /var/lib/mysql is copied to ${ebs_volume_path}/_var_lib_mysql). Once this is done, the directories are bind-mounted to the relevant paths. If the directories in question already exist, they will just be bind-mounted.
Diffstat (limited to 'ec2-run-user-data.py')
-rwxr-xr-xec2-run-user-data.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py
index 67ecf219..d7e8e632 100755
--- a/ec2-run-user-data.py
+++ b/ec2-run-user-data.py
@@ -61,7 +61,7 @@ def handle_appliance_config(payload):
@handler('text/x-ebs-mount-description')
def handle_ebs_mount_description(payload):
- (volume_description, path) = payload.split(':')
+ (volume_description, paths) = payload.split(':')
(identifier_type, identifier) = volume_description.split('=')
if identifier_type == 'device':
@@ -73,6 +73,17 @@ def handle_ebs_mount_description(payload):
else:
return
+ mount_ebs_volume(device, paths.split(','))
+
+def mount_ebs_volume(device, paths):
+ if os.path.exists('ec2-init-appliance-ebs-volume-mount.sh'):
+ helper = './ec2-init-appliance-ebs-volume-mount.sh'
+ else:
+ helper = '/usr/share/ec2-init/ec2-init-appliance-ebs-volume-mount.sh'
+ helper = subprocess.Popen([helper, device] + paths, stdout=subprocess.PIPE)
+ stdout, stderr = helper.communicate()
+ return stdout
+
@handler('text/x-shellscript')
def handle_shell_script(payload):
(fd, path) = tempfile.mkstemp()
@@ -129,6 +140,16 @@ class ApplianceConfig(object):
# An empty script?
continue
content_type_handlers['text/x-shellscript'](script)
+ elif node.tagName == 'storage':
+ paths = []
+ device = node.getAttribute('device')
+ for subnode in node.childNodes:
+ if subnode.tagName == 'path':
+ for subsubnode in subnode.childNodes:
+ if subsubnode.nodeType == root.TEXT_NODE:
+ paths += [subsubnode.nodeValue.strip()]
+ break
+ mount_ebs_volume(device, paths)
def main():
ec2 = ec2init.EC2Init()