'Creates a new instance of the requested entity.'

@db_api.retry_db_errors
def _create(self, request, body, **kwargs):

    parent_id = kwargs.get(self._parent_id_name)
    body = Controller.prepare_request_body(request.context, body, True, self._resource, self._attr_info, allow_bulk=self._allow_bulk)
    action = self._plugin_handlers[self.CREATE]
    if (self._collection in body):
        items = body[self._collection]
    else:
        items = [body]
    policy.init()
    request_deltas = collections.defaultdict(int)
    for item in items:
        self._validate_network_tenant_ownership(request, item[self._resource])
        policy.enforce(request.context, action, item[self._resource], pluralized=self._collection)
        if ('tenant_id' not in item[self._resource]):
            continue
        tenant_id = item[self._resource]['tenant_id']
        request_deltas[tenant_id] += 1
    reservations = []
    try:
        for (tenant, delta) in request_deltas.items():
            reservation = quota.QUOTAS.make_reservation(request.context, tenant, {self._resource: delta}, self._plugin)
            reservations.append(reservation)
    except n_exc.QuotaResourceUnknown as e:
        LOG.debug(e)
    def notify(create_result):
        with db_api.context_manager.writer.using(request.context):
            for reservation in reservations:
                quota.QUOTAS.commit_reservation(request.context, reservation.reservation_id)
            resource_registry.set_resources_dirty(request.context)
        notifier_method = (self._resource + '.create.end')
        self._notifier.info(request.context, notifier_method, create_result)
        registry.notify(self._resource, events.BEFORE_RESPONSE, self, context=request.context, data=create_result, method_name=notifier_method, collection=self._collection, action=action, original={})
        return create_result
    def do_create(body, bulk=False, emulated=False):
        kwargs = ({self._parent_id_name: parent_id} if parent_id else {})
        if (bulk and (not emulated)):
            obj_creator = getattr(self._plugin, ('%s_bulk' % action))
        else:
            obj_creator = getattr(self._plugin, action)
        try:
            if emulated:
                return self._emulate_bulk_create(obj_creator, request, body, parent_id)
            else:
                if (self._collection in body):
                    kwargs.update({self._collection: body})
                else:
                    kwargs.update({self._resource: body})
                return obj_creator(request.context, **kwargs)
        except Exception:
            with excutils.save_and_reraise_exception():
                for reservation in reservations:
                    quota.QUOTAS.cancel_reservation(request.context, reservation.reservation_id)
    if ((self._collection in body) and self._native_bulk):
        objs = do_create(body, bulk=True)
        fields_to_strip = self._exclude_attributes_by_policy(request.context, objs[0])
        return notify({self._collection: [self._filter_attributes(obj, fields_to_strip=fields_to_strip) for obj in objs]})
    elif (self._collection in body):
        objs = do_create(body, bulk=True, emulated=True)
        return notify({self._collection: objs})
    else:
        obj = do_create(body)
        return notify({self._resource: self._view(request.context, obj)})
