Define Configuration

In this stage, you define your configuration in Python using the Forge facade API. Because configuration is ordinary Python code, you can apply standard software engineering patterns to keep it clean, reusable, and maintainable.

This page presents common patterns, ordered from the simplest single-script approach to more structured techniques for larger projects. Choose the ones that fit your project’s size and complexity.

The examples demonstrate common patterns. They are not guaranteed to run because the Forge facade API might have evolved since this page was written.

Basic Pattern: Inline Script

The simplest approach is a single Python script that creates facade instances, sets values, and exports the result. This is appropriate for small, self-contained configurations.

from fsp_config_foundation import ExportTool
from ves_socom.facades import (
    ComDaemonFacade,
    CommunicationContextFacade,
    DataIpPortFacade,
    SubnetCommunicationFacade,
    SubnetFacade,
    SubnetServiceDiscoveryFacade,
)

if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    runtime = daemon.runtime

    ctx = CommunicationContextFacade.create()
    runtime.add_communication_context(ctx)

    subnet = SubnetFacade.create(ip_address="127.0.0.1")
    subnet.service_discovery = SubnetServiceDiscoveryFacade.create(
        sd_ip_port=12330,
        sd_multicast_ip_address="224.0.0.17",
    )

    communication = SubnetCommunicationFacade.create()
    communication.add_data_ip_port(
        DataIpPortFacade.create(daemon_context_ref=runtime.get_communication_context_ref(ctx.name))
    )
    subnet.communication = communication

    runtime.add_subnet(subnet)
    ExportTool().export_config_unit(daemon, "./cfg")

Pattern: Named Constants

Hard-coded values scattered across a script are difficult to review and maintain. Extract all project-specific values into named constants at the top of the file. This makes every meaningful value visible in one place and easy to change.

from fsp_config_foundation import ExportTool
from ves_socom.facades import (
    ComDaemonFacade,
    CommunicationContextFacade,
    DataIpPortFacade,
    SubnetCommunicationFacade,
    SubnetFacade,
    SubnetServiceDiscoveryFacade,
)

# Network configuration constants
_SUBNET_IP_ADDRESS = "127.0.0.1"
_SD_IP_PORT = 12330
_SD_MULTICAST_IP_ADDRESS = "224.0.0.17"

if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    runtime = daemon.runtime

    ctx = CommunicationContextFacade.create()
    runtime.add_communication_context(ctx)

    subnet = SubnetFacade.create(ip_address=_SUBNET_IP_ADDRESS)
    subnet.service_discovery = SubnetServiceDiscoveryFacade.create(
        sd_ip_port=_SD_IP_PORT,
        sd_multicast_ip_address=_SD_MULTICAST_IP_ADDRESS,
    )

    communication = SubnetCommunicationFacade.create()
    communication.add_data_ip_port(
        DataIpPortFacade.create(daemon_context_ref=runtime.get_communication_context_ref(ctx.name))
    )
    subnet.communication = communication

    runtime.add_subnet(subnet)
    ExportTool().export_config_unit(daemon, "./cfg")

Pattern: Shared Constants Across Modules

When multiple configuration scripts need the same values (for example, IP addresses shared between a daemon and a user application), define the constants in a separate module and import them.

src/constants.py
# Shared network constants for the project
SUBNET_IP_ADDRESS = "127.0.0.1"
SD_IP_PORT = 12330
SD_MULTICAST_IP_ADDRESS = "224.0.0.17"
src/my_comdaemon.py
from fsp_config_foundation import ExportTool
from ves_socom.facades import (
    ComDaemonFacade,
    CommunicationContextFacade,
    DataIpPortFacade,
    SubnetCommunicationFacade,
    SubnetFacade,
    SubnetServiceDiscoveryFacade,
)
from constants import SUBNET_IP_ADDRESS, SD_IP_PORT, SD_MULTICAST_IP_ADDRESS

if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    runtime = daemon.runtime

    ctx = CommunicationContextFacade.create()
    runtime.add_communication_context(ctx)

    subnet = SubnetFacade.create(ip_address=SUBNET_IP_ADDRESS)
    subnet.service_discovery = SubnetServiceDiscoveryFacade.create(
        sd_ip_port=SD_IP_PORT,
        sd_multicast_ip_address=SD_MULTICAST_IP_ADDRESS,
    )

    communication = SubnetCommunicationFacade.create()
    communication.add_data_ip_port(
        DataIpPortFacade.create(daemon_context_ref=runtime.get_communication_context_ref(ctx.name))
    )
    subnet.communication = communication

    runtime.add_subnet(subnet)
    ExportTool().export_config_unit(daemon, "./cfg")

Any script that imports constants.py will automatically use the updated value when it changes.

Pattern: Factory Functions

If you create the same structure in multiple places—for example, a subnet with a fixed set of defaults—extract it into a factory function. This avoids copy-paste errors and makes the intent of each call explicit.

from fsp_config_foundation import ExportTool
from ves_socom.facades import (
    ComDaemonFacade,
    ComDaemonRuntimeFacade,
    CommunicationContextFacade,
    DataIpPortFacade,
    SubnetCommunicationFacade,
    SubnetFacade,
    SubnetServiceDiscoveryFacade,
)

from constants import SUBNET_IP_ADDRESS, SD_IP_PORT, SD_MULTICAST_IP_ADDRESS


def create_default_subnet(runtime: ComDaemonRuntimeFacade, ctx: CommunicationContextFacade) -> SubnetFacade:
    """Create a subnet with the project's standard network settings."""
    subnet = SubnetFacade.create(ip_address=SUBNET_IP_ADDRESS)
    subnet.service_discovery = SubnetServiceDiscoveryFacade.create(
        sd_ip_port=SD_IP_PORT,
        sd_multicast_ip_address=SD_MULTICAST_IP_ADDRESS,
    )

    communication = SubnetCommunicationFacade.create()
    communication.add_data_ip_port(
        DataIpPortFacade.create(daemon_context_ref=runtime.get_communication_context_ref(ctx.name))
    )
    subnet.communication = communication
    return subnet


if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    runtime = daemon.runtime

    ctx = CommunicationContextFacade.create()
    runtime.add_communication_context(ctx)
    runtime.add_subnet(create_default_subnet(runtime, ctx))
    ExportTool().export_config_unit(daemon, "./cfg")

Pattern: Custom Facade by Inheritance

For larger projects, you may want to create a project-specific facade that encapsulates your team’s conventions and hides configuration details that never change. Subclass the Forge facade and override or extend it.

from fsp_config_foundation import ExportTool
from ves_socom.facades import (
    ComDaemonFacade,
    CommunicationContextFacade,
    DataIpPortFacade,
    SubnetCommunicationFacade,
    SubnetFacade,
    SubnetServiceDiscoveryFacade,
)
from constants import SUBNET_IP_ADDRESS, SD_IP_PORT, SD_MULTICAST_IP_ADDRESS


class ProjectComDaemonFacade(ComDaemonFacade):
    """Project-specific ComDaemon facade with standard network defaults pre-applied."""

    @classmethod
    def create_with_defaults(cls, name: str) -> ComDaemonFacade:
        daemon = cls.create(name)
        runtime = daemon.runtime

        ctx = CommunicationContextFacade.create()
        runtime.add_communication_context(ctx)

        subnet = SubnetFacade.create(ip_address=SUBNET_IP_ADDRESS)
        subnet.service_discovery = SubnetServiceDiscoveryFacade.create(
            sd_ip_port=SD_IP_PORT,
            sd_multicast_ip_address=SD_MULTICAST_IP_ADDRESS,
        )

        communication = SubnetCommunicationFacade.create()
        communication.add_data_ip_port(
            DataIpPortFacade.create(daemon_context_ref=runtime.get_communication_context_ref(ctx.name))
        )
        subnet.communication = communication

        runtime.add_subnet(subnet)
        return daemon


if __name__ == "__main__":
    daemon = ProjectComDaemonFacade.create_with_defaults("my_comdaemon")
    # apply any project-specific overrides here
    ExportTool().export_config_unit(daemon, "./cfg")

Using inheritance keeps individual configuration scripts short and focused on what varies between Configurable Units, while the shared logic lives in one place.

Pattern: Parameterized Scripts

Configuration often differs between build variants (for example, development vs. production) or deployment targets. Rather than maintaining separate scripts, accept parameters at the command line and branch on them.

import argparse
from fsp_config_foundation import ExportTool
from ves_socom.facades import (
    ComDaemonFacade,
    CommunicationContextFacade,
    DataIpPortFacade,
    SubnetCommunicationFacade,
    SubnetFacade,
    SubnetServiceDiscoveryFacade,
)

_NETWORK_PROFILES = {
    "dev":  {"ip": "127.0.0.1",   "sd_port": 12330, "multicast": "224.0.0.17"},
    "prod": {"ip": "192.168.1.10", "sd_port": 30490, "multicast": "239.192.255.250"},
}

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--profile", choices=_NETWORK_PROFILES.keys(), default="dev")
    parser.add_argument("--output", default="./cfg")
    args = parser.parse_args()

    profile = _NETWORK_PROFILES[args.profile]
    daemon = ComDaemonFacade.create("my_comdaemon")
    runtime = daemon.runtime

    ctx = CommunicationContextFacade.create()
    runtime.add_communication_context(ctx)

    subnet = SubnetFacade.create(ip_address=profile["ip"])
    subnet.service_discovery = SubnetServiceDiscoveryFacade.create(
        sd_ip_port=profile["sd_port"],
        sd_multicast_ip_address=profile["multicast"],
    )

    communication = SubnetCommunicationFacade.create()
    communication.add_data_ip_port(
        DataIpPortFacade.create(daemon_context_ref=runtime.get_communication_context_ref(ctx.name))
    )
    subnet.communication = communication

    runtime.add_subnet(subnet)
    ExportTool().export_config_unit(daemon, args.output)

Run it as:

uv run ./src/my_comdaemon.py --profile prod --output ./cfg/prod