Mini Shell

Direktori : /opt/bakmgr/lib/python3.6/site-packages/bakmgr/dash/routing/
Upload File :
Current File : //opt/bakmgr/lib/python3.6/site-packages/bakmgr/dash/routing/status.py

from pathlib import Path
from flask import current_app as app
from flask import render_template
from bakmgr.configs import Conf
from bakmgr.server_info import find_bin
from bakmgr.api.bakauth import BakAuthError, get_vded_quota
from bakmgr.dash.dash_helpers import get_reg, iter_dir, login
from bakmgr.api.quotas import SizeCache


@app.route('/status')
@login
def status_page():
    conf = Conf()
    check_conf(conf)
    try:
        reg = get_reg()
        reg_info = f"Registered as {reg['client_host']}"
        quota_mb = get_vded_quota(nocache=True)
        quota_gb = int(quota_mb / 1024)
        size_cache = SizeCache(conf, quota_mb)
    except BakAuthError as exc:
        reg_info = str(exc)
        quota_gb = None
        size_cache = None
    errors = {}
    for err_path in iter_dir(Path('/opt/bakmgr/var/monitoring')):
        try:
            errors[err_path.name] = err_path.read_text('utf-8')
        except FileNotFoundError:
            continue
    return render_template(
        "status.html.jinja",
        conf=conf,
        reg_info=reg_info,
        quota_gb=quota_gb,
        size_cache=size_cache,
        errors=errors,
        page='status',
    )


def check_conf(conf: Conf):
    if conf.mysql.enabled:
        if not find_bin('mysqldump'):
            conf.errors.append(
                "MySQL backups are enabled but the 'mysqldump' "
                "command is missing"
            )
    if conf.pgsql.enabled:
        if not find_bin('pg_dumpall'):
            conf.errors.append(
                "PgSQL backups are enabled but the 'pg_dumpall' "
                "command is missing"
            )
    if conf.files.enabled:
        if not conf.files.include:
            conf.errors.append(
                "File backups are enabled but no paths are included"
            )
        includes_exist = False
        for file in conf.files.include:
            path = Path(file)
            if path.is_absolute():
                if path.exists():
                    includes_exist = True
            else:
                conf.errors.append(f"Included path is not absolute: {path}")
        if not includes_exist:
            conf.errors.append("No included paths for file backups exist")
        for file in conf.files.exclude:
            path = Path(file)
            if not path.is_absolute():
                conf.errors.append(f"Excluded path is not absolute: {path}")

Zerion Mini Shell 1.0