'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'

def create_block_device_map(self, root_snapshot_id=None, root_device_name='/dev/sda1', add_ephemeral_drives=False, num_ephemeral_drives=24, instance_store=False):

    bmap = boto.ec2.blockdevicemapping.BlockDeviceMapping()
    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:
        if (not instance_store):
            drives = [('/dev/xvd%s%%s' % s) for s in string.lowercase]
            for i in range(num_ephemeral_drives):
                (j, k) = ((i % 26), (i / 26))
                device_fmt = drives[k]
                eph = boto.ec2.blockdevicemapping.BlockDeviceType()
                eph.ephemeral_name = ('ephemeral%d' % i)
                bmap[(device_fmt % chr((ord('a') + j)))] = eph
        else:
            drives = [('sd%s%d' % (s, i)) for i in range(1, 10) for s in string.lowercase[1:]]
            for i in range(num_ephemeral_drives):
                eph = boto.ec2.blockdevicemapping.BlockDeviceType()
                eph.ephemeral_name = ('ephemeral%d' % i)
                bmap[drives[i]] = eph
    return bmap
