2013-06-23 12:00:17 +02:00
|
|
|
from base import Task
|
2013-06-23 15:26:08 +02:00
|
|
|
from common import phases
|
|
|
|
from connection import Connect
|
2013-06-23 12:00:17 +02:00
|
|
|
|
|
|
|
class CreateVolume(Task):
|
|
|
|
description = 'Creating an EBS volume for bootstrapping'
|
2013-06-23 22:12:29 +02:00
|
|
|
phase = phases.volume_creation
|
2013-06-23 15:26:08 +02:00
|
|
|
after = [Connect]
|
2013-06-23 12:00:17 +02:00
|
|
|
|
|
|
|
def run(self, info):
|
2013-06-24 19:06:12 +02:00
|
|
|
volume_size = int(info.manifest.volume['size']/1024)
|
|
|
|
info.volume = info.conn.create_volume(volume_size, info.host['availabilityZone'])
|
2013-06-23 12:00:17 +02:00
|
|
|
|
2013-06-24 19:06:12 +02:00
|
|
|
class AttachVolume(Task):
|
|
|
|
description = 'Attaching the EBS volume'
|
|
|
|
phase = phases.volume_creation
|
|
|
|
after = [CreateVolume]
|
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
def char_range(c1, c2):
|
|
|
|
"""Generates the characters from `c1` to `c2`, inclusive."""
|
|
|
|
for c in xrange(ord(c1), ord(c2)+1):
|
|
|
|
yield chr(c)
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
import os.stat
|
|
|
|
from stat import S_ISBLK
|
|
|
|
for letter in char_range('a', 'z'):
|
|
|
|
dev_path = os.path.join('/dev', 'xvd' + letter)
|
|
|
|
mode = os.stat(dev_path).st_mode
|
|
|
|
if S_ISBLK(mode):
|
|
|
|
info.bootstrap_device = {'path': dev_path}
|
|
|
|
break
|
|
|
|
if 'path' not in info.bootstrap_device:
|
|
|
|
raise VolumeError('Unable to find a free block device path for mounting the bootstrap volume')
|
|
|
|
info.conn.volume.attach(info.host['instanceId'], info.bootstrap_device['path'])
|
2013-06-23 12:00:17 +02:00
|
|
|
|