58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
import re
|
|
import sys
|
|
import json
|
|
import ipaddress
|
|
from datetime import datetime, timedelta
|
|
from flask import Blueprint
|
|
from flask import flash
|
|
from flask import current_app
|
|
from flask import g
|
|
from flask import request
|
|
from flask import session
|
|
from flask import render_template
|
|
from flask import redirect
|
|
from flask import url_for
|
|
from werkzeug.exceptions import abort
|
|
|
|
from capsulflask.metrics import durations as metric_durations
|
|
from capsulflask.auth import admin_account_required
|
|
from capsulflask.db import get_model
|
|
from capsulflask.shared import my_exec_info_message
|
|
|
|
bp = Blueprint("admin", __name__, url_prefix="/admin")
|
|
|
|
@bp.route("/")
|
|
@admin_account_required
|
|
def index():
|
|
hosts = get_model().list_hosts_with_networks()
|
|
vms = get_model().all_non_deleted_vms()
|
|
operations = get_model().list_all_operations()
|
|
|
|
display_hosts = []
|
|
|
|
for kv in hosts.items():
|
|
name = kv[0]
|
|
value = kv[1]
|
|
|
|
for network in value['networks']:
|
|
network["network_name"]
|
|
|
|
ipv4_network = ipaddress.ip_network(network["public_ipv4_cidr_block"], False)
|
|
network_start_int = -1
|
|
network_end_int = -1
|
|
i = 0
|
|
for ipv4_address in ipv4_network:
|
|
i += 1
|
|
if i > 2:
|
|
if network_start_int == -1:
|
|
network_start_int = int(ipv4_address)
|
|
|
|
network_end_int = int(ipv4_address)
|
|
|
|
|
|
|
|
display_hosts.append(dict(name=name, last_health_check=value['last_health_check']))
|
|
|
|
|
|
return render_template("admin.html", vms=mappedVms, has_vms=len(vms) > 0, created=created)
|