'Creates a new server group.'

@wsgi.Controller.api_version('2.1')
@extensions.expected_errors((400, 403))
@validation.schema(schema.create, '2.0', '2.14')
@validation.schema(schema.create_v215, '2.15')
def create(self, req, body):

    context = _authorize_context(req, 'create')
    try:
        objects.Quotas.check_deltas(context, {'server_groups': 1}, context.project_id, context.user_id)
    except nova.exception.OverQuota:
        msg = _('Quota    exceeded,    too    many    server    groups.')
        raise exc.HTTPForbidden(explanation=msg)
    vals = body['server_group']
    sg = objects.InstanceGroup(context)
    sg.project_id = context.project_id
    sg.user_id = context.user_id
    try:
        sg.name = vals.get('name')
        sg.policies = vals.get('policies')
        sg.create()
    except ValueError as e:
        raise exc.HTTPBadRequest(explanation=e)
    if CONF.quota.recheck_quota:
        try:
            objects.Quotas.check_deltas(context, {'server_groups': 0}, context.project_id, context.user_id)
        except nova.exception.OverQuota:
            sg.destroy()
            msg = _('Quota    exceeded,    too    many    server    groups.')
            raise exc.HTTPForbidden(explanation=msg)
    return {'server_group': self._format_server_group(context, sg, req)}
