예제 #1
0
    def get_all(self, function_id=None, all_projects=False, project_id=None,
                status=None, description=None):
        """Return a list of executions.

        :param function_id: Optional. Filtering executions by function_id.
        :param project_id: Optional. Admin user can query other projects
            resources, the param is ignored for normal user.
        :param all_projects: Optional. Get resources of all projects.
        :param status: Optional. Filter by execution status.
        :param description: Optional. Filter by description.
        """
        ctx = context.get_ctx()
        if project_id and not ctx.is_admin:
            project_id = context.ctx().projectid
        if project_id and ctx.is_admin:
            all_projects = True

        if all_projects:
            acl.enforce('execution:get_all:all_projects', ctx)

        filters = rest_utils.get_filters(
            function_id=function_id,
            project_id=project_id,
            status=status,
            description=description
        )
        LOG.info("Get all %ss. filters=%s", self.type, filters)

        db_execs = db_api.get_executions(insecure=all_projects, **filters)
        executions = [resources.Execution.from_dict(db_model.to_dict())
                      for db_model in db_execs]

        return resources.Executions(executions=executions)
예제 #2
0
    def get_all(self, all_projects=False, project_id=None):
        """Get all the function aliases.

        :param project_id: Optional. Admin user can query other projects
            resources, the param is ignored for normal user.
        :param all_projects: Optional. Get resources of all projects.
        """
        ctx = context.get_ctx()
        project_id, all_projects = rest_utils.get_project_params(
            project_id, all_projects)
        if all_projects:
            acl.enforce('function_version:get_all:all_projects', ctx)

        filters = rest_utils.get_filters(project_id=project_id)

        LOG.info("Get all function aliases. filters=%s", filters)

        db_aliases = db_api.get_function_aliases(insecure=all_projects,
                                                 **filters)
        aliases = [
            resources.FunctionAlias.from_db_obj(db_model)
            for db_model in db_aliases
        ]

        return resources.FunctionAliases(function_aliases=aliases)
예제 #3
0
파일: function.py 프로젝트: Kryndex/qinling
    def get_all(self, all_projects=False, project_id=None):
        """Return a list of functions.

        :param project_id: Optional. Admin user can query other projects
            resources, the param is ignored for normal user.
        :param all_projects: Optional. Get resources of all projects.
        """
        ctx = context.get_ctx()
        if project_id and not ctx.is_admin:
            project_id = context.ctx().projectid
        if project_id and ctx.is_admin:
            all_projects = True

        if all_projects:
            acl.enforce('function:get_all:all_projects', ctx)

        filters = rest_utils.get_filters(project_id=project_id, )
        LOG.info("Get all functions. filters=%s", filters)
        db_functions = db_api.get_functions(insecure=all_projects, **filters)
        functions = [
            resources.Function.from_dict(db_model.to_dict())
            for db_model in db_functions
        ]

        return resources.Functions(functions=functions)
예제 #4
0
    def delete(self, function_id, version):
        """Delete a specific function version.

        - The version should not being used by any job
        - The version should not being used by any webhook
        - Admin user can not delete normal user's version
        """
        ctx = context.get_ctx()
        acl.enforce('function_version:delete', ctx)
        LOG.info("Deleting version %s of function %s.", version, function_id)

        with db_api.transaction():
            version_db = db_api.get_function_version(function_id,
                                                     version,
                                                     insecure=False)
            latest_version = version_db.function.latest_version

            version_jobs = db_api.get_jobs(
                function_id=version_db.function_id,
                function_version=version_db.version_number,
                status={'nin': ['done', 'cancelled']})
            if len(version_jobs) > 0:
                raise exc.NotAllowedException(
                    'The function version is still associated with running '
                    'job(s).')

            version_webhook = db_api.get_webhooks(
                function_id=version_db.function_id,
                function_version=version_db.version_number,
            )
            if len(version_webhook) > 0:
                raise exc.NotAllowedException(
                    'The function version is still associated with webhook.')

            filters = rest_utils.get_filters(
                function_id=version_db.function_id,
                function_version=version_db.version_number)
            version_aliases = db_api.get_function_aliases(**filters)
            if len(version_aliases) > 0:
                raise exc.NotAllowedException(
                    'The function version is still associated with alias.')

            # Delete resources for function version
            self.engine_client.delete_function(function_id, version=version)
            etcd_util.delete_function(function_id, version=version)

            self.storage_provider.delete(ctx.projectid,
                                         function_id,
                                         None,
                                         version=version)

            db_api.delete_function_version(function_id, version)

            if latest_version == version:
                version_db.function.latest_version = latest_version - 1

        LOG.info("Version %s of function %s deleted.", version, function_id)
예제 #5
0
    def get_all(self, all_projects=False, project_id=None):
        project_id, all_projects = rest_utils.get_project_params(
            project_id, all_projects)
        if all_projects:
            acl.enforce('job:get_all:all_projects', context.get_ctx())

        filters = rest_utils.get_filters(project_id=project_id, )
        LOG.info("Get all %ss. filters=%s", self.type, filters)
        db_jobs = db_api.get_jobs(insecure=all_projects, **filters)
        jobs = [resources.Job.from_db_obj(db_model) for db_model in db_jobs]

        return resources.Jobs(jobs=jobs)
예제 #6
0
    def get_all(self, all_projects=False, project_id=None):
        project_id, all_projects = rest_utils.get_project_params(
            project_id, all_projects)
        if all_projects:
            acl.enforce('webhook:get_all:all_projects', context.get_ctx())

        filters = rest_utils.get_filters(project_id=project_id, )

        LOG.info("Get all %ss. filters=%s", self.type, filters)
        webhooks = []
        for i in db_api.get_webhooks(insecure=all_projects, **filters):
            webhooks.append(
                resources.Webhook.from_dict(
                    self._add_webhook_url(i.id, i.to_dict())))

        return resources.Webhooks(webhooks=webhooks)