From 7372f93a6ed1c735d1217f410ddcadf7ed99c9fd Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Fri, 3 Jan 2025 14:20:05 +0100 Subject: [PATCH 1/2] server, webui: add pool descriptions Fix #133 An example description for a builder: aws_x86_64_normalreserved_prod: description: > A pool of reserved x86_64 instances in the Amazon AWS Fedora organization. Thank you IBM for sponsoring these builders. --- resallocserver/manager.py | 1 + resallocwebui/app.py | 9 +++++++++ resallocwebui/templates/pools.html | 2 ++ 3 files changed, 12 insertions(+) diff --git a/resallocserver/manager.py b/resallocserver/manager.py index 353d650..3e6fa1f 100644 --- a/resallocserver/manager.py +++ b/resallocserver/manager.py @@ -465,6 +465,7 @@ def run(self): class Pool(object): + description = None max = 4 max_starting = 1 max_prealloc = 2 diff --git a/resallocwebui/app.py b/resallocwebui/app.py index b025318..6939b2c 100644 --- a/resallocwebui/app.py +++ b/resallocwebui/app.py @@ -3,6 +3,7 @@ from resallocserver.app import session_scope from resallocserver.logic import QResources from resallocserver import models +from resallocserver.manager import reload_config from resalloc.helpers import RState from resallocwebui import staticdir, templatedir @@ -37,12 +38,20 @@ def pools(): # e.g. result["copr_hv_x86_64_01_prod"]["STARTING"] result = {} + _, pools_from_config = reload_config() + # Prepare the two-dimensional array, and fill it with zeros with session_scope() as session: for pool in session.query(models.Pool).all(): result[pool.name] = dict.fromkeys(columns, 0) result[pool.name]["MAX"] = pool.max + if pool.name not in pools_from_config: + continue + + result[pool.name]["DESCRIPTION"] =\ + pools_from_config[pool.name].description + with session_scope() as session: # Iterate over running resources and calculate how many is starting, # deleting, etc. diff --git a/resallocwebui/templates/pools.html b/resallocwebui/templates/pools.html index b03235b..6c2d333 100644 --- a/resallocwebui/templates/pools.html +++ b/resallocwebui/templates/pools.html @@ -12,6 +12,7 @@

Resalloc pools

Pool + Description Max Up Ready @@ -25,6 +26,7 @@

Resalloc pools

{% for pool, info in information.items()|sort(attribute='0') %} {{ pool }} + {{ info['DESCRIPTION'] |default(omit, True) }} {{ info['MAX'] }} {{ info['UP'] }} {{ info['READY'] }} From a6c3c73195716add7daa8bb1f728c0d9eb98b3dd Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Mon, 6 Jan 2025 20:55:32 +0100 Subject: [PATCH 2/2] webui: don't re-use the manager reload_config function It does some logging which causes permission errors, it is misleading because it logs as the manager, etc. --- resallocwebui/app.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/resallocwebui/app.py b/resallocwebui/app.py index 6939b2c..388b1f5 100644 --- a/resallocwebui/app.py +++ b/resallocwebui/app.py @@ -1,9 +1,8 @@ -import os +import yaml from flask import Flask, render_template from resallocserver.app import session_scope from resallocserver.logic import QResources from resallocserver import models -from resallocserver.manager import reload_config from resalloc.helpers import RState from resallocwebui import staticdir, templatedir @@ -12,6 +11,20 @@ app.static_folder = staticdir +def load_config(): + """ + A simpler version of `manager.py:reload_config`. + The `reload_config` function does some logging which causes permission + errors, it is misleading because it logs as the manager, etc. + """ + try: + config_file = "/etc/resallocserver/pools.yaml" + with open(config_file, "r", encoding="utf-8") as fp: + return yaml.safe_load(fp) + except OSError: + return {} + + @app.route("/") def home(): return render_template("home.html", resources=resources) @@ -38,7 +51,7 @@ def pools(): # e.g. result["copr_hv_x86_64_01_prod"]["STARTING"] result = {} - _, pools_from_config = reload_config() + pools_from_config = load_config() # Prepare the two-dimensional array, and fill it with zeros with session_scope() as session: @@ -50,7 +63,7 @@ def pools(): continue result[pool.name]["DESCRIPTION"] =\ - pools_from_config[pool.name].description + pools_from_config[pool.name].get("description") with session_scope() as session: # Iterate over running resources and calculate how many is starting,