Permalink
Browse files

add all ephemeral drives when launching instances

Generalized create_root_block_device_map to create_block_device_map with
new kwarg root_snapshot_id and num_ephemeral_drives.

The num_ephemeral_drives kwarg is 24 by default which covers all
instance types. Any types that have less than 24 ephemeral drives
available will simply ignore the rest in the block device map.

Updated request_instances() to always add *all* ephemeral drives if
block_device_map is not specified.

closes gh-202
  • Loading branch information...
1 parent 00c15db commit 184da7f04b065689c5b2e2f6f51213d4f930ee50 @jtriley committed Jan 25, 2013
Showing with 18 additions and 25 deletions.
  1. +16 −23 starcluster/awsutils.py
  2. +2 −2 starcluster/image.py
@@ -330,6 +330,9 @@ def request_instances(self, image_id, price=None, instance_type='m1.small',
"""
Convenience method for running spot or flat-rate instances
"""
+ if not block_device_map:
+ bdmap = self.create_block_device_map(add_ephemeral_drives=True)
+ block_device_map = bdmap
if price:
return self.request_spot_instances(
price, image_id, instance_type=instance_type,
@@ -904,36 +907,26 @@ def migrate_image(self, image_id, destbucket, migrate_manifest=False,
log.info("Manifest migrated successfully. You can now run:\n" +
register_cmd + "\nto register your migrated image.")
- def create_root_block_device_map(self, snapshot_id,
- root_device_name='/dev/sda1',
- add_ephemeral_drives=False,
- ephemeral_drive_0='/dev/sdb1',
- ephemeral_drive_1='/dev/sdc1',
- ephemeral_drive_2='/dev/sdd1',
- ephemeral_drive_3='/dev/sde1'):
+ def create_block_device_map(self, root_snapshot_id=None,
+ root_device_name='/dev/sda1',
+ add_ephemeral_drives=False,
+ num_ephemeral_drives=24):
"""
Utility method for building a new block_device_map for a given snapshot
id. This is useful when creating a new image from a volume snapshot.
The returned block device map can be used with self.register_image
"""
bmap = boto.ec2.blockdevicemapping.BlockDeviceMapping()
- sda1 = boto.ec2.blockdevicemapping.BlockDeviceType()
- sda1.snapshot_id = snapshot_id
- sda1.delete_on_termination = True
- bmap[root_device_name] = sda1
+ if root_snapshot_id:
+ sda1 = boto.ec2.blockdevicemapping.BlockDeviceType()
+ sda1.snapshot_id = root_snapshot_id
+ sda1.delete_on_termination = True
+ bmap[root_device_name] = sda1
if add_ephemeral_drives:
- sdb1 = boto.ec2.blockdevicemapping.BlockDeviceType()
- sdb1.ephemeral_name = 'ephemeral0'
- bmap[ephemeral_drive_0] = sdb1
- sdc1 = boto.ec2.blockdevicemapping.BlockDeviceType()
- sdc1.ephemeral_name = 'ephemeral1'
- bmap[ephemeral_drive_1] = sdc1
- sdd1 = boto.ec2.blockdevicemapping.BlockDeviceType()
- sdd1.ephemeral_name = 'ephemeral2'
- bmap[ephemeral_drive_2] = sdd1
- sde1 = boto.ec2.blockdevicemapping.BlockDeviceType()
- sde1.ephemeral_name = 'ephemeral3'
- bmap[ephemeral_drive_3] = sde1
+ for i in range(num_ephemeral_drives):
+ eph = boto.ec2.blockdevicemapping.BlockDeviceType()
+ eph.ephemeral_name = 'ephemeral%d' % i
+ bmap['/dev/sd%s1' % chr(ord('b') + i)] = eph
return bmap
@print_timing("Downloading image")
@@ -305,8 +305,8 @@ def _create_image_from_instance_store(self, size=15):
log.info("Removing generated volume %s" % vol.id)
vol.delete()
log.info("Creating root block device map using snapshot %s" % snap.id)
- bmap = self.ec2.create_root_block_device_map(snap.id,
- add_ephemeral_drives=True)
+ bmap = self.ec2.create_block_device_map(root_snapshot_id=snap.id,
+ add_ephemeral_drives=True)
log.info("Registering new image...")
img_id = self.ec2.register_image(name=self.name,
description=self.description,

0 comments on commit 184da7f

Please sign in to comment.