174 lines
6.4 KiB
Python
174 lines
6.4 KiB
Python
import json
|
|
from django.shortcuts import render
|
|
|
|
_BASE = {
|
|
"region_name": "ct3k1ldt"
|
|
}
|
|
|
|
def index(request):
|
|
context = {**_BASE,
|
|
# CPU and RAM utilization data
|
|
'cpu_used': 42,
|
|
'cpu_free': 58,
|
|
'cpu_used_percentage': 42.0,
|
|
'ram_used': 128,
|
|
'ram_free': 256,
|
|
'ram_used_percentage': 33.3,
|
|
|
|
# Instance summary data
|
|
'vm_count': 47,
|
|
'vm_active': 42,
|
|
'vm_stopped': 5,
|
|
'vm_error': 0,
|
|
'common_flavor': 'm1.medium',
|
|
'common_flavor_count': 18,
|
|
'second_common_flavor': {
|
|
'name': 'm1.small',
|
|
'count': 12
|
|
},
|
|
'third_common_flavor': {
|
|
'name': 'm1.large',
|
|
'count': 8
|
|
},
|
|
|
|
# Resource allocation data
|
|
'cpu_allocated': 94,
|
|
'cpu_total': 160,
|
|
'cpu_overcommit_ratio': 1.5,
|
|
'ram_allocated': 384,
|
|
'ram_total': 512,
|
|
'ram_overcommit_ratio': 1.2,
|
|
|
|
# Quick stats
|
|
'avg_cpu_per_vm': 2.0,
|
|
'avg_ram_per_vm': 8.2,
|
|
'vm_density': 9.4,
|
|
|
|
# Audit data
|
|
'audits': [
|
|
{
|
|
'id': 'audit_001',
|
|
'name': 'Weekly Optimization',
|
|
'created_at': '2024-01-15',
|
|
'cpu_weight': 1.2,
|
|
'ram_weight': 0.8,
|
|
'scope': 'Full Cluster',
|
|
'strategy': 'Load Balancing',
|
|
'goal': 'Optimize CPU distribution across all hosts',
|
|
'migrations': [
|
|
{
|
|
'instanceName': 'web-server-01',
|
|
'source': 'compute-02',
|
|
'destination': 'compute-05',
|
|
'flavor': 'm1.medium',
|
|
'impact': 'Low'
|
|
},
|
|
{
|
|
'instanceName': 'db-replica-03',
|
|
'source': 'compute-01',
|
|
'destination': 'compute-04',
|
|
'flavor': 'm1.large',
|
|
'impact': 'Medium'
|
|
},
|
|
{
|
|
'instanceName': 'api-gateway',
|
|
'source': 'compute-03',
|
|
'destination': 'compute-06',
|
|
'flavor': 'm1.small',
|
|
'impact': 'Low'
|
|
},
|
|
{
|
|
'instanceName': 'cache-node-02',
|
|
'source': 'compute-01',
|
|
'destination': 'compute-07',
|
|
'flavor': 'm1.small',
|
|
'impact': 'Low'
|
|
},
|
|
{
|
|
'instanceName': 'monitoring-server',
|
|
'source': 'compute-04',
|
|
'destination': 'compute-02',
|
|
'flavor': 'm1.medium',
|
|
'impact': 'Low'
|
|
}
|
|
],
|
|
'host_labels': ['compute-01', 'compute-02', 'compute-03', 'compute-04', 'compute-05', 'compute-06', 'compute-07'],
|
|
'cpu_current': [78, 65, 42, 89, 34, 56, 71],
|
|
'cpu_projected': [65, 58, 45, 72, 48, 61, 68]
|
|
},
|
|
{
|
|
'id': 'audit_002',
|
|
'name': 'Emergency Rebalance',
|
|
'created_at': '2024-01-14',
|
|
'cpu_weight': 1.0,
|
|
'ram_weight': 1.0,
|
|
'scope': 'Overloaded Hosts',
|
|
'strategy': 'Hotspot Reduction',
|
|
'goal': 'Reduce load on compute-01 and compute-04',
|
|
'migrations': [
|
|
{
|
|
'instanceName': 'app-server-02',
|
|
'source': 'compute-01',
|
|
'destination': 'compute-06',
|
|
'flavor': 'm1.medium',
|
|
'impact': 'Medium'
|
|
},
|
|
{
|
|
'instanceName': 'file-server-01',
|
|
'source': 'compute-04',
|
|
'destination': 'compute-07',
|
|
'flavor': 'm1.large',
|
|
'impact': 'High'
|
|
}
|
|
],
|
|
'host_labels': ['compute-01', 'compute-02', 'compute-03', 'compute-04', 'compute-05', 'compute-06', 'compute-07'],
|
|
'cpu_current': [92, 65, 42, 85, 34, 56, 71],
|
|
'cpu_projected': [72, 65, 42, 65, 34, 66, 81]
|
|
},
|
|
{
|
|
'id': 'audit_003',
|
|
'name': 'Pre-Maintenance Planning',
|
|
'created_at': '2024-01-10',
|
|
'cpu_weight': 0.8,
|
|
'ram_weight': 1.5,
|
|
'scope': 'Maintenance Zone',
|
|
'strategy': 'Evacuation',
|
|
'goal': 'Empty compute-03 for maintenance',
|
|
'migrations': [
|
|
{
|
|
'instanceName': 'test-vm-01',
|
|
'source': 'compute-03',
|
|
'destination': 'compute-02',
|
|
'flavor': 'm1.small',
|
|
'impact': 'Low'
|
|
},
|
|
{
|
|
'instanceName': 'dev-server',
|
|
'source': 'compute-03',
|
|
'destination': 'compute-05',
|
|
'flavor': 'm1.medium',
|
|
'impact': 'Low'
|
|
},
|
|
{
|
|
'instanceName': 'staging-db',
|
|
'source': 'compute-03',
|
|
'destination': 'compute-07',
|
|
'flavor': 'm1.large',
|
|
'impact': 'High'
|
|
}
|
|
],
|
|
'host_labels': ['compute-01', 'compute-02', 'compute-03', 'compute-04', 'compute-05', 'compute-06', 'compute-07'],
|
|
'cpu_current': [78, 65, 56, 89, 34, 56, 71],
|
|
'cpu_projected': [78, 75, 0, 89, 54, 56, 81]
|
|
}
|
|
]
|
|
}
|
|
|
|
# Serialize lists for JavaScript
|
|
for audit in context['audits']:
|
|
audit['migrations'] = json.dumps(audit['migrations'])
|
|
audit['host_labels'] = json.dumps(audit['host_labels'])
|
|
audit['cpu_current'] = json.dumps(audit['cpu_current'])
|
|
audit['cpu_projected'] = json.dumps(audit['cpu_projected'])
|
|
|
|
return render(request, 'index.html', context) |