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', })
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', })
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', })
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
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, })
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", }, )
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, })
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', })
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", }, )
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', })
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', })
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", }, )
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', })
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', })
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', })
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', })
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", }, )
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", }, )