#2142 resalloc: add resalloc resources overview page
Closed 2 years ago by schlupov. Opened 2 years ago by schlupov.
copr/ schlupov/copr resalloc_page  into  main

empty or binary file added
file added
+41
@@ -0,0 +1,41 @@ 

+ from flask import Flask, render_template

+ from resallocserver.app import session_scope

+ from resallocserver.logic import QResources

+ from resalloc.helpers import load_config_file

+ 

+ app = Flask(__name__)

+ 

+ 

+ @app.route('/resources')

+ def up():

why "up"?

hmm, maybe "on" is a better word since I use resources.on(), which is all that is not ended

+     with session_scope() as session:

+         resources = QResources(session)

+     pools = load_config_file("/etc/resallocserver/pools.yaml")

+     resources_list = append_resources(resources.on())

+     resources_in_use = {}

+     for resource in resources_list:

+         if not resource["ticket"]:

+             continue

+         if resource["pool"] not in resources_in_use.keys():

+             resources_in_use[resource["pool"]] = 1

+         else:

+             resources_in_use[resource["pool"]] += 1

+     information = {}

+     for name, number in resources_in_use.items():

+         information[name] = {"available": pools[name]["max"] - number, "max": pools[name]["max"],

+                              "ticket": number}

+     return render_template('resources.html', information=information)

+ 

+ 

+ def append_resources(resources):

+     resources_list = []

+     for resource in resources.all():

+         resources_list.append(

+             {'id': resource.id, 'name': resource.name, 'pool': resource.pool, 'tags': ', '.join(list(resource.tag_set)),

+              'status': resource.state, 'releases': resource.releases_counter,

+              'ticket': resource.ticket.id if resource.ticket else None})

+     return resources_list

+ 

+ 

+ if __name__ == '__main__':

+     app.run(host="0.0.0.0")

@@ -0,0 +1,12 @@ 

+ body {

+   margin: 15px;

+ }

+ 

+ .resource {

+   display: grid;

+   grid-template-columns: 1fr 1fr 1fr 1fr;

+   grid-template-rows: auto auto;

+   row-gap: 10px;

+   column-gap: 10px;

+   grid-auto-flow: row;

+ }

@@ -0,0 +1,27 @@ 

+ <!DOCTYPE html>

+ <html lang="en">

+ <head>

+     <meta charset="UTF-8">

+     <meta name="viewport" content="width=device-width, initial-scale=1.0">

+     <title>Resalloc resources</title>

+     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"

+           integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

+     <link rel="stylesheet" href="/static/index.css">

+ </head>

+ <body>

+     <h1 class="resource--title">Resalloc resources</h1>

+     <div class="resource">

+         <div class="card">

+             {% for resource, info in information.items() %}

+                 <div class="card-header text-white" style="background-color: #0057c5;">

+                     {{ resource }}

+                 </div>

+                 <ul class="list-group list-group-flush">

+                     <li class="list-group-item">Max: {{ info.max }}</li>

+                     <li class="list-group-item">Available: {{ info.available }}</li>

+                 <li class="list-group-item">Tickets: {{ info.ticket }}</li>

+                 </ul>

+             {% endfor %}

+         </div>

+     </div>

+ </body>

no initial comment

One table for one pool with 3 information.
I don't know how to get it on the backend.

Build succeeded.

Ah, interesting approach. I thought you would submit this PR against the resalloc project :-)

The feedback to the screenshot -- please try to make it a table, because we have at least a dozen of pools nowadays. Replace the "Ticket" header with "Taken".

Ah, interesting approach. I thought you would submit this PR against the resalloc project :-)

I'm not against making it part of the resalloc package :)

hmm, maybe "on" is a better word since I use resources.on(), which is all that is not ended

hmm, maybe "on" is a better word

I would call it "resources", when the route is "/resources/".

[copr-build] (testing if pagure events under non-root user work)

Pull-Request has been closed by schlupov

2 years ago