Example #1
0
 def create_log(self, context, log):
     """Create a log object"""
     log_data = log['log']
     resource_type = log_data['resource_type']
     if resource_type not in self.supported_logging_types:
         raise log_exc.InvalidLogResourceType(resource_type=resource_type)
     validators.validate_request(context, log_data)
     with db_api.context_manager.writer.using(context):
         # body 'log' contains both tenant_id and project_id
         # but only latter needs to be used to create Log object.
         # We need to remove redundant keyword.
         log_data.pop('tenant_id', None)
         log_obj = log_object.Log(context=context, **log_data)
         log_obj.create()
     return log_obj
Example #2
0
    def validate_request(self, context, log_data):
        """
        This method will get validated method according to resource_type. An
        InvalidLogResourceType exception will be raised if there is no logging
        driver that supports resource_type as logging resource. In addition,
        a ValidatedMethodNotFound exception will be raised if a validate method
        was not registered for resource_type.
        """

        resource_type = log_data.get('resource_type')
        log_plugin = directory.get_plugin(alias=plugin_const.LOG_API)
        supported_logging_types = log_plugin.supported_logging_types

        if resource_type in supported_logging_types:
            method = self.get_validated_method(resource_type)
            method(context, log_data)
        else:
            raise log_exc.InvalidLogResourceType(resource_type=resource_type)