'Creates a new volume.'

@wsgi.response(http_client.ACCEPTED)
def create(self, req, body):

    self.assert_valid_body(body, 'volume')
    LOG.debug('Create    volume    request    body:    %s', body)
    context = req.environ['cinder.context']
    volume = body['volume']
    kwargs = {}
    self.validate_name_and_description(volume)
    if ('name' in volume):
        volume['display_name'] = volume.pop('name')
    if ('description' in volume):
        volume['display_description'] = volume.pop('description')
    if ('image_id' in volume):
        volume['imageRef'] = volume.pop('image_id')
    req_volume_type = volume.get('volume_type', None)
    if req_volume_type:
        kwargs['volume_type'] = objects.VolumeType.get_by_name_or_id(context, req_volume_type)
    kwargs['metadata'] = volume.get('metadata', None)
    snapshot_id = volume.get('snapshot_id')
    if (snapshot_id is not None):
        if (not uuidutils.is_uuid_like(snapshot_id)):
            msg = _('Snapshot    ID    must    be    in    UUID    form.')
            raise exc.HTTPBadRequest(explanation=msg)
        kwargs['snapshot'] = self.volume_api.get_snapshot(context, snapshot_id)
    else:
        kwargs['snapshot'] = None
    source_volid = volume.get('source_volid')
    if (source_volid is not None):
        if (not uuidutils.is_uuid_like(source_volid)):
            msg = (_("Source    volume    ID    '%s'    must    be    a    valid    UUID.") % source_volid)
            raise exc.HTTPBadRequest(explanation=msg)
        kwargs['source_volume'] = self.volume_api.get_volume(context, source_volid)
    else:
        kwargs['source_volume'] = None
    source_replica = volume.get('source_replica')
    if (source_replica is not None):
        if (not uuidutils.is_uuid_like(source_replica)):
            msg = (_("Source    replica    ID    '%s'    must    be    a    valid    UUID") % source_replica)
            raise exc.HTTPBadRequest(explanation=msg)
        src_vol = self.volume_api.get_volume(context, source_replica)
        if (src_vol['replication_status'] == 'disabled'):
            explanation = (_('source    volume    id:%s    is    not    replicated') % source_replica)
            raise exc.HTTPBadRequest(explanation=explanation)
        kwargs['source_replica'] = src_vol
    else:
        kwargs['source_replica'] = None
    kwargs['group'] = None
    kwargs['consistencygroup'] = None
    consistencygroup_id = volume.get('consistencygroup_id')
    if (consistencygroup_id is not None):
        if (not uuidutils.is_uuid_like(consistencygroup_id)):
            msg = (_("Consistency    group    ID    '%s'    must    be    a    valid    UUID.") % consistencygroup_id)
            raise exc.HTTPBadRequest(explanation=msg)
        kwargs['group'] = self.group_api.get(context, consistencygroup_id)
    size = volume.get('size', None)
    if ((size is None) and (kwargs['snapshot'] is not None)):
        size = kwargs['snapshot']['volume_size']
    elif ((size is None) and (kwargs['source_volume'] is not None)):
        size = kwargs['source_volume']['size']
    elif ((size is None) and (kwargs['source_replica'] is not None)):
        size = kwargs['source_replica']['size']
    LOG.info('Create    volume    of    %s    GB', size)
    if self.ext_mgr.is_loaded('os-image-create'):
        image_ref = volume.get('imageRef')
        if (image_ref is not None):
            image_uuid = self._image_uuid_from_ref(image_ref, context)
            kwargs['image_id'] = image_uuid
    kwargs['availability_zone'] = volume.get('availability_zone', None)
    kwargs['scheduler_hints'] = volume.get('scheduler_hints', None)
    kwargs['multiattach'] = utils.get_bool_param('multiattach', volume)
    new_volume = self.volume_api.create(context, size, volume.get('display_name'), volume.get('display_description'), **kwargs)
    retval = self._view_builder.detail(req, new_volume)
    return retval
