'Creates a new volume.'

@wsgi.Controller.api_version('2.1', MAX_PROXY_API_SUPPORT_VERSION)
@extensions.expected_errors((400, 403, 404))
@validation.schema(volumes_schema.create)
def create(self, req, body):

    context = req.environ['nova.context']
    context.can(vol_policies.BASE_POLICY_NAME)
    vol = body['volume']
    vol_type = vol.get('volume_type')
    metadata = vol.get('metadata')
    snapshot_id = vol.get('snapshot_id', None)
    if (snapshot_id is not None):
        try:
            snapshot = self.volume_api.get_snapshot(context, snapshot_id)
        except exception.SnapshotNotFound as e:
            raise exc.HTTPNotFound(explanation=e.format_message())
    else:
        snapshot = None
    size = vol.get('size', None)
    if ((size is None) and (snapshot is not None)):
        size = snapshot['volume_size']
    availability_zone = vol.get('availability_zone')
    try:
        new_volume = self.volume_api.create(context, size, vol.get('display_name'), vol.get('display_description'), snapshot=snapshot, volume_type=vol_type, metadata=metadata, availability_zone=availability_zone)
    except exception.InvalidInput as err:
        raise exc.HTTPBadRequest(explanation=err.format_message())
    except exception.OverQuota as err:
        raise exc.HTTPForbidden(explanation=err.format_message())
    retval = _translate_volume_detail_view(context, dict(new_volume))
    result = {'volume': retval}
    location = ('%s/%s' % (req.url, new_volume['id']))
    return wsgi.ResponseObject(result, headers=dict(location=location))
