Skip to content

Commit

Permalink
fix: visuals links and template rendering for index
Browse files Browse the repository at this point in the history
Change-Id: I92a8baf3b16b1cfbf769b7f56d4878e819712bf9
  • Loading branch information
grafuls committed Sep 26, 2024
1 parent 28613db commit 9cca8e9
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 55 deletions.
8 changes: 4 additions & 4 deletions cron/quads
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ SHELL=/bin/bash
# * * * * * ( echo "=== Move and Rebuild == @ " $(date) ; flock -n /tmp/moveandrebuild.lock -c "podman exec quads quads --move-hosts" ) 1>>/var/log/move-and-rebuild.log 2>&1
# * * * * * ( echo "=== Validating == @ " $(date) ; flock -n /tmp/validateenv.lock -c "podman exec quads quads --validate-env" ) 1>/dev/null 2>&1
# 0 0 * * * ( echo "=== Sending Notifications == @ " $(date) ; flock -n /tmp/notify.lock -c "podman exec quads quads --notify" ) 1>/dev/null 2>&1
# 0 0 * * * ( echo "=== Regenerate Heat Map == @ " $(date) ; flock -n /tmp/simpletableweb.lock -c "podman exec quads quads --regen-heatmap" ) 1>/dev/null 2>&1
# * * * * * ( echo "=== Rebuild Instackenv == @ " $(date) ; flock -n /tmp/makeinstackenv.lock -c "podman exec quads quads --regen-instack" ) 1>/dev/null 2>&1
# 0 0 * * * ( echo "=== Regenerate Heat Map == @ " $(date) ; flock -n /tmp/heatmap.lock -c "podman exec quads quads --regen-heatmap" ) 1>/dev/null 2>&1
# * * * * * ( echo "=== Rebuild Instackenv == @ " $(date) ; flock -n /tmp/instackenv.lock -c "podman exec quads quads --regen-instack" ) 1>/dev/null 2>&1
# 0 */3 * * 1-6 ( echo "=== Foreman RBAC == @ " $(date) ; flock -n /tmp/foremanrbac.lock -c "podman exec quads quads --foreman-rbac" ) 1>/dev/null 2>&1
#########################################
##### (RECOMMENDED)
Expand All @@ -38,8 +38,8 @@ SHELL=/bin/bash
#*/5 * * * * ( echo "=== Move and Rebuild == @ " $(date) ; flock -n /tmp/moveandrebuild.lock -c "quads --move-hosts" ) 1>>/var/log/move-and-rebuild.log 2>&1
#*/25 * * * * ( echo "=== Validating == @ " $(date) ; flock -n /tmp/validateenv.lock -c "quads --validate-env" ) 1>>/var/log/validate-env.log 2>&1
#*/10 * * * * ( echo "=== Sending Notifications == @ " $(date) ; flock -n /tmp/notify.lock -c "quads --notify" ) 1>>/var/log/quads-notify.log 2>&1
#*/20 * * * * ( echo "=== Regenerate Heat Map == @ " $(date) ; flock -n /tmp/simpletableweb.lock -c "quads --regen-heatmap" ) 1>/dev/null 2>&1
#*/15 * * * * ( echo "=== Rebuild Instackenv == @ " $(date) ; flock -n /tmp/makeinstackenv.lock -c "quads --regen-instack" ) 1>/dev/null 2>&1
#*/20 * * * * ( echo "=== Regenerate Heat Map == @ " $(date) ; flock -n /tmp/heatmap.lock -c "quads --regen-heatmap" ) 1>/dev/null 2>&1
#*/15 * * * * ( echo "=== Rebuild Instackenv == @ " $(date) ; flock -n /tmp/instackenv.lock -c "quads --regen-instack" ) 1>/dev/null 2>&1
#0 */3 * * 1-6 ( echo "=== Foreman RBAC == @ " $(date) ; flock -n /tmp/foremanrbac.lock -c "quads --foreman-rbac" ) 1>/dev/null 2>&1
########################################
########################################
Binary file modified image/quads-architecture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 9 additions & 36 deletions src/quads/web/app.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import asyncio
import os
import re

from datetime import datetime, time

from flask import Flask, abort, g, jsonify, redirect, render_template, request, url_for
from flask import Flask, g, jsonify, redirect, render_template, request, url_for

from quads.config import Config
from quads.quads_api import APIBadRequest, APIServerException
from quads.quads_api import QuadsApi as Quads
from quads.tools.external.foreman import Foreman
from quads.web.blueprints.dynamic_content import dynamic_content_bp
from quads.web.blueprints.instack import instack_bp
from quads.web.blueprints.visual import visual_bp
from quads.web.controller.CloudOperations import CloudOperations
from quads.web.forms import ModelSearchForm

flask_app = Flask(__name__)
flask_app.url_map.strict_slashes = False
flask_app.secret_key = "flask rocks!"
flask_app.register_blueprint(dynamic_content_bp)
flask_app.register_blueprint(visual_bp, url_prefix="/visual")
flask_app.register_blueprint(instack_bp, url_prefix="/instack")

quads = Quads(Config)
loop = asyncio.new_event_loop()
Expand Down Expand Up @@ -58,7 +63,7 @@ def get_dynamic_navigation():
for link in links:
ln = link["text"]
try:
lnum = int(ln.split()[0])
int(ln.split()[0])
numbered_links.append(link)
except:
unnumbered_links.append(link)
Expand All @@ -80,7 +85,7 @@ def get_dynamic_navigation():
unnumbered_submenus = []
for sm in submenus:
try:
sm_num = int(sm.split("_")[0])
int(sm.split("_")[0])
numbered_submenus.append(sm)
except:
unnumbered_submenus.append(sm)
Expand Down Expand Up @@ -130,14 +135,13 @@ def get_dynamic_navigation():
for sl in sub_links:
sl_name = sl["text"]
try:
sl_num = int(sl_name.split()[0])
int(sl_name.split()[0])
numbered_sub_links.append(sl)
except:
unnumbered_sub_links.append(sl)

sorted_numbered_sub_links = sorted(numbered_sub_links, key=lambda x: x["text"])
sorted_unnumbered_sub_links = sorted(unnumbered_sub_links, key=lambda x: x["text"])
stripped_numbered_sub_links = []

for sl in sorted_numbered_sub_links:
sl["text"] = " ".join(sl["text"].split()[1:])
Expand Down Expand Up @@ -303,37 +307,6 @@ def create_vlans():
return render_template("wiki/vlans.html", vlans=vlans)


@flask_app.route("/visual/<when>")
def visuals(when):
path = os.path.join(WEB_CONTENT_PATH, "visual")
file_paths = get_file_paths(path)
print(file_paths)
for file in file_paths:
if when in file:
return render_template(file)
return abort(404)


@flask_app.route("/instack/<host>")
def instack(host):
path = os.path.join(WEB_CONTENT_PATH, "instack")
file_paths = get_file_paths(path)
for file in file_paths:
if host in file:
return render_template(file)
return abort(404)


def get_file_paths(web_path: str = WEB_CONTENT_PATH):
file_paths = []
for root, dirs, files in os.walk(web_path):
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS]
for file in files:
file_path = os.path.join(root, file)
file_paths.append(file_path)
return file_paths


if __name__ == "__main__":
flask_app.debug = True
flask_app.run(host="0.0.0.0", port=5001)
15 changes: 15 additions & 0 deletions src/quads/web/blueprints/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

from quads.config import Config

WEB_CONTENT_PATH = Config.get("web_content_path")
EXCLUDE_DIRS = Config.get("web_exclude_dirs")


def get_file_paths(web_path: str = WEB_CONTENT_PATH):
file_paths = []
for root, dirs, files in os.walk(web_path):
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS]
for file in files:
file_paths.append(file)
return file_paths
13 changes: 1 addition & 12 deletions src/quads/web/blueprints/dynamic_content.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os

from flask import Blueprint, abort, render_template
from quads.config import Config

WEB_CONTENT_PATH = Config.get("web_content_path")
EXCLUDE_DIRS = Config.get("web_exclude_dirs")
from quads.web.blueprints.common import WEB_CONTENT_PATH, get_file_paths

STATIC_DIR = os.path.join(WEB_CONTENT_PATH, "static")
dynamic_content_bp = Blueprint(
Expand Down Expand Up @@ -32,12 +30,3 @@ def dynamic_content_sub(directory, page):
if page in file:
return render_template(os.path.join(directory, file))
return abort(404)


def get_file_paths(web_path: str = WEB_CONTENT_PATH):
file_paths = []
for root, dirs, files in os.walk(web_path):
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS]
for file in files:
file_paths.append(file)
return file_paths
22 changes: 22 additions & 0 deletions src/quads/web/blueprints/instack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from flask import Blueprint, abort, render_template

from quads.web.blueprints.common import WEB_CONTENT_PATH, get_file_paths

TEMPLATE_DIR = os.path.join(WEB_CONTENT_PATH, "instack")
instack_bp = Blueprint(
"instack",
__name__,
template_folder=TEMPLATE_DIR,
)


@instack_bp.route("/<cloud>")
def instack(cloud):
path = os.path.join(WEB_CONTENT_PATH, "instack")
file_paths = get_file_paths(path)
for file in file_paths:
if cloud in file:
return render_template(file)
return abort(404)
30 changes: 30 additions & 0 deletions src/quads/web/blueprints/visual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

from flask import Blueprint, abort, render_template

from quads.web.blueprints.common import WEB_CONTENT_PATH, get_file_paths

TEMPLATE_DIR = os.path.join(WEB_CONTENT_PATH, "visual")
visual_bp = Blueprint(
"visual",
__name__,
template_folder=TEMPLATE_DIR,
)


@visual_bp.route("/")
def index():
try:
return render_template("index.html")
except Exception as e:
return str(e), 500


@visual_bp.route("/<when>")
def visuals(when):
path = os.path.join(WEB_CONTENT_PATH, "visual")
file_paths = get_file_paths(path)
for file in file_paths:
if when in file:
return render_template(file)
return abort(404)
6 changes: 3 additions & 3 deletions src/quads/web/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
>Visualizations</a>
<ul class="dropdown-menu" aria-labelledby="visualizationsDropdown">
<li>
<a class="dropdown-item" href="{{ url_for("visuals", when="current") }}">Current Month Visualization Map</a>
<a class="dropdown-item" href="{{ url_for("visual.visuals", when="current") }}">Current Month Visualization Map</a>
</li>
<li>
<a class="dropdown-item" href="{{ url_for("visuals", when="next") }}">Next Month Visualization Map</a>
<a class="dropdown-item" href="{{ url_for("visual.visuals", when="next") }}">Next Month Visualization Map</a>
</li>
<li>
<a class="dropdown-item" href="{{ url_for("visuals", when="current") }}">All Month Visualization Map</a>
<a class="dropdown-item" href="{{ url_for("visual.index") }}">All Month Visualization Map</a>
</li>
</ul>
</li>
Expand Down

0 comments on commit 9cca8e9

Please sign in to comment.