예제 #1
0
파일: base.py 프로젝트: Open-SFC/nscs
    def update(self, request, id, body=None, **kwargs):
        """Updates the specified entity's attributes"""
        parent_ids={}
        if self._parent_ids:
            for pid in self._parent_ids:
                if kwargs.get(pid):
                    parent_ids[pid] = kwargs.get(pid)
        elif kwargs.get(self._parent_id_name):
            parent_ids[self._parent_id_name] = kwargs.get(self._parent_id_name)
        try:
            payload = body.copy()
        except AttributeError:
            msg = _("Invalid format: %s") % request.body
            raise exceptions.BadRequest(resource='body', msg=msg)
        payload['id'] = id
        notifier_api.notify(request.context,
                            self._publisher_id,
                            self._resource + '.update.start',
                            notifier_api.CONF.default_notification_level,
                            payload)
        body = Controller.prepare_request_body(request.context, body, False,
                                               self._resource, self._attr_info,
                                               allow_bulk=self._allow_bulk)
        action = self._plugin_handlers[self.UPDATE]
        # Load object to check authz
        # but pass only attributes in the original body and required
        # by the policy engine to the policy 'brain'
        field_list = [name for (name, value) in self._attr_info.iteritems()
                      if ('required_by_policy' in value and
                          value['required_by_policy'] or
                          'default' not in value)]
        orig_obj = self._item(request, id, field_list=field_list,
                              parent_id=parent_ids)
        orig_obj.update(body[self._resource])
        try:
            policy.enforce(request.context,
                           action,
                           orig_obj,
                           plugin=self._plugin)
        except exceptions.PolicyNotAuthorized:
            # To avoid giving away information, pretend that it
            # doesn't exist
            raise webob.exc.HTTPNotFound()

        obj_updater = getattr(self._plugin, action)
        kwargs = {self._resource: body}
        if parent_ids:
            kwargs.update(parent_ids)
        #LOG.debug(_('kwarge => %s  ID-> %s '), str(kwargs), str(id))    
        obj = obj_updater(request.context, id, **kwargs)
        result = {self._resource: self._view(obj)}
        notifier_method = self._resource + '.update.end'
        notifier_api.notify(request.context,
                            self._publisher_id,
                            notifier_method,
                            notifier_api.CONF.default_notification_level,
                            result)
        return result
예제 #2
0
파일: base.py 프로젝트: Open-SFC/nscs
        def notify(create_result):
            #LOG.debug(_("################ Before Notify  = %s"),str(create_result))
            notifier_method = self._resource + '.create.end'
            notifier_api.notify(request.context,
                                self._publisher_id,
                                notifier_method,
                                notifier_api.CONF.default_notification_level,
                                create_result)

            #LOG.debug(_("################ After Notify  = %s"),str(create_result))
            return create_result
예제 #3
0
파일: base.py 프로젝트: Open-SFC/nscs
    def delete(self, request, id, **kwargs):
        """Deletes the specified entity"""
        notifier_api.notify(request.context,
                            self._publisher_id,
                            self._resource + '.delete.start',
                            notifier_api.CONF.default_notification_level,
                            {self._resource + '_id': id})
        action = self._plugin_handlers[self.DELETE]

        # Check authz
        parent_ids={}
        if self._parent_ids:
            for pid in self._parent_ids:
                if kwargs.get(pid):
                    parent_ids[pid] = kwargs.get(pid)
        elif kwargs.get(self._parent_id_name):
            parent_ids[self._parent_id_name] = kwargs.get(self._parent_id_name)
        obj = self._item(request, id, parent_id=parent_ids)
        try:
            policy.enforce(request.context,
                           action,
                           obj,
                           plugin=self._plugin)
        except exceptions.PolicyNotAuthorized:
            # To avoid giving away information, pretend that it
            # doesn't exist
            raise webob.exc.HTTPNotFound()

        obj_deleter = getattr(self._plugin, action)
        obj_deleter(request.context, id, **kwargs)
        notifier_method = self._resource + '.delete.end'
        notifier_api.notify(request.context,
                            self._publisher_id,
                            notifier_method,
                            notifier_api.CONF.default_notification_level,
                            {self._resource + '_id': id})
        result = {self._resource: self._view(obj)}
예제 #4
0
파일: base.py 프로젝트: Open-SFC/nscs
    def create(self, request, body=None, **kwargs):
        """Creates a new instance of the requested entity"""
        parent_ids={}
        if self._parent_ids:
            for pid in self._parent_ids:
                if kwargs.get(pid):
                    parent_ids[pid] = kwargs.get(pid)
        elif kwargs.get(self._parent_id_name):
            parent_ids[self._parent_id_name] = kwargs.get(self._parent_id_name)
        notifier_api.notify(request.context,
                            self._publisher_id,
                            self._resource + '.create.start',
                            notifier_api.CONF.default_notification_level,
                            body)
        #LOG.debug(_("ATTR INFOOOOOOOOOOOO = %s *************"),str(self._attr_info))
        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]
        # Check authz
        if self._collection in body:
            # Have to account for bulk create
            items = body[self._collection]
            deltas = {}
            bulk = True
        else:
            items = [body]
            bulk = False
        for item in items:
            #self._validate_network_tenant_ownership(request,
            #                                        item[self._resource])
            policy.enforce(request.context,
                           action,
                           item[self._resource],
                           plugin=self._plugin)
            try:
                tenant_id = item[self._resource]['tenant_id']
                #count = quota.QUOTAS.count(request.context, self._resource,
                #                          self._plugin, self._collection,
                #                          tenant_id)
                if bulk:
                    delta = deltas.get(tenant_id, 0) + 1
                    deltas[tenant_id] = delta
                else:
                    delta = 1
                kwargs = {self._resource: delta}
            except exceptions.QuotaResourceUnknown as e:
                # We don't want to quota this resource
                LOG.debug(e)
            #else:
            #    quota.QUOTAS.limit_check(request.context,
            #                             item[self._resource]['tenant_id'],
            #                             **kwargs)

        def notify(create_result):
            #LOG.debug(_("################ Before Notify  = %s"),str(create_result))
            notifier_method = self._resource + '.create.end'
            notifier_api.notify(request.context,
                                self._publisher_id,
                                notifier_method,
                                notifier_api.CONF.default_notification_level,
                                create_result)

            #LOG.debug(_("################ After Notify  = %s"),str(create_result))
            return create_result
        
        kwargs = parent_ids
        if self._collection in body and self._native_bulk:
            # plugin does atomic bulk create operations
            obj_creator = getattr(self._plugin, "%s_bulk" % action)
            objs = obj_creator(request.context, body, **kwargs)
            return notify({self._collection: [self._view(obj)
                                              for obj in objs]})
        else:
            obj_creator = getattr(self._plugin, action)
            if self._collection in body:
                # Emulate atomic bulk behavior
                objs = self._emulate_bulk_create(obj_creator, request,
                                                 body, parent_ids)
                return notify({self._collection: objs})
            else:
                kwargs.update({self._resource: body})
                obj = obj_creator(request.context, **kwargs)
                #LOG.debug(_("Creator_result ******************* view [%s]"), str(obj))
                return notify({self._resource: self._view(obj)})