'Create a volume on EBS. Store Flocker-specific
{metadata version, cluster id, dataset id} for the volume
as volume tag data.
Open issues: https://clusterhq.atlassian.net/browse/FLOC-1792'

def create_volume_with_profile(self, dataset_id, size, profile_name):

    requested_size = int(Byte(size).to_GiB().value)
    try:
        (volume_type, iops) = _volume_type_and_iops_for_profile_name(profile_name, requested_size)
        requested_volume = self._create_ebs_volume(size=requested_size, zone=self.zone, volume_type=volume_type, iops=iops)
    except ClientError as e:
        if (e.response['Error']['Code'] != INVALID_PARAMETER_VALUE):
            raise e
        CREATE_VOLUME_FAILURE(dataset_id=unicode(dataset_id), aws_code=e.response['Error']['Code'], aws_message=unicode(e.response['Error']['Message'])).write()
        (volume_type, iops) = _volume_type_and_iops_for_profile_name(MandatoryProfiles.DEFAULT.value, requested_size)
        requested_volume = self._create_ebs_volume(size=requested_size, zone=self.zone, volume_type=volume_type, iops=iops)
    message_type = (BOTO_LOG_RESULT + u':created_volume')
    Message.new(message_type=message_type, volume_id=unicode(requested_volume.id), dataset_id=unicode(dataset_id), size=unicode(size)).write()
    metadata = {METADATA_VERSION_LABEL: '1', CLUSTER_ID_LABEL: unicode(self.cluster_id), DATASET_ID_LABEL: unicode(dataset_id), 'Name': u'flocker-{}'.format(dataset_id)}
    tags_list = []
    for (key, value) in metadata.items():
        tags_list.append(dict(Key=key, Value=value))
    requested_volume.create_tags(Tags=tags_list)
    message_type = (BOTO_LOG_RESULT + u':created_tags')
    Message.new(message_type=message_type, requested_volume=requested_volume.id, tags=metadata).write()
    _wait_for_volume_state_change(VolumeOperations.CREATE, requested_volume)
    return _blockdevicevolume_from_ebs_volume(requested_volume)
