Skip to content
Snippets Groups Projects
Select Git revision
  • 22aa6f7bcd2a1a3f4180bb0ddc587749737fca91
  • develop default
  • master protected
  • async-provision
  • DBOARD3-1252/inventory-api
  • 0.88
  • 0.87
  • 0.86
  • 0.85
  • 0.84
  • 0.83
  • 0.82
  • 0.81
  • 0.80
  • 0.79
  • 0.78
  • 0.77
  • 0.76
  • 0.75
  • 0.74
  • 0.73
  • 0.72
  • 0.71
  • 0.70
  • 0.69
25 results

config.py

Blame
  • config.py 5.84 KiB
    """
    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 = '/tmp/briandashboardmanager-state.json'
    
    DEFAULT_ORGANIZATIONS = [
        {
            "name": "GÉANT Staff",
            "excluded_nrens": [],
            "excluded_dashboards": [],
            "excluded_folders": {}
        },
        {
            "name": "NRENs",
            "excluded_nrens": [
                "CUSTOMER GEANT",
                "GEANT-IT"
            ],
            "excluded_dashboards": [
                "GÉANT Office devices",
                "GÉANT VM",
                "Lab Devices"
            ],
            "excluded_folders": {
                "Aggregates": ["CAE1"]
            }
        },
        {
            "name": "General Public",
            "excluded_nrens": [
                "CARNET",
                "PSNC",
                "PIONIER",
                "CUSTOMER GEANT",
                "GEANT-IT"
            ],
            "excluded_dashboards": [
                "GÉANT Office devices",
                "GÉANT VM",
                "Lab Devices",
                "IAS",
                "IAS Peers"
            ],
            "excluded_folders": {
                "Aggregates": ["CAE1", "GWS UPSTREAMS", "IAS PEERS"],
                "IAS CUSTOMER": True,
                "IAS PRIVATE": True,
                "IAS PUBLIC": True,
                "IAS UPSTREAM": True,
                "GWS PHY Upstream": True,
                "GWS Direct": True,
                "GWS Indirect": True,
            }
        },
        {
            "name": "CAE1 - Europe",
            "excluded_nrens": [
                "CUSTOMER GEANT",
                "GEANT-IT",
                "PSNC",
                "PIONIER",
            ],
            "excluded_dashboards": [
                "GÉANT Office devices",
                "GÉANT VM",
                "Lab Devices",
            ],
            "excluded_folders": {
    
            }
        },
        {
            "name": "CAE1 - Asia",
            "excluded_nrens": [
                "CARNET",
                "PSNC",
                "PIONIER",
                "CUSTOMER GEANT",
                "GEANT-IT"
            ],
            "excluded_dashboards": [
                "GÉANT Office devices",
                "GÉANT VM",
                "Lab Devices",
                "IAS",
                "IAS Peers"
            ],
            "excluded_folders": {
                "Aggregates": ["GWS UPSTREAMS", "IAS PEERS"],
                "IAS CUSTOMER": True,
                "IAS PRIVATE": True,
                "IAS PUBLIC": True,
                "IAS UPSTREAM": True,
                "GWS PHY Upstream": 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"
                ]
            },
            "organization": {
                "type": "object",
                "properties": {
                        "name": {"type": "string"},
                        "excluded_nrens": {
                            "type": "array",
                            "items": {"type": "string"}
                        },
                },
                "required": [
                    "name",
                    "excluded_nrens",
                ]
            }
        },
    
        "type": "object",
        "properties": {
            "admin_username": {"type": "string"},
            "admin_password": {"type": "string"},
            "hostname": {"type": "string"},
            "listen_port": {"type": "integer"},
            "inventory_provider": {"type": "string"},
            "datasources": {
                "type": "object",
                "properties": {
                    "influxdb": {"$ref": "#definitions/influx-datasource"}
                },
                "additionalProperties": False
            },
            "ignored_folders": {
                "type": "array",
                "items": {"type": "string"}
            }
        },
        "required": [
            "admin_username",
            "admin_password",
            "hostname",
            "inventory_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