Skip to content

gufo.thor.config

Config data structures.

CliConfig dataclass

Config populated during runtime.

Should not be set by user. Populated from CLI options.

Config dataclass

The Gufo Thor config.

Attributes:

Name Type Description
project str | None

Optional project name used to prefix the services and volumes. If not set - directory name is used. Should be unique within Thor projects on same host.

noc NocConfig

The noc section of the config.

expose ExposeConfig

The expose section of the config.

services dict[str, ServiceConfig]

The services section of the config.

labs dict[str, LabConfig]

The labs section of the config.

local_backup_path property

Get the local directory used to store backups.

Returns:

Type Description
Path

Local backup directory path.

apply(other)

Apply settings from another configuration.

Parameters:

Name Type Description Default
other Config

Configuration whose values should be copied to this one.

required

default() staticmethod

Generate default config.

Returns:

Type Description
Config

An Config instance

from_file(path) staticmethod

Read file and return instance of the Config.

Dies if config contains errors.

Parameters:

Name Type Description Default
path Path | str

File path.

required

Returns:

Type Description
Config

Config instance.

from_yaml(data) staticmethod

Parse YAML file and return an instance of the Config.

Dies if config contains errors.

Parameters:

Name Type Description Default
data str

String containing YAML config.

required

Returns:

Type Description
Config

An Config instance.

get_ui_url()

Build the NOC UI URL from the current configuration.

Returns:

Type Description
str

HTTPS URL for the configured NOC web interface.

setup(path=None)

Load configuration from a file into this config instance.

Parameters:

Name Type Description Default
path Path | None

Config file path. Defaults to thor.yml.

None

ExposeConfig dataclass

The expose section of the config.

Attributes:

Name Type Description
domain_name str

A domain name through which the NOC's user interface will be accessed in browser.

web Listen | None

Web listener configuration.

port Listen | None

An HTTPS port of the NOC's user interface (deprecated).

open_browser bool

Open browser on startup.

mtls_ca_cert str | None

When set, enables mTLS and defines CA certificate path, relative to assets

default() staticmethod

Get default ExposeConfig.

Returns:

Type Description
ExposeConfig

ExposeConfig instance.

from_dict(data) staticmethod

Generate ExposeConfig instance from a dictionary.

Parameters:

Name Type Description Default
data dict[str, Any]

Incoming data.

required

Returns:

Type Description
ExposeConfig

A configured ExposeConfig instance.

IsisLinkProtocolConfig dataclass

ISIS protocol configuration for link.

from_dict(data) staticmethod

Generate IsisLinkProtocolConfig from dict.

Parameters:

Name Type Description Default
data dict[str, Any]

Incoming data.

required

Returns:

Type Description
IsisLinkProtocolConfig

IsisLinkProtocolConfig instance.

LabConfig dataclass

The labs section of the config.

Attributes:

Name Type Description
name str

lab name.

nodes dict[str, LabNodeConfig]

Nodes configuration.

pool str | None

Lab pool.

check()

Check config.

from_dict(name, data) staticmethod

Generate LabConfig instance from a dictionary.

Parameters:

Name Type Description Default
name str

Lab name.

required
data dict[str, Any]

Incoming data.

required

Returns:

Type Description
LabConfig

A configured LabConfig instance.

LabLinkConfig dataclass

Link item.

from_dict(data) staticmethod

Create link item from config.

LabNodeConfig dataclass

The labs.nodes section of config.

from_dict(name, data) staticmethod

Generate LabNodeConfig from dict.

Parameters:

Name Type Description Default
name str

Node name.

required
data dict[str, str | None]

Incoming data.

required

Returns:

Type Description
LabNodeConfig

LabNodeConfig instance.

LabNodeSnmpV2cCredentials dataclass

Bases: TypedDict

SNMP v2c Credentials.

LabNodeUserCredentials dataclass

User credentials.

Attributes:

Name Type Description
user str

Local user name.

password str

Plain-text password.

from_dict(data) staticmethod

Get user credentials from dict.

LinkProtocolConfig

Bases: TypedDict

Protocol settings.

Listen dataclass

Listener configuration.

Used to proxy host's ports into the container.

Accepts formats:

* <port>
* "<port>"
* "<address>:<port>"
* {"port": <port>}
* {"address": "<address>", "port": <port>}

Attributes:

Name Type Description
address str

Listen address.

port int

Listen port.

__str__()

str() implementation.

default() classmethod

Default value.

docker_compose_port(container_port)

Generate configuration for port forwarding.

Parameters:

Name Type Description Default
container_port int

Port in the container.

required

Returns:

Type Description
str

Port configuration for docker compose.

from_dict(data) staticmethod

Generate listener from data.

Parameters:

Name Type Description Default
data dict[str, Any] | int | str

Incoming data.

required

Returns:

Type Description
Listen

A configured Listener instance.

NocConfig dataclass

The noc section of the config.

Attributes:

Name Type Description
version str

NOC version.

tag str | None

Optional NOC image tag

path str | None

An optional path to the NOC source code. If not empty, image's /opt/noc will be replaced with.

ui_path str | None

An optional path to the compiled UI. If not empty, web image's /opt/noc/src/noc/ui will be replaced with.

custom str | None

Optional path to the custom, will be mounted in the /opt/noc_custom directory.

installation_name str

The installation name which will be shown in the interface.

theme Literal['noc', 'gray']

Web interface theme. One of: noc, gray.

language Literal['en', 'ru']

Web interface language.

migrate bool

Run migrations on start

config dict[str, Any] | None

User-defined config.

default() staticmethod

Get default NocConfig.

Returns:

Type Description
NocConfig

NocConfig instance.

from_dict(data) staticmethod

Generate NocConfig instance from a dictionary.

Parameters:

Name Type Description Default
data dict[str, Any]

Incoming data.

required

Returns:

Type Description
NocConfig

A configured NocConfig instance.

PoolAddressConfig dataclass

Pool addresses configuration.

Attributes:

Name Type Description
gw IPv4Address | None

Gateway address for pool-gw.

syslog IPv4Address | None

Syslog collector address.

trap IPv4Address | None

SNMP trap address.

from_dict(data) staticmethod

Get addresses config from dict.

iter_used()

Iterate all used addresses.

PoolConfig dataclass

The pools section of config.

Attributes:

Name Type Description
name str

Pool name.

subnet IPv4Prefix

Allocated subnet.

from_dict(name, data) staticmethod

Generate PoolConfig instance from a dictionary.

Parameters:

Name Type Description Default
name str

Pool name.

required
data dict[str, Any]

Incoming data.

required

Returns:

Type Description
PoolConfig

A configured PoolConfig instance.

ServiceConfig dataclass

The services section of the config.

Attributes:

Name Type Description
tag str | None

Override noc.tag setting for a service if not empty.

scale int

Number of concurrently running servers. 0 - disable.

default() staticmethod

Get default ServiceConfig.

from_dict(data) staticmethod

Generate ServiceConfig instance from a dictionary.

Parameters:

Name Type Description Default
data dict[str, Any]

Incoming data.

required

Returns:

Type Description
ServiceConfig

A configured ServiceConfig instance.

get_sample(name)

Get preconfigured config sample by name.

All samples are preserved in templates/samples directory.

Parameters:

Name Type Description Default
name str

Sample name, without .yml extension.

required

Returns:

Type Description
str

A string containinng sample code.

with_config(cfg)

Temporarily replace the global configuration for testing.

This is a test helper intended to override the global configuration within a context and restore the previous configuration afterwards.

Parameters:

Name Type Description Default
cfg Config

Configuration to use within the context.

required

Yields:

Type Description
Config

The temporarily active configuration.