Skip to content

Commit

Permalink
add all ephemeral drives when launching instances
Browse files Browse the repository at this point in the history
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
jtriley committed Jan 25, 2013
1 parent 00c15db commit 184da7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
39 changes: 16 additions & 23 deletions starcluster/awsutils.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 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: if price:
return self.request_spot_instances( return self.request_spot_instances(
price, image_id, instance_type=instance_type, price, image_id, instance_type=instance_type,
Expand Down Expand Up @@ -904,36 +907,26 @@ def migrate_image(self, image_id, destbucket, migrate_manifest=False,
log.info("Manifest migrated successfully. You can now run:\n" + log.info("Manifest migrated successfully. You can now run:\n" +
register_cmd + "\nto register your migrated image.") register_cmd + "\nto register your migrated image.")


def create_root_block_device_map(self, snapshot_id, def create_block_device_map(self, root_snapshot_id=None,
root_device_name='/dev/sda1', root_device_name='/dev/sda1',
add_ephemeral_drives=False, add_ephemeral_drives=False,
ephemeral_drive_0='/dev/sdb1', num_ephemeral_drives=24):
ephemeral_drive_1='/dev/sdc1',
ephemeral_drive_2='/dev/sdd1',
ephemeral_drive_3='/dev/sde1'):
""" """
Utility method for building a new block_device_map for a given snapshot 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. 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 The returned block device map can be used with self.register_image
""" """
bmap = boto.ec2.blockdevicemapping.BlockDeviceMapping() bmap = boto.ec2.blockdevicemapping.BlockDeviceMapping()
sda1 = boto.ec2.blockdevicemapping.BlockDeviceType() if root_snapshot_id:
sda1.snapshot_id = snapshot_id sda1 = boto.ec2.blockdevicemapping.BlockDeviceType()
sda1.delete_on_termination = True sda1.snapshot_id = root_snapshot_id
bmap[root_device_name] = sda1 sda1.delete_on_termination = True
bmap[root_device_name] = sda1
if add_ephemeral_drives: if add_ephemeral_drives:
sdb1 = boto.ec2.blockdevicemapping.BlockDeviceType() for i in range(num_ephemeral_drives):
sdb1.ephemeral_name = 'ephemeral0' eph = boto.ec2.blockdevicemapping.BlockDeviceType()
bmap[ephemeral_drive_0] = sdb1 eph.ephemeral_name = 'ephemeral%d' % i
sdc1 = boto.ec2.blockdevicemapping.BlockDeviceType() bmap['/dev/sd%s1' % chr(ord('b') + i)] = eph
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
return bmap return bmap


@print_timing("Downloading image") @print_timing("Downloading image")
Expand Down
4 changes: 2 additions & 2 deletions starcluster/image.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def _create_image_from_instance_store(self, size=15):
log.info("Removing generated volume %s" % vol.id) log.info("Removing generated volume %s" % vol.id)
vol.delete() vol.delete()
log.info("Creating root block device map using snapshot %s" % snap.id) log.info("Creating root block device map using snapshot %s" % snap.id)
bmap = self.ec2.create_root_block_device_map(snap.id, bmap = self.ec2.create_block_device_map(root_snapshot_id=snap.id,
add_ephemeral_drives=True) add_ephemeral_drives=True)
log.info("Registering new image...") log.info("Registering new image...")
img_id = self.ec2.register_image(name=self.name, img_id = self.ec2.register_image(name=self.name,
description=self.description, description=self.description,
Expand Down

0 comments on commit 184da7f

Please sign in to comment.