Skip to content
Snippets Groups Projects
config.py 6.5 KiB
Newer Older
"""
This file loads the configuration used for the dashboard manager.

The config is stored in a JSON format on the filesystem,
with the following schema:

.. asjson::
    brian_dashboard_manager.config.CONFIG_SCHEMA


Some config specific to each organization is hardcoded.
This includes which organizations to provision,
and which dashboards not to provision for each organization:

`excluded_nrens` is a list of strings to search for in interface descriptions
to exclude for that organization.

`excluded_dashboards` is a list of dashboard names to exclude.
These only cover the static dashboards loaded from the file system.

`excluded_folders` covers dynamically generated folders and dashboards.
This property is a mapping of folder name to `True` or a list of dashboards.
A value of `True` should result in that folder being excluded.
If the value is a list, dashboard titles within the list should be excluded.

.. asjson::
    brian_dashboard_manager.config.DEFAULT_ORGANIZATIONS
"""

import json
import jsonschema

STATE_PATH = tempfile.gettempdir() + '/briandashboardmanager-state.json'
DEFAULT_ORGANIZATIONS = [
    {
        "name": "GÉANT Staff",
        "excluded_nrens": [
            "GEANT",
        "excluded_dashboards": [],
        "excluded_folders": {}
    },
    {
        "name": "NRENs",
        "excluded_nrens": [
        "excluded_dashboards": [
            "GÉANT Office devices",
            "GÉANT VM",
            "Lab Devices",
            "EUMETSAT"
        ],
        "excluded_folders": {
            "Aggregates": ["CAE1"],
            "EUMETSAT Multicast": True,
    },
    {
        "name": "General Public",
        "excluded_nrens": [
Bjarke Madsen's avatar
Bjarke Madsen committed
            "PIONIER",
        "excluded_dashboards": [
            "GÉANT Office devices",
            "GÉANT VM",
            "IAS Peers",
            "EUMETSAT"
        ],
        "excluded_folders": {
Bjarke Madsen's avatar
Bjarke Madsen committed
            "Aggregates": ["CAE1", "GWS UPSTREAMS", "IAS PEERS"],
            "IAS CUSTOMER": True,
            "IAS PRIVATE": True,
            "IAS PUBLIC": True,
Bjarke Madsen's avatar
Bjarke Madsen committed
            "IAS UPSTREAM": True,
            "GWS PHY Upstream": True,
            "GWS Direct": True,
            "GWS Indirect": True,
            "EUMETSAT Multicast": True,
            "NREN Access BETA": True
    },
    {
        "name": "CAE1 - Europe",
        "excluded_nrens": [
        "excluded_dashboards": [
            "GÉANT Office devices",
            "GÉANT VM",
            "Lab Devices",
            "EUMETSAT"
        "excluded_folders": {
            "EUMETSAT Multicast": True
    },
    {
        "name": "CAE1 - Asia",
        "excluded_nrens": [
Bjarke Madsen's avatar
Bjarke Madsen committed
            "PIONIER",
        "excluded_dashboards": [
            "GÉANT Office devices",
            "GÉANT VM",
Bjarke Madsen's avatar
Bjarke Madsen committed
            "IAS",
            "IAS Peers",
            "EUMETSAT"
        ],
        "excluded_folders": {
Bjarke Madsen's avatar
Bjarke Madsen committed
            "Aggregates": ["GWS UPSTREAMS", "IAS PEERS"],
            "IAS CUSTOMER": True,
            "IAS PRIVATE": True,
            "IAS PUBLIC": True,
Bjarke Madsen's avatar
Bjarke Madsen committed
            "IAS UPSTREAM": True,
            "EUMETSAT Multicast": True,
            "NREN Access BETA": True
CONFIG_SCHEMA = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "influx-datasource": {
            "type": "object",
            "properties": {
                    "name": {"type": "string"},
                    "username": {"type": "string"},
                    "password": {"type": "string"},
                    "type": {"type": "string"},
                    "url": {"type": "string"},
                    "database": {"type": "string"},
                    "basicAuth": {"type": "boolean"},
                    "access": {"type": "string"},
                    "isDefault": {"type": "boolean"},
                    "readOnly": {"type": "boolean"}
            },
            "required": [
                "name",
                "type",
                "url",
                "database",
                "basicAuth",
                "access",
                "isDefault",
                "readOnly"
            ]
Bjarke Madsen's avatar
Bjarke Madsen committed
        },
        "organization": {
            "type": "object",
            "properties": {
                    "name": {"type": "string"},
                    "excluded_nrens": {
                        "type": "array",
                        "items": {"type": "string"}
                    },
Bjarke Madsen's avatar
Bjarke Madsen committed
            },
            "required": [
                "name",
                "excluded_nrens",
            ]
    "type": "object",
    "properties": {
        "admin_username": {"type": "string"},
        "admin_password": {"type": "string"},
        "hostname": {"type": "string"},
        "listen_port": {"type": "integer"},
Bjarke Madsen's avatar
Bjarke Madsen committed
        "inventory_provider": {"type": "string"},
        "reporting_provider": {"type": "string"},
        "datasources": {
            "type": "object",
            "properties": {
                "influxdb": {"$ref": "#/definitions/influx-datasource"}
            },
            "additionalProperties": False
        },
        "ignored_folders": {
            "type": "array",
            "items": {"type": "string"}
        }
Bjarke Madsen's avatar
Bjarke Madsen committed
    "required": [
        "admin_username",
        "admin_password",
        "hostname",
Bjarke Madsen's avatar
Bjarke Madsen committed
        "inventory_provider",
        "reporting_provider",
        "datasources",
        "ignored_folders"
}


def defaults():
    return {
        "admin_username": "admin",
        "admin_password": "admin",
        "hostname": "localhost:3000",
        "listen_port": 3001,
        "datasources": {},
        "ignored_folders": []
    }


def load(f):
    """
    loads, validates and returns configuration parameters

    :param f: file-like object that produces the config file
    :return:
    """
    config = json.loads(f.read())
    jsonschema.validate(config, CONFIG_SCHEMA)
    return config