Merge lp:~tellis/ubuntu-on-ec2/attach-volume into lp:~ubuntu-on-ec2/ubuntu-on-ec2/cloud-utils

Proposed by Tom Ellis
Status: Merged
Merged at revision: 86
Proposed branch: lp:~tellis/ubuntu-on-ec2/attach-volume
Merge into: lp:~ubuntu-on-ec2/ubuntu-on-ec2/cloud-utils
Diff against target: 71 lines (+40/-0)
1 file modified
uec-run-instances (+40/-0)
To merge this branch: bzr merge lp:~tellis/ubuntu-on-ec2/attach-volume
Reviewer Review Type Date Requested Status
Tom Ellis (community) Needs Resubmitting
Scott Moser Pending
Review via email: mp+49576@code.launchpad.net

Description of the change

Attach volume on boot of system. This work is based on the associate ip and wait_for=ssh work, as volumes can only be attached successfully when instance status = running.
Tested on UEC, might need some tweaking for volume device on ec2.

My first foray into python so be gentle :-)

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Thanks for doing this. I have two suggestions:
- make default dev (/dev/sdb) configurable via command line options (maybe '--attach-volume-dev). Its fine to use /dev/sdb by default as on ec2, people would probably use --block-device-mapping.
- support attaching a snapshot. I think with the end goal of EBS root, this is more reasonable. Ie, if the target of --attach-volume starts with SNAP- or 'snap-' the, create a volume from that SNAP, wait for it to become available, and then start the instances.

Revision history for this message
Tom Ellis (tellis) wrote :

Thanks for the comments Scott, I'll work on updating the patch to add these two features.

86. By Scott Moser

add --attach-volume from Tom Ellis

Revision history for this message
Scott Moser (smoser) wrote :

I merged.
Tom just work on the other two changes and submit those.

Revision history for this message
Tom Ellis (tellis) wrote :

Checked out the branch after your merge and noticed a problem with an indent causing it traceback. Fixed it in this merge, not sure how that got in there...

Working on those other proposals and will submit other merge requests.

Cheers!

review: Needs Resubmitting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'uec-run-instances'
2--- uec-run-instances 2010-08-30 17:56:54 +0000
3+++ uec-run-instances 2011-02-13 23:00:51 +0000
4@@ -6,6 +6,7 @@
5 # Authors: Dustin Kirkland <kirkland@canonical.com>
6 # Scott Moser <scott.moser@canonical.com>
7 # Clint Byrum <clint.byrum@canonical.com>
8+# Tom Ellis <tom.ellis@canonical.com>
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12@@ -309,6 +310,9 @@
13 parser.add_option("", "--associate-ip", dest="ip",
14 help="associate elastic IP with instance", metavar="IP_ADDR",
15 default=None)
16+ parser.add_option("", "--attach-volume", dest="vol",
17+ help="attach EBS volume with instance", metavar="VOLUME_ID",
18+ default=None)
19 parser.add_option("", "--known-hosts", dest="known_hosts", action="append",
20 help="write host keys to specified known_hosts file. Specify multiple times to read keys from multiple files (only updates last one)",
21 metavar="KnownHosts", default=None)
22@@ -502,6 +506,9 @@
23 elif istatus != 'running' and options.wait_for:
24 logging.warning('%s is %s', iid, istatus)
25 new_pending_instance_ids.append(iid)
26+ elif istatus != 'running' and options.vol:
27+ logging.warning('%s is %s', iid, istatus)
28+ new_pending_instance_ids.append(iid)
29 else:
30 logging.info("%s %s", iid, istatus)
31 inst = Instance()
32@@ -552,6 +559,39 @@
33 if bool(ret):
34 logging.debug('associate-ip returned %d', ret)
35
36+ if options.vol:
37+ # as you can start multiple instances, support multiple vols like ips, instead of multiple volumes on one instance
38+ vols = options.vol.split(',')
39+ if len(vols) < len(instances):
40+ logging.warning('only %d volumes given, some instances will not get a volume attached', len(vols))
41+ elif len(vols) > len(instances):
42+ logging.warning('%d volumes given, some volumes will not be associated', len(vols))
43+
44+ rcmds = []
45+ vols.reverse()
46+ for inst in instances:
47+ # instance needs to be 'running' not 'pending' before attaching volume, otherwise it fails
48+ logging.info('waiting for instance to run')
49+ cmd = '%s-attach-volume' % provider
50+ if len(vols) < 1:
51+ break
52+ vol = vols.pop()
53+ dev = '/dev/sdb'
54+ args = [ cmd , '-i', inst.id, '-d', dev, vol ]
55+ logging.debug('running %s',args)
56+ logging.info("attaching volume with id = %s to instance id = %s", vol, inst.id)
57+ rattach = Popen(args, stdout=PIPE)
58+ rcmds.append(rattach)
59+ for rcmd in rcmds:
60+ # dump stdin into the inst object
61+ try:
62+ for line in rcmd.stdout:
63+ logging.info(line)
64+ finally:
65+ ret = rcmd.wait()
66+ if bool(ret):
67+ logging.debug('attach-volume returned %d', ret)
68+
69 if options.wait_for == 'ssh':
70 logging.info('waiting for ssh access')
71 for inst in instances:

Subscribers

People subscribed via source and target branches