Add DM Sans font integration and enhance dashboard context
- Added DM Sans font to the project, including multiple weights and styles for improved typography. - Updated package.json and package-lock.json to include @fontsource/dm-sans dependency. - Enhanced dashboard context to include current cluster CPU state, integrating new data into the context and API responses. - Updated relevant templates and JavaScript to utilize the new current cluster data for better visualization and user experience.
This commit is contained in:
@@ -8,7 +8,7 @@ from django.shortcuts import render
|
||||
from dashboard.openstack_utils.connect import get_connection
|
||||
from dashboard.openstack_utils.flavor import get_flavor_list
|
||||
from dashboard.prometheus_utils.query import query_prometheus
|
||||
from dashboard.openstack_utils.audits import get_audits
|
||||
from dashboard.openstack_utils.audits import get_audits, get_current_cluster_cpu
|
||||
from dashboard.mock_data import get_mock_context
|
||||
|
||||
# Prometheus queries run in parallel (query_key -> query string)
|
||||
@@ -122,6 +122,11 @@ def collect_context():
|
||||
"flavors": flavors,
|
||||
"audits": audits,
|
||||
}
|
||||
current_cluster = get_current_cluster_cpu(connection)
|
||||
context["current_cluster"] = {
|
||||
"host_labels": json.dumps(current_cluster["host_labels"]),
|
||||
"cpu_current": json.dumps(current_cluster["cpu_current"]),
|
||||
}
|
||||
# Serialize audit list fields for JavaScript so cached context is render-ready
|
||||
for audit in context["audits"]:
|
||||
audit["migrations"] = json.dumps(audit["migrations"])
|
||||
@@ -221,6 +226,10 @@ def _skeleton_context():
|
||||
"vm": {"count": 0, "active": 0, "stopped": 0, "avg_cpu": 0, "avg_ram": 0, "density": 0},
|
||||
"flavors": empty_flavors,
|
||||
"audits": [],
|
||||
"current_cluster": {
|
||||
"host_labels": "[]",
|
||||
"cpu_current": "[]",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -243,10 +252,16 @@ def api_stats(request):
|
||||
|
||||
|
||||
def api_audits(request):
|
||||
cache_key = "dashboard_audits"
|
||||
cache_key_audits = "dashboard_audits"
|
||||
cache_key_cluster = "dashboard_current_cluster"
|
||||
cache_ttl = getattr(settings, "DASHBOARD_CACHE_TTL", 120)
|
||||
audits = cache.get(cache_key)
|
||||
audits = cache.get(cache_key_audits)
|
||||
current_cluster = cache.get(cache_key_cluster)
|
||||
if audits is None:
|
||||
audits = collect_audits()
|
||||
cache.set(cache_key, audits, timeout=cache_ttl)
|
||||
return JsonResponse({"audits": audits})
|
||||
cache.set(cache_key_audits, audits, timeout=cache_ttl)
|
||||
if current_cluster is None:
|
||||
connection = get_connection()
|
||||
current_cluster = get_current_cluster_cpu(connection)
|
||||
cache.set(cache_key_cluster, current_cluster, timeout=cache_ttl)
|
||||
return JsonResponse({"audits": audits, "current_cluster": current_cluster})
|
||||
Reference in New Issue
Block a user