Skip to content
Snippets Groups Projects
settings.py 2.93 KiB
Newer Older
""":term:`GSO` settings.
Ensuring that the required parameters are set correctly. An example file ``oss-params-example.json`` is present in the
:term:`GSO` package itself.
import ipaddress
import json
import logging
import os
from pydantic import BaseSettings, NonNegativeInt
logger = logging.getLogger(__name__)

class GeneralParams(BaseSettings):
    """General parameters for a :term:`GSO` configuration file."""
    """The hostname that :term:`GSO` is publicly served at, used for building the callback URL that the provisioning
class CeleryParams(BaseSettings):
    """Parameters for Celery."""

    broker_url: str
    result_backend: str
    timezone: str = "Europe/Amsterdam"
    enable_utc: bool = True
    result_expires: int = 3600


class InfoBloxParams(BaseSettings):
    """Parameters related to InfoBlox."""
    scheme: str
    wapi_version: str
    host: str
    username: str
    password: str


class V4Netmask(NonNegativeInt):
    le = 32


class V6Netmask(NonNegativeInt):
    le = 128


class V4NetworkParams(BaseSettings):
    """A set of parameters that describe an IPv4 network in InfoBlox."""
    containers: list[ipaddress.IPv4Network]


class V6NetworkParams(BaseSettings):
    """A set of parameters that describe an IPv6 network in InfoBlox."""
    containers: list[ipaddress.IPv6Network]


class ServiceNetworkParams(BaseSettings):
    """Parameters for InfoBlox.

    The parameters describe IPv4 and v6 networks, and the corresponding domain name that should be used as a suffix.
    V4: V4NetworkParams
    V6: V6NetworkParams


class IPAMParams(BaseSettings):
    """A set of parameters related to :term:`IPAM`."""
    INFOBLOX: InfoBloxParams
    TRUNK: ServiceNetworkParams
    GEANT_IP: ServiceNetworkParams
    SI: ServiceNetworkParams
    LT_IAS: ServiceNetworkParams
class ProvisioningProxyParams(BaseSettings):
    """Parameters for the provisioning proxy."""
    #:  .. deprecated:: 0.1
    #:     Not used anymore, may be left out from config file.
    auth: str | None
class NetBoxParams(BaseSettings):
    """Parameters for NetBox."""
class OSSParams(BaseSettings):
    """The set of parameters required for running :term:`GSO`."""
    IPAM: IPAMParams
    PROVISIONING_PROXY: ProvisioningProxyParams
    CELERY: CeleryParams


def load_oss_params() -> OSSParams:
    """Look for OSS_PARAMS_FILENAME in the environment and load the parameters from that file."""
    with open(os.environ["OSS_PARAMS_FILENAME"], encoding="utf-8") as file:
        return OSSParams(**json.loads(file.read()))
if __name__ == "__main__":
    logger.debug(load_oss_params())