Beispiel #1
0
 def nodegroups(self, name=None, **kwargs):
     if name:
         group = NodeGroup.visible(request).filter(
             NodeGroup.name == name).first()
         return O.group(group.serialize(skip=['id', 'org_id']))
     else:
         groups = NodeGroup.visible(request).all()
         return O.groups(_list=[
             g.serialize(skip=['id', 'org_id'],
                         rel=[('nodes', 'members', _serialize)])
             for g in groups
         ])
 def groups(self, name=None, *args):
     def modifier(roles):
         return [dict(as_user=role.as_user, servers=role.servers)
                 for role in roles]
     if name:
         group = Group.visible(request).filter(Group.name == name).first()
         return O.group(group.serialize(
             skip=['id', 'org_id'],
             rel=[('roles', 'roles', modifier)]))
     else:
         groups = [u.serialize(
             skip=['id', 'org_id'],
             rel=[('roles', 'roles', modifier)])
             for u in Group.visible(request).all()]
         return O._anon(groups=groups,
                        quota=dict(allowed=request.user.tier.groups))
Beispiel #3
0
    def groups(self, name=None, *args):
        def modifier(roles):
            return [
                dict(as_user=role.as_user, servers=role.servers)
                for role in roles
            ]

        if name:
            group = Group.visible(request).filter(Group.name == name).first()
            return O.group(
                group.serialize(skip=['id', 'org_id'],
                                rel=[('roles', 'roles', modifier)]))
        else:
            groups = [
                u.serialize(skip=['id', 'org_id'],
                            rel=[('roles', 'roles', modifier)])
                for u in Group.visible(request).all()
            ]
            return O._anon(groups=groups,
                           quota=dict(allowed=request.user.tier.groups))
Beispiel #4
0
    def get(self, group=None, task_ids=None, run_uuids=None,
            nodes=None, etag=None, script_name=None):
        try:
            groups = TaskGroup.unique(request).order_by(Task.created_at.desc())
            if group:
                groups = groups.filter(TaskGroup.id == group)
            else:
                if run_uuids:
                    run_uuids = run_uuids.split(',')
                    groups = groups.filter(Run.uuid.in_(run_uuids))
                if nodes:
                    nodes = nodes.split(',')
                    if len(nodes) == 1:
                        nodes = [valid_node_name(*nodes)]
                    else:
                        nodes = valid_node_name(*nodes)

                    if nodes:
                        groups = groups.filter(RunNode.name.in_(nodes))
                if script_name:
                    scr = Script.find(request, script_name).one()
                    groups = groups.join(Revision,
                                         Script).filter(Script.id == scr.id)
            ts = None
            if etag:
                ts = datetime.utcfromtimestamp(etag / 1000.0)
                groups = groups.filter(Task.created_at >= ts)
            group = groups.first()
            if not group:
                return O.task()
            group = group[0]
            tasks = Task.visible(request).filter(
                Task.taskgroup_id == group)

            if task_ids:
                task_ids = task_ids.split(",")
                tasks = tasks.filter(Task.uuid.in_(task_ids))

            tasks = tasks.all()

            batch = {'workflows': []}
            for task in tasks:
                data = dict(created_at=task.created_at,
                            exit_code=task.exit_code,
                            uuid=task.uuid,
                            status=LOG_STATUS.from_value(task.status),
                            script_name=task.script_name,
                            timeout=task.timeout)

                data['runs'] = []
                for r in task.runs:
                    to_skip = ['id', 'task_id', 'exec_user_id']
                    rels = [('nodes', 'nodes', map_nodes2),
                            ('env_out', 'env_out', lambda e: e or {}),
                            ('env_in', 'env_in', lambda e: safe_load(e))]
                    if r.exec_user_id != int(request.user.id):
                        to_skip.extend(['env_in', 'env_out', 'full_script'])
                    data['runs'].append(r.serialize(skip=to_skip,
                                                    rel=rels))
                data['runs'] = sorted(data['runs'],
                                      key=lambda _r: _r['step_index'])
                batch['workflows'].append(data)
            return O.group(**batch)
        except exc.NoResultFound, ex:
            LOG.error(ex)
            request.db.rollback()