当前位置: 首页>>代码示例>>Python>>正文


Python JsonOutput.error方法代码示例

本文整理汇总了Python中cloudrunner_server.api.util.JsonOutput.error方法的典型用法代码示例。如果您正苦于以下问题:Python JsonOutput.error方法的具体用法?Python JsonOutput.error怎么用?Python JsonOutput.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cloudrunner_server.api.util.JsonOutput的用法示例。


在下文中一共展示了JsonOutput.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: repository_update

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def repository_update(self, name=None, **kwargs):
        new_name = kwargs.get('new_name')
        repository = Repository.own(request).filter(
            Repository.name == name).one()

        if not repository:
            return O.error("Cannot find repo")

        enabled = kwargs.get("enabled")
        if enabled and enabled in ['1', 'true', 'True']:
            repository.enabled = True
        elif not repository.editable(request):
            return O.error(msg="Cannot edit this repo")
        elif new_name:
            repository.name = new_name
        private = kwargs.get('private')
        if private:
            private = private not in ['0', 'false', 'False']
            repository.private = private

        if repository.type != 'cloudrunner':
            if kwargs.get('user'):
                repository.credentials.auth_user = kwargs.get('user')
            if kwargs.get('pass'):
                if kwargs['pass'] == '---empty---':
                    repository.credentials.auth_pass = ""
                else:
                    repository.credentials.auth_pass = kwargs.get('pass')
            if kwargs.get('args'):
                if kwargs['args'] == '---empty---':
                    repository.credentials.auth_args = ""
                else:
                    repository.credentials.auth_args = kwargs.get('args')

        request.db.add(repository)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:37,代码来源:library.py

示例2: start

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def start(self, name, *args, **kwargs):
        kwargs = kwargs or request.json
        LOG.info("Received rebuild job [%s] from: %s" % (
            name, request.client_addr))

        if not getattr(request, "user", None):
            key = kwargs.pop('key', None)
            if not key:
                return O.error(msg="Missing auth key")

            api_key = get_api_key(key)
            if not api_key:
                return abort(401)
            request.user = cached_user(api_key.user)

        depl = request.db.query(Deployment).filter(
            Deployment.name == name).first()
        if not depl:
            return O.error(msg="Deployment '%s' not found" % depl)
        if depl.status not in ['Pending', 'Stopped']:
            return O.error(msg="Deployment must be Pending or Stopped "
                           "to be Started.")

        request.db.commit()
        task_ids = _execute(depl, env=kwargs)

        return O.success(msg="Started", task_ids=task_ids)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:29,代码来源:execute.py

示例3: script_create

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def script_create(self, name=None, **kwargs):
        name = name or kwargs['name']
        if not Script.valid_name(name):
            return O.error(msg="Invalid script name")
        content = kwargs['content']
        mime = kwargs.get('mime', 'text/plain')
        meta = kwargs.get('meta')
        folder_name = kwargs['folder']
        repository, _, folder_path = folder_name.partition("/")
        folder_path = "/" + folder_path
        if not folder_path.endswith('/'):
            folder_path += "/"

        folder = Folder.editable(request, repository, folder_path).first()
        if not folder or not folder.repository.editable(request):
            return O.error(msg="Folder %s is not editable" % folder_name)

        scr = Script(name=name,
                     owner_id=request.user.id,
                     folder=folder,
                     mime_type=mime)
        request.db.add(scr)
        request.db.commit()
        request._model_id = scr.id

        if isinstance(meta, dict):
            meta = json.dumps(meta)

        rev = Revision(content=content, script_id=scr.id,
                       meta=meta)

        request.db.add(rev)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:34,代码来源:library.py

示例4: activate

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def activate(self, **kwargs):
        if request.method != "POST":
            return O.none()
        if not kwargs:
            kwargs = request.json
        username = kwargs['user']
        key = kwargs['code']
        user = request.db.query(User).join(Org, ApiKey).filter(
            User.username == username,
            ApiKey.value == key, ApiKey.enabled == True).first()  # noqa
        if not user:
            user = request.db.query(User).join(Org, ApiKey).filter(
                User.username == username,
                User.enabled == True).first()  # noqa
            if user:
                return O.error(msg="Already enabled")
            else:
                return O.error(msg="User not found")

        user.enabled = True
        api_key = request.db.query(ApiKey).filter(ApiKey.value == key).one()
        new_key = ApiKey(user=user)

        request.db.delete(api_key)
        request.db.add(user)
        request.db.add(new_key)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:28,代码来源:auth.py

示例5: login

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def login(self, **kwargs):

        if not kwargs:
            kwargs = request.json

        username = kwargs.get('username')
        password = kwargs['password']
        token = kwargs.get('token')
        expire = int(kwargs.get('expire', DEFAULT_EXP))
        if not username and token:
            # Recover
            t = request.db.query(Token).filter(
                Token.value == token, Token.scope == 'RECOVER').first()
            if not t:
                return O.error(msg="The recovery key is invalid "
                               "or expired.")
            username = t.user.username
            t.user.set_password(password)
            request.db.add(t.user)
            request.db.delete(t)
            request.db.commit()

        user = request.db.query(User).join(Org).outerjoin(
            Token, Permission).filter(
                User.enabled == True,  # noqa
                User.username == username,
                User.password == hash_token(password)).first()
        if not user:
            return O.error(msg='Cannot login')

        try:
            expire = int(expire)
            if expire < 0 or expire > MAX_EXP:
                return O.error(msg='Invalid expire timeout, '
                               'should be between 1 and %d minutes' % MAX_EXP)
        except:
            expire = DEFAULT_EXP
        token = User.create_token(request, user.id,
                                  minutes=expire,
                                  scope='LOGIN')

        permissions = [p.name for p in user.permissions]
        md = hashlib.md5()
        md.update(user.email)
        email_hash = md.hexdigest()
        cached_token = dict(uid=user.id, org=user.org.name, token=token.value,
                            tier=user.org.tier.serialize(skip=['id']),
                            permissions=permissions, email=user.email,
                            email_hash=email_hash)

        cache = CacheRegistry()
        cache.add_token(username, cached_token, expire)

        return O.login(user=username,
                       email=user.email,
                       email_hash=email_hash,
                       token=token.value,
                       expire=token.expires_at,
                       org=user.org.name,
                       perms=permissions)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:62,代码来源:auth.py

示例6: repository_delete

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
 def repository_delete(self, *args, **kwargs):
     name = args[0]
     repository = Repository.own(request).filter(
         Repository.name == name).one()
     if not repository.removable(request):
         return O.error(msg="Cannot edit/delete this repo")
     if repository.type == "cloudrunner" and any(
         [f for f in repository.folders
             if f.name != "/" or f.full_name != "/"]):
         return O.error(msg="Cannot remove repo, "
                        "not empty")
     request.db.delete(repository)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:14,代码来源:library.py

示例7: add_share

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def add_share(self, profile, *args, **kwargs):
        name = kwargs.get('name')
        node_quota = int(kwargs.get('node_quota', 0))
        if not name:
            return O.error(msg="Name if required")

        prof = CloudProfile.my(request).filter(
            CloudProfile.name == profile).first()
        if not prof:
            return O.error(msg="Cloud Profile '%s' not found" % profile)

        share = CloudShare(name=name, password=random_token(length=64),
                           node_quota=node_quota, profile=prof)
        request.db.add(share)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:16,代码来源:clouds.py

示例8: rm_group

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def rm_group(self, name, *args):
        group = Group.visible(request).filter(Group.name == name).first()
        if not group:
            return O.error(msg="Group not found")

        request.db.delete(group)
        request.db.commit()
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:9,代码来源:groups.py

示例9: deployments

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def deployments(self, name=None, **kwargs):
        skip = ['id', 'owner_id']

        def _encode(s):
            try:
                return json.loads(s)
            except ValueError:
                return {}
        if name:
            depl = Deployment.my(request).filter(
                Deployment.name == name).first()
            if depl:
                return O.deployment(**depl.serialize(
                    skip=skip,
                    rel=[('content', 'content',
                          lambda p: _encode(p))]))
            else:
                return O.error(msg="Cannot find deployment '%s'" % name)
        else:
            depl = sorted([d.serialize(skip=skip)
                           for d in Deployment.my(request).all()],
                          key=lambda d: d['name'])
            return O._anon(deployments=depl,
                           quota=dict(allowed=request.user.tier.deployments))
        return O.none()
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:27,代码来源:deployments.py

示例10: delete

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
 def delete(self, *args, **kwargs):
     name = "/".join(args)
     depl = Deployment.my(request).filter(Deployment.name == name).first()
     if not depl:
         return O.error(msg="Cannot find deployment '%s'" % name)
     _cleanup(depl)
     request.db.delete(depl)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:9,代码来源:deployments.py

示例11: add_profile

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def add_profile(self, name, *args, **kwargs):
        p_type = kwargs['type']
        user = User.visible(request).filter(
            User.id == request.user.id).first()
        name = name or kwargs['name']

        if p_type == "shared":
            username = kwargs.pop('username')
            password = kwargs.pop('password')
            share = request.db.query(CloudShare).filter(
                CloudShare.name == username,
                CloudShare.password == password).first()
            if not share:
                return O.error(msg="The specified shared profile is not found")
            prof = CloudProfile(name=name, username=username,
                                password=password,
                                owner=user,
                                type=share.profile.type,
                                shared=share.profile)
            request.db.add(prof)
        else:
            username = kwargs.pop('username')
            password = kwargs.pop('password')
            arguments = kwargs.pop('arguments')
            clear_nodes = (bool(kwargs.get('clear_nodes'))
                           and not kwargs.get('clear_nodes')
                           in ['0', 'false', 'False'])

            prof = CloudProfile(name=name, username=username,
                                password=password, arguments=arguments,
                                owner=user,
                                clear_nodes=clear_nodes,
                                type=p_type)
            request.db.add(prof)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:36,代码来源:clouds.py

示例12: folder_delete

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def folder_delete(self, *args, **kwargs):
        full_path = "/".join(args).strip("/")
        repository, _, folder_path = full_path.partition("/")
        folder_path = "/" + folder_path
        if not folder_path.endswith('/'):
            folder_path += "/"

        if folder_path == "/":
            return O.error(msg="Cannot delete root folder")

        folder = Folder.editable(request,
                                 repository,
                                 folder_path).first()
        if not folder:
            return O.error(msg="Folder '%s' not found" % full_path)
        request.db.delete(folder)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:18,代码来源:library.py

示例13: revisions

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def revisions(self, repository, *args, **kwargs):
        path = "/".join(args)
        path.rstrip("/")
        if not path.startswith("/"):
            path = "/" + path

        path, _, script = path.rpartition('/')
        path = path + '/'

        scr = Script.visible(request,
                             repository,
                             path).filter(Script.name == script).first()
        if not scr:
            return O.error(msg="Script not found")

        revisions = sorted([r.serialize(
            skip=['id', 'script_id', 'draft', 'content', 'meta'],
            rel=[("created_at", "created_at", lambda d: d)])
            for r in scr.history
            if not r.draft], key=lambda r: r["created_at"], reverse=True)
        return O.history(
            script=scr.name,
            owner=scr.owner.username,
            revisions=revisions
        )
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:27,代码来源:library.py

示例14: preview

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def preview(self, *args, **kwargs):
        if not args:
            return O.error(msg="Path not provided")
        content = kwargs['content']

        content = expand_script(content)

        return O.preview(content=content)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:10,代码来源:library.py

示例15: start

# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import error [as 别名]
    def start(self, name, *args, **kwargs):
        name = name or kwargs['name']

        depl = Deployment.my(request).filter(Deployment.name == name).first()
        if not depl:
            return O.error(msg="Cannot find deployment '%s'" % name)
        if depl.status not in ['Pending', 'Stopped']:
            return O.error(msg="Deployment must be Pending or Stopped "
                           "to be Started.")

        content = json.loads(depl.content)
        _validate(content)
        request.db.commit()
        depl.status = "Starting"
        task_ids = _execute(depl, **kwargs)

        return O.success(status="ok", task_ids=task_ids)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:19,代码来源:deployments.py


注:本文中的cloudrunner_server.api.util.JsonOutput.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。