Skip to content

File Output

sat edited this page Jan 3, 2026 · 2 revisions

File Output

This page explains how dot2net generates and controls output files.

Overview

File output in dot2net is controlled by two key concepts:

Concept Role
FileDefinition Defines file properties (name, path, output location)
ConfigTemplate.file Associates a template with a file for output

File Definition

FileDefinitions declare output files with their properties:

file:
  - name: frr.conf
    path: /etc/frr/frr.conf      # Container path (for bind mounts)

  - name: startup
    output: root                  # Output to lab root directory
    name_suffix: .startup         # Results in "r1.startup", "r2.startup"

FileDefinition Fields

Field Description Default
name File identifier (referenced by ConfigTemplate.file) Required
path Target path inside container (used for bind mounts) ""
scope network or node - determines file generation scope node
output root or node - output directory location Inferred from scope
name_prefix Prefix for output filename ""
name_suffix Suffix for output filename ""

Output Location Control

The output field controls where files are placed:

output_directory/
├── topo.yaml              # scope: network (always in root)
├── r1.startup             # scope: node, output: root
├── r2.startup             # scope: node, output: root
├── r1/
│   └── frr.conf           # scope: node, output: node (default)
└── r2/
    └── frr.conf

Examples:

file:
  # Traditional: node config in subdirectory
  - name: frr.conf
    path: /etc/frr/frr.conf
    # output: node (default for node scope)

  # Kathara-style: startup files in root with node name
  - name: startup
    output: root
    name_suffix: .startup
    # Results: r1.startup, r2.startup in root

  # Network-scope file (always in root)
  - name: topo.yaml
    scope: network

Filename Generation

When name_prefix or name_suffix is set, the filename is constructed as:

{name_prefix}{object_name}{name_suffix}
Configuration Object Result
name_suffix: .startup r1 r1.startup
name_prefix: config_ r1 config_r1
name_prefix: init_, name_suffix: .sh r1 init_r1.sh

If neither prefix nor suffix is set, the name field is used as the filename.

ConfigTemplate and File Output

A ConfigTemplate generates output to a file when it has a file attribute:

nodeclass:
  - name: router
    config:
      - name: frr_config
        file: frr.conf           # Output to this file
        template:
          - "hostname {{ .name }}"
          - "!"

File Generation Rules

A file is generated for an object only if:

  1. The object has a ConfigTemplate with matching file attribute
  2. The ConfigTemplate conditions are satisfied (required_params, class conditions, etc.)

This means different nodes can generate different sets of files based on their class configurations.

Bind Mounts (path field)

The path field specifies the target path inside containers. When using modules like Containerlab or TiNET, files with path defined are automatically added to bind mount configurations.

file:
  - name: frr.conf
    path: /etc/frr/frr.conf    # Mounted as: r1/frr.conf:/etc/frr/frr.conf

Only files that a node actually generates (based on class configuration) are included in bind mounts. See Module System for details.

See Also

Clone this wiki locally