Ejemplo n.º 1
0
def get_distro_activity():
    """
    Returns a pageable JSON collection of all distro activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``distro``
        Name of the distro affected.
    ``distro.name``
        Name of the distro affected.
    """
    query = DistroActivity.query.order_by(DistroActivity.id.desc())
    # join Distro for sorting/filtering and also for eager loading
    query = query.join(DistroActivity.object)\
            .options(contains_eager(DistroActivity.object))
    if not request.args.get('q'):
        # need to avoid a filesort due to MySQL picking distro as first table
        query = query.with_hint(DistroActivity.__table__,
                'IGNORE INDEX (ix_distro_activity_distro_id)', 'mysql')
    json_result = json_collection(query,
            columns=dict(common_activity_search_columns.items() + {
                'distro': Distro.name,
                'distro.name': Distro.name,
                }.items()),
            skip_count=True)
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template('bkr.server.templates.backgrid', {
        'title': u'Distro Activity',
        'grid_collection_type': 'Activity',
        'grid_collection_data': json_result,
        'grid_collection_url': request.path,
        'grid_view_type': 'DistroActivityView',
    })
Ejemplo n.º 2
0
def get_lab_controller_activity():
    """
    Returns a pageable JSON collection of all lab controller activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``lab_controller``
        FQDN of the lab controller affected.
    ``lab_controller.fqdn``
        FQDN of the lab controller affected.
    """
    query = LabControllerActivity.query.order_by(LabControllerActivity.id.desc())
    # join LabController for sorting/filtering and also for eager loading
    query = query.join(LabControllerActivity.object)\
            .options(contains_eager(LabControllerActivity.object))
    if not request.args.get('q'):
        # need to avoid a filesort due to MySQL picking lab_controller as first table
        query = query.with_hint(LabControllerActivity.__table__,
                'IGNORE INDEX (ix_lab_controller_activity_lab_controller_id)', 'mysql')
    json_result = json_collection(query,
            columns=dict(common_activity_search_columns.items() + {
                'lab_controller': LabController.fqdn,
                'lab_controller.fqdn': LabController.fqdn,
                }.items()))
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template('bkr.server.templates.backgrid', {
        'title': u'Lab Controller Activity',
        'grid_collection_type': 'Activity',
        'grid_collection_data': json_result,
        'grid_collection_url': request.path,
        'grid_view_type': 'LabControllerActivityView',
    })
Ejemplo n.º 3
0
def get_systems_activity(): # distinct from get_system_activity
    """
    Returns a pageable JSON collection of all system activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``system``
        FQDN of the system affected.
    ``system.fqdn``
        FQDN of the system affected.
    """
    query = SystemActivity.query.order_by(SystemActivity.id.desc())
    # join System for sorting/filtering and also for eager loading
    query = query.join(SystemActivity.object)\
            .options(contains_eager(SystemActivity.object))
    if not request.args.get('q'):
        # need to avoid a filesort due to MySQL picking system as first table
        query = query.with_hint(SystemActivity.__table__,
                'IGNORE INDEX (ix_system_activity_system_id)', 'mysql')
    json_result = json_collection(query,
            columns=dict(common_activity_search_columns.items() + {
                'system': System.fqdn,
                'system.fqdn': System.fqdn,
                }.items()),
            skip_count=True)
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template('bkr.server.templates.backgrid', {
        'title': u'System Activity',
        'grid_collection_type': 'Activity',
        'grid_collection_data': json_result,
        'grid_collection_url': request.path,
        'grid_view_type': 'SystemsActivityView',
    })
Ejemplo n.º 4
0
def get_tasks():
    """
    Returns a pageable JSON collection of the task library in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``id``
        ID of the task.
    ``name``
        Name of the task.
    ``description``
        The description of the task provided in the loaded RPM.
    ``version``
        Version of the task provided in the loaded RPM.
    ``type``
        Type of the task, derived from the ``Type`` field in the task metadata.
    ``excluded_arch``
        Arch for which the task is excluded from. Tasks
        are applicable to all arches by default, unless specified
        otherwise in the ``Architectures`` field of the task metadata.
    ``excluded_osmajor``
        OS major version for which the task is excluded from.
        Tasks are applicable to all OS major versions by default,
        unless otherwise specified in the ``Releases`` field of
        the task metadata.
    """
    query = Task.query.filter(Task.valid == True).order_by(Task.name)
    json_result = json_collection(query,
                                  columns={
                                      'id':
                                      Task.id,
                                      'name':
                                      Task.name,
                                      'description':
                                      Task.description,
                                      'version':
                                      Task.version,
                                      'type': (Task.types, TaskType.type),
                                      'excluded_arch':
                                      (Task.excluded_arches, Arch.arch),
                                      'excluded_osmajor':
                                      (Task.excluded_osmajors,
                                       OSMajor.osmajor),
                                  })

    if request_wants_json():
        return jsonify(json_result)

    result = render_tg_template(
        'bkr.server.templates.backgrid', {
            'title': 'Tasks Library',
            'grid_collection_type': 'TaskLibrary',
            'grid_collection_data': json_result,
            'grid_collection_url': request.base_url,
            'grid_view_type': 'TasksView',
        })
    return result
Ejemplo n.º 5
0
def get_groups():
    """
    Returns a pageable JSON collection of Beaker groups.

    The following fields are supported for filtering and sorting:

    ``id``
        ID of the group.
    ``group_name``
        Symbolic name of the group.
    ``display_name``
        Human-friendly display name of the group.
    ``created``
        Timestamp at which the group was created.
    """
    query = Group.query.order_by(Group.group_name)
    # Eager load all group members as an optimisation to avoid N database roundtrips
    query = query.options(joinedload('user_group_assocs'),
                          joinedload('user_group_assocs.user'))
    json_result = json_collection(
        query,
        columns={
            'id': Group.id,
            'group_name': Group.group_name,
            'display_name': Group.display_name,
            'created': Group.created,
            'member.user_name': (Group.dyn_users, User.user_name),
            'member.display_name': (Group.dyn_users, User.display_name),
            'member.email_address': (Group.dyn_users, User.email_address),
            'owner.user_name': (Group.dyn_owners, User.user_name),
            'owner.display_name': (Group.dyn_owners, User.display_name),
            'owner.email_address': (Group.dyn_owners, User.email_address),
        })
    # Need to call .to_json() on the groups because the default __json__
    # representation is the minimal cut-down one, we want the complete
    # representation here (including members and owners etc).
    json_result['entries'] = [g.to_json() for g in json_result['entries']]
    if request_wants_json():
        return jsonify(json_result)
    if identity.current.user:
        grid_add_view_type = 'GroupCreateModal',
        grid_add_view_options = {
            'can_create_ldap': Group.can_create_ldap(identity.current.user),
        }
    else:
        grid_add_view_type = 'null'
        grid_add_view_options = {}
    return render_tg_template(
        'bkr.server.templates.backgrid', {
            'title': u'Groups',
            'grid_collection_type': 'Groups',
            'grid_collection_data': json_result,
            'grid_collection_url': request.path,
            'grid_view_type': 'GroupsView',
            'grid_add_label': 'Create',
            'grid_add_view_type': grid_add_view_type,
            'grid_add_view_options': grid_add_view_options,
        })
Ejemplo n.º 6
0
def get_distro_tree_activity():
    """
    Returns a pageable JSON collection of all distro tree activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``distro_tree.distro``
        Distro name of the tree affected.
    ``distro_tree.distro.name``
        Distro name of the tree affected.
    ``distro_tree.variant``
        Variant of the tree affected.
    ``distro_tree.arch``
        Arch of the tree affected.
    """
    query = DistroTreeActivity.query.order_by(DistroTreeActivity.id.desc())
    # join DistroTree, Distro, and Arch for sorting/filtering and also for eager loading
    query = (
        query.join(DistroTreeActivity.object)
        .join(DistroTree.distro)
        .join(DistroTree.arch)
        .options(contains_eager(DistroTreeActivity.object, DistroTree.distro))
        .options(contains_eager(DistroTreeActivity.object, DistroTree.arch))
    )
    if not request.args.get("q"):
        # need to avoid a filesort due to MySQL picking distro_tree as first table
        query = query.with_hint(
            DistroTreeActivity.__table__, "IGNORE INDEX (ix_distro_tree_activity_distro_tree_id)", "mysql"
        )
    json_result = json_collection(
        query,
        columns=dict(
            common_activity_search_columns.items()
            + {
                "distro_tree.distro": Distro.name,
                "distro_tree.distro.name": Distro.name,
                "distro_tree.variant": DistroTree.variant,
                "distro_tree.arch": Arch.arch,
            }.items()
        ),
        skip_count=True,
    )
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        "bkr.server.templates.backgrid",
        {
            "title": u"Distro Tree Activity",
            "grid_collection_type": "Activity",
            "grid_collection_data": json_result,
            "grid_collection_url": request.path,
            "grid_view_type": "DistroTreeActivityView",
        },
    )
Ejemplo n.º 7
0
def get_powertypes():
    """Returns a JSON collection of all power types defined in Beaker."""
    result = PowerType.query.order_by(PowerType.name).all()
    if request_wants_json():
        return jsonify(power_types=result)
    return render_tg_template('bkr.server.templates.power_types', {
        'title': 'Power Types',
        'power_types': result,
        'power_types_url': url('/powertypes/'),
        'user_can_edit': identity.current.user is not None and identity.current.user.is_admin()
    })
Ejemplo n.º 8
0
def get_labcontrollers():
    """Returns a JSON collection of all labcontrollers defined in Beaker."""
    labcontrollers = LabController.query.order_by(LabController.fqdn).all()
    if request_wants_json():
        return jsonify(entries=labcontrollers)
    can_edit = identity.current.user is not None and identity.current.user.is_admin()
    return render_tg_template('bkr.server.templates.labcontrollers', {
        'title': 'Lab Controllers',
        'labcontrollers': labcontrollers,
        'labcontrollers_url': absolute_url('/labcontrollers/'),
        'can_edit': can_edit,
    })
Ejemplo n.º 9
0
def get_labcontrollers():
    """Returns a JSON collection of all labcontrollers defined in Beaker."""
    labcontrollers = LabController.query.order_by(LabController.fqdn).all()
    if request_wants_json():
        return jsonify(entries=labcontrollers)
    can_edit = identity.current.user is not None and identity.current.user.is_admin()
    return render_tg_template('bkr.server.templates.labcontrollers', {
        'title': 'Lab Controllers',
        'labcontrollers': labcontrollers,
        'labcontrollers_url': absolute_url('/labcontrollers/'),
        'can_edit': can_edit,
    })
Ejemplo n.º 10
0
def get_groups():
    """
    Returns a pageable JSON collection of Beaker groups.

    The following fields are supported for filtering and sorting:

    ``group_name``
        Symbolic name of the group.
    ``display_name``
        Human-friendly display name of the group.
    ``created``
        Timestamp at which the group was created.
    """
    query = Group.query.order_by(Group.group_name)
    # Eager load all group members as an optimisation to avoid N database roundtrips
    query = query.options(joinedload('user_group_assocs'),
            joinedload('user_group_assocs.user'))
    json_result = json_collection(query, columns={
        'group_name': Group.group_name,
        'display_name': Group.display_name,
        'created': Group.created,
        'member.user_name': (Group.dyn_users, User.user_name),
        'member.display_name': (Group.dyn_users, User.display_name),
        'member.email_address': (Group.dyn_users, User.email_address),
        'owner.user_name': (Group.dyn_owners, User.user_name),
        'owner.display_name': (Group.dyn_owners, User.display_name),
        'owner.email_address': (Group.dyn_owners, User.email_address),
    })
    # Need to call .to_json() on the groups because the default __json__ 
    # representation is the minimal cut-down one, we want the complete 
    # representation here (including members and owners etc).
    json_result['entries'] = [g.to_json() for g in json_result['entries']]
    if request_wants_json():
        return jsonify(json_result)
    if identity.current.user:
        grid_add_view_type = 'GroupCreateModal',
        grid_add_view_options = {
            'can_create_ldap': Group.can_create_ldap(identity.current.user),
        }
    else:
        grid_add_view_type = 'null'
        grid_add_view_options = {}
    return render_tg_template('bkr.server.templates.backgrid', {
        'title': u'Groups',
        'grid_collection_type': 'Groups',
        'grid_collection_data': json_result,
        'grid_collection_url': request.path,
        'grid_view_type': 'GroupsView',
        'grid_add_label': 'Create',
        'grid_add_view_type': grid_add_view_type,
        'grid_add_view_options': grid_add_view_options,
    })
Ejemplo n.º 11
0
def get_users():
    """
    Returns a pageable JSON collection of all users accounts in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``id``
        ID of the user.
    ``user_name``
        The user's username.
    ``display_name``
        Full display name of the user.
    ``email_address``
        The user's email address.
    ``disabled``
        A boolean field which is true if the user has been temporarily disabled 
        by the Beaker administrator (preventing them from logging in or running 
        jobs).
    ``removed``
        Timestamp when the user account was deleted, or null for a user account 
        which has not been deleted.
    """
    query = User.query.order_by(User.user_name)
    json_result = json_collection(query,
                                  columns={
                                      'id': User.id,
                                      'user_name': User.user_name,
                                      'display_name': User.display_name,
                                      'email_address': User.email_address,
                                      'disabled': User.disabled,
                                      'removed': User.removed,
                                  })
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        'bkr.server.templates.backgrid', {
            'title':
            u'Users',
            'grid_collection_type':
            'Users',
            'grid_collection_data':
            json_result,
            'grid_collection_url':
            request.path,
            'grid_view_type':
            'UsersView',
            'grid_add_label':
            'Create',
            'grid_add_view_type':
            'UserCreateModal' if identity.current.user.is_admin() else 'null',
        })
Ejemplo n.º 12
0
def get_group(group_name):
    """
    Provides detailed information about a group in JSON format.

    :param group_name: Group's name.
    """
    group = _get_group_by_name(group_name)
    if request_wants_json():
        return jsonify(group.to_json())
    return render_tg_template('bkr.server.templates.group', {
        'title': group.group_name,
        'group': group,
    })
Ejemplo n.º 13
0
def get_pool(pool_name):
    """
    Provides detailed information about a system pool in JSON format.

    :param pool_name: System pool's name.
    """
    pool = _get_pool_by_name(pool_name)
    if request_wants_json():
        return jsonify(pool.__json__())
    return render_tg_template('bkr.server.templates.system_pool', {
        'title': pool.name,
        'system_pool': pool,
    })
Ejemplo n.º 14
0
def get_group(group_name):
    """
    Provides detailed information about a group in JSON format.

    :param group_name: Group's name.
    """
    group = _get_group_by_name(group_name)
    if request_wants_json():
        return jsonify(group.to_json())
    return render_tg_template('bkr.server.templates.group', {
        'title': group.group_name,
        'group': group,
    })
Ejemplo n.º 15
0
def get_pool(pool_name):
    """
    Provides detailed information about a system pool in JSON format.

    :param pool_name: System pool's name.
    """
    pool = _get_pool_by_name(pool_name)
    if request_wants_json():
        return jsonify(pool.__json__())
    return render_tg_template('bkr.server.templates.system_pool', {
        'title': pool.name,
        'system_pool': pool,
    })
Ejemplo n.º 16
0
def get_system_pools_activity():
    """
    Returns a pageable JSON collection of all system pool activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``pool``
        Name of the system pool
    ``pool.name``
        Name of the system pool
    ``pool.owner.user_name``
        Username of the pool owner (if the pool is owned by a user rather than 
        by a group).
    ``pool.owner.group_name``
        Name of the pool's owning group (if the pool is owned by a group rather 
        than by a user).

    """
    query = SystemPoolActivity.query.order_by(SystemPoolActivity.id.desc())
    query = (
        query.join(SystemPoolActivity.object)
        .options(contains_eager(SystemPoolActivity.object))
        .outerjoin(SystemPool.owning_user)
        .outerjoin(SystemPool.owning_group)
    )
    json_result = json_collection(
        query,
        columns=dict(
            common_activity_search_columns.items()
            + {
                "pool": SystemPool.name,
                "pool.name": SystemPool.name,
                "pool.owner.user_name": User.user_name,
                "pool.owner.group_name": Group.group_name,
            }.items()
        ),
        skip_count=True,
    )
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        "bkr.server.templates.backgrid",
        {
            "title": u"System Pool Activity",
            "grid_collection_type": "Activity",
            "grid_collection_data": json_result,
            "grid_collection_url": request.path,
            "grid_view_type": "SystemPoolActivityView",
        },
    )
Ejemplo n.º 17
0
def get_user(username):
    """
    Returns details about a Beaker user account.

    :param username: The user's username.
    """
    user = _get_user(username)
    attributes = user_full_json(user)
    if request_wants_json():
        return jsonify(attributes)
    return render_tg_template('bkr.server.templates.user_edit_form', {
        'attributes': attributes,
        'url': user.href,
    })
Ejemplo n.º 18
0
def get_user(username):
    """
    Returns details about a Beaker user account.

    :param username: The user's username.
    """
    user = _get_user(username)
    attributes = user_full_json(user)
    if request_wants_json():
        return jsonify(attributes)
    return render_tg_template('bkr.server.templates.user_edit_form', {
        'attributes': attributes,
        'url': user.href,
    })
Ejemplo n.º 19
0
def prefs():
    user = identity.current.user
    attributes = user_full_json(user)
    # Show all future root passwords, and the previous five
    rootpw = ConfigItem.by_name('root_password')
    rootpw_values = rootpw.values().filter(rootpw.value_class.valid_from > datetime.utcnow())\
                   .order_by(rootpw.value_class.valid_from.desc()).all()\
                  + rootpw.values().filter(rootpw.value_class.valid_from <= datetime.utcnow())\
                   .order_by(rootpw.value_class.valid_from.desc())[:5]
    return render_tg_template('bkr.server.templates.prefs', {
        'user': user,
        'attributes': attributes,
        'default_root_password': rootpw.current_value(),
        'default_root_passwords': rootpw_values,
    })
Ejemplo n.º 20
0
def prefs():
    user = identity.current.user
    attributes = user_full_json(user)
    # Show all future root passwords, and the previous five
    rootpw = ConfigItem.by_name('root_password')
    rootpw_values = rootpw.values().filter(rootpw.value_class.valid_from > datetime.utcnow())\
                   .order_by(rootpw.value_class.valid_from.desc()).all()\
                  + rootpw.values().filter(rootpw.value_class.valid_from <= datetime.utcnow())\
                   .order_by(rootpw.value_class.valid_from.desc())[:5]
    return render_tg_template('bkr.server.templates.prefs', {
        'user': user,
        'attributes': attributes,
        'default_root_password': rootpw.current_value(),
        'default_root_passwords': rootpw_values,
    })
Ejemplo n.º 21
0
def get_pools():
    """
    Returns a pageable JSON collection of system pools in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``name``
        Name of the pool.
    ``owner.user_name``
        Username of the pool owner (if the pool is owned by a user rather than 
        by a group).
    ``owner.group_name``
        Name of the pool's owning group (if the pool is owned by a group rather 
        than by a user).
    """
    query = SystemPool.query.order_by(SystemPool.name)
    # join User and Group for sorting/filtering and also for eager loading
    query = query\
            .outerjoin(SystemPool.owning_user)\
            .options(contains_eager(SystemPool.owning_user))\
            .outerjoin(SystemPool.owning_group)\
            .options(contains_eager(SystemPool.owning_group))
    json_result = json_collection(query,
                                  columns={
                                      'name': SystemPool.name,
                                      'owner.user_name': User.user_name,
                                      'owner.group_name': Group.group_name,
                                  })
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        'bkr.server.templates.backgrid', {
            'title':
            u'Pools',
            'grid_collection_type':
            'SystemPools',
            'grid_collection_data':
            json_result,
            'grid_collection_url':
            request.base_url,
            'grid_view_type':
            'PoolsView',
            'grid_add_label':
            'Create',
            'grid_add_view_type':
            'PoolCreateModal' if not identity.current.anonymous else 'null',
        })
Ejemplo n.º 22
0
def get_user(username):
    """
    Returns details about a Beaker user account.

    :param username: The user's username.
    """
    user = User.by_user_name(username)
    if user is None:
        raise NotFound404('User %s does not exist' % username)
    attributes = user_full_json(user)
    if request_wants_json():
        return jsonify(attributes)
    return render_tg_template('bkr.server.templates.user_edit_form', {
        'attributes': attributes,
        'url': user.href,
    })
Ejemplo n.º 23
0
def get_user(username):
    """
    Returns details about a Beaker user account.

    :param username: The user's username.
    """
    user = User.by_user_name(username)
    if user is None:
        raise NotFound404('User %s does not exist' % username)
    attributes = user_full_json(user)
    if request_wants_json():
        return jsonify(attributes)
    return render_tg_template('bkr.server.templates.user_edit_form', {
        'attributes': attributes,
        'url': user.href,
    })
Ejemplo n.º 24
0
def get_activity():
    """
    Returns a pageable JSON collection of all activity records in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``type``
        Type of the activity record. Possible values are: ``system_activity``, 
        ``lab_controller_activity``, ``distro_activity``, 
        ``distro_tree_activity``, ``job_activity``, ``recipeset_activity``, 
        ``user_activity``, ``group_activity``.
    ``service``
        Service through which the action was performed. Usually this is 
        ``XMLRPC``, ``WEBUI``, ``HTTP``, or ``Scheduler``.
    ``created``
        Timestamp at which the activity was recorded.
    ``action``
        Action which was recorded.
    ``field_name``
        Field in the system data which was affected by the action.
    ``old_value``
        Previous value of the field before the action was performed (if applicable).
    ``new_value``
        New value of the field after the action was performed (if applicable).
    """
    query = Activity.query.order_by(Activity.id.desc())
    # Command queue inherits from activity but really it's a separate thing, so
    # we filter it out. The obvious way would be:
    #   query = query.filter(Activity.type != 'command_activity')
    # but that destroys all performance, because MySQL.
    # Hence this outer join business.
    query = query.outerjoin(CommandActivity.__table__)\
            .filter(CommandActivity.id == None)
    json_result = json_collection(query,
                                  columns=common_activity_search_columns,
                                  skip_count=True)
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        'bkr.server.templates.backgrid', {
            'title': u'Activity',
            'grid_collection_type': 'Activity',
            'grid_collection_data': json_result,
            'grid_collection_url': request.base_url,
            'grid_view_type': 'ActivityView',
        })
Ejemplo n.º 25
0
def get_recipe(id):
    """
    Provides detailed information about a recipe in JSON format.

    :param id: Recipe's id.
    """
    recipe = _get_recipe_by_id(id)
    if request_wants_json():
        return jsonify(recipe.to_json(include_recipeset=True))
    if identity.current.user and identity.current.user.use_old_job_page:
        return NotFound404('Fall back to old recipe page')
    if identity.current.user:
        recipe.set_reviewed_state(identity.current.user, True)
    return render_tg_template('bkr.server.templates.recipe', {
        'title': recipe.t_id,
        'recipe': recipe,
    })
Ejemplo n.º 26
0
def get_activity():
    """
    Returns a pageable JSON collection of all activity records in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``type``
        Type of the activity record. Possible values are: ``system_activity``, 
        ``lab_controller_activity``, ``distro_activity``, 
        ``distro_tree_activity``, ``job_activity``, ``recipeset_activity``, 
        ``recipe_activity``,``user_activity``, ``group_activity``.
    ``service``
        Service through which the action was performed. Usually this is 
        ``XMLRPC``, ``WEBUI``, ``HTTP``, or ``Scheduler``.
    ``created``
        Timestamp at which the activity was recorded.
    ``action``
        Action which was recorded.
    ``field_name``
        Field in the system data which was affected by the action.
    ``old_value``
        Previous value of the field before the action was performed (if applicable).
    ``new_value``
        New value of the field after the action was performed (if applicable).
    """
    query = Activity.query.order_by(Activity.id.desc())
    # Command queue inherits from activity but really it's a separate thing, so
    # we filter it out. The obvious way would be:
    #   query = query.filter(Activity.type != 'command_activity')
    # but that destroys all performance, because MySQL.
    # Hence this outer join business.
    query = query.outerjoin(CommandActivity.__table__).filter(CommandActivity.id == None)
    json_result = json_collection(query, columns=common_activity_search_columns, skip_count=True)
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        "bkr.server.templates.backgrid",
        {
            "title": u"Activity",
            "grid_collection_type": "Activity",
            "grid_collection_data": json_result,
            "grid_collection_url": request.path,
            "grid_view_type": "ActivityView",
        },
    )
Ejemplo n.º 27
0
def get_powertypes():
    """Returns a JSON collection of all power types defined in Beaker."""
    result = PowerType.query.order_by(PowerType.name).all()
    if request_wants_json():
        return jsonify(power_types=result)
    return render_tg_template(
        'bkr.server.templates.power_types', {
            'title':
            'Power Types',
            'power_types':
            result,
            'power_types_url':
            url('/powertypes/'),
            'user_can_edit':
            identity.current.user is not None
            and identity.current.user.is_admin()
        })
Ejemplo n.º 28
0
def get_recipe(id):
    """
    Provides detailed information about a recipe in JSON format.

    :param id: Recipe's id.
    """
    recipe = _get_recipe_by_id(id)
    if request_wants_json():
        return jsonify(recipe.to_json(include_recipeset=True))
    if identity.current.user and identity.current.user.use_old_job_page:
        return NotFound404('Fall back to old recipe page')
    if identity.current.user and (recipe.is_finished()
            or recipe.status == TaskStatus.reserved):
        recipe.set_reviewed_state(identity.current.user, True)
    return render_tg_template('bkr.server.templates.recipe', {
        'title': recipe.t_id,
        'recipe': recipe,
    })
Ejemplo n.º 29
0
def get_system_pools_activity():
    """
    Returns a pageable JSON collection of all system pool activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``pool``
        Name of the system pool
    ``pool.name``
        Name of the system pool
    ``pool.owner.user_name``
        Username of the pool owner (if the pool is owned by a user rather than 
        by a group).
    ``pool.owner.group_name``
        Name of the pool's owning group (if the pool is owned by a group rather 
        than by a user).

    """
    query = SystemPoolActivity.query.order_by(SystemPoolActivity.id.desc())
    query = query.join(SystemPoolActivity.object)\
            .options(contains_eager(SystemPoolActivity.object)) \
            .outerjoin(SystemPool.owning_user) \
            .outerjoin(SystemPool.owning_group)
    json_result = json_collection(
        query,
        columns=dict(
            common_activity_search_columns.items() + {
                'pool': SystemPool.name,
                'pool.name': SystemPool.name,
                'pool.owner.user_name': User.user_name,
                'pool.owner.group_name': Group.group_name,
            }.items()),
        skip_count=True)
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        'bkr.server.templates.backgrid', {
            'title': u'System Pool Activity',
            'grid_collection_type': 'Activity',
            'grid_collection_data': json_result,
            'grid_collection_url': request.base_url,
            'grid_view_type': 'SystemPoolActivityView',
        })
Ejemplo n.º 30
0
def get_users():
    """
    Returns a pageable JSON collection of all users accounts in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``id``
        ID of the user.
    ``user_name``
        The user's username.
    ``display_name``
        Full display name of the user.
    ``email_address``
        The user's email address.
    ``disabled``
        A boolean field which is true if the user has been temporarily disabled 
        by the Beaker administrator (preventing them from logging in or running 
        jobs).
    ``removed``
        Timestamp when the user account was deleted, or null for a user account 
        which has not been deleted.
    """
    query = User.query.order_by(User.user_name)
    json_result = json_collection(query, columns={
        'id': User.id,
        'user_name': User.user_name,
        'display_name': User.display_name,
        'email_address': User.email_address,
        'disabled': User.disabled,
        'removed': User.removed,
    })
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template('bkr.server.templates.backgrid', {
        'title': u'Users',
        'grid_collection_type': 'Users',
        'grid_collection_data': json_result,
        'grid_collection_url': request.path,
        'grid_view_type': 'UsersView',
        'grid_add_label': 'Create',
        'grid_add_view_type': 'UserCreateModal' if identity.current.user.is_admin() else 'null',
    })
Ejemplo n.º 31
0
def get_pools():
    """
    Returns a pageable JSON collection of system pools in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``id``
        ID of the pool.
    ``name``
        Name of the pool.
    ``owner.user_name``
        Username of the pool owner (if the pool is owned by a user rather than 
        by a group).
    ``owner.group_name``
        Name of the pool's owning group (if the pool is owned by a group rather 
        than by a user).
    """
    query = SystemPool.query.order_by(SystemPool.name)
    # join User and Group for sorting/filtering and also for eager loading
    query = query\
            .outerjoin(SystemPool.owning_user)\
            .options(contains_eager(SystemPool.owning_user))\
            .outerjoin(SystemPool.owning_group)\
            .options(contains_eager(SystemPool.owning_group))
    json_result = json_collection(query, columns={
        'id': SystemPool.id,
        'name': SystemPool.name,
        'owner.user_name': User.user_name,
        'owner.group_name': Group.group_name,
    })
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template('bkr.server.templates.backgrid', {
        'title': u'Pools',
        'grid_collection_type': 'SystemPools',
        'grid_collection_data': json_result,
        'grid_collection_url': request.path,
        'grid_view_type': 'PoolsView',
        'grid_add_label': 'Create',
        'grid_add_view_type': 'PoolCreateModal' if not identity.current.anonymous else 'null',
    })
Ejemplo n.º 32
0
def get_activity():
    """
    Returns a pageable JSON collection of all activity records in Beaker.
    Refer to :ref:`pageable-json-collections`.

    The following fields are supported for filtering and sorting:

    ``id``
        ID of the activity.
    ``type``
        Type of the activity record. Possible values are: ``system_activity``, 
        ``lab_controller_activity``, ``distro_activity``, 
        ``distro_tree_activity``, ``job_activity``, ``recipeset_activity``, 
        ``recipe_activity``,``user_activity``, ``group_activity``.
    ``service``
        Service through which the action was performed. Usually this is 
        ``XMLRPC``, ``WEBUI``, ``HTTP``, or ``Scheduler``.
    ``created``
        Timestamp at which the activity was recorded.
    ``action``
        Action which was recorded.
    ``field_name``
        Field in the system data which was affected by the action.
    ``old_value``
        Previous value of the field before the action was performed (if applicable).
    ``new_value``
        New value of the field after the action was performed (if applicable).
    """
    query = Activity.query.order_by(Activity.id.desc())
    json_result = json_collection(query,
            columns=common_activity_search_columns,
            skip_count=True)
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template('bkr.server.templates.backgrid', {
        'title': u'Activity',
        'grid_collection_type': 'Activity',
        'grid_collection_data': json_result,
        'grid_collection_url': request.path,
        'grid_view_type': 'ActivityView',
    })
Ejemplo n.º 33
0
def get_lab_controller_activity():
    """
    Returns a pageable JSON collection of all lab controller activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``lab_controller``
        FQDN of the lab controller affected.
    ``lab_controller.fqdn``
        FQDN of the lab controller affected.
    """
    query = LabControllerActivity.query.order_by(LabControllerActivity.id.desc())
    # join LabController for sorting/filtering and also for eager loading
    query = query.join(LabControllerActivity.object).options(contains_eager(LabControllerActivity.object))
    if not request.args.get("q"):
        # need to avoid a filesort due to MySQL picking lab_controller as first table
        query = query.with_hint(
            LabControllerActivity.__table__, "IGNORE INDEX (ix_lab_controller_activity_lab_controller_id)", "mysql"
        )
    json_result = json_collection(
        query,
        columns=dict(
            common_activity_search_columns.items()
            + {"lab_controller": LabController.fqdn, "lab_controller.fqdn": LabController.fqdn}.items()
        ),
    )
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        "bkr.server.templates.backgrid",
        {
            "title": u"Lab Controller Activity",
            "grid_collection_type": "Activity",
            "grid_collection_data": json_result,
            "grid_collection_url": request.path,
            "grid_view_type": "LabControllerActivityView",
        },
    )
Ejemplo n.º 34
0
def get_group_activity():
    """
    Returns a pageable JSON collection of all group activity records.

    Supports the same fields for filtering and sorting as 
    :http:get:`/activity/`, with the following additions:

    ``group``
        Name of the group affected.
    ``group.group_name``
        Name of the group affected.
    """
    query = GroupActivity.query.order_by(GroupActivity.id.desc())
    # join Group for sorting/filtering and also for eager loading
    query = query.join(GroupActivity.object).options(contains_eager(DistroTreeActivity.object))
    if not request.args.get("q"):
        # need to avoid a filesort due to MySQL picking group as first table
        query = query.with_hint(GroupActivity.__table__, "IGNORE INDEX (ix_group_activity_group_id)", "mysql")
    json_result = json_collection(
        query,
        columns=dict(
            common_activity_search_columns.items()
            + {"group": Group.group_name, "group.group_name": Group.group_name}.items()
        ),
    )
    if request_wants_json():
        return jsonify(json_result)
    return render_tg_template(
        "bkr.server.templates.backgrid",
        {
            "title": u"Group Activity",
            "grid_collection_type": "Activity",
            "grid_collection_data": json_result,
            "grid_collection_url": request.path,
            "grid_view_type": "GroupActivityView",
        },
    )