Skip to content

Writing examples ​

How to add a lab to examples/ so it looks and works like the other thirty. Examples are documentation that runs: users copy them with vz init --example, and they ship inside every release.

Folder layout ​

text
examples/NN-short-name/
├── lab.yaml
├── README.md
├── init/
│   └── <node>/
│       ├── user-data
│       └── network-config
├── .gitignore          # only when the lab creates disk files: *.asif
└── ansible/ terraform/ k8s/ ...   # only when the lab uses those tools
  • NN is the next free two-digit number. vz init --example accepts the whole folder name, the number (14) or the part after the number (ospf-triangle).
  • Every folder with a lab.yaml is an example. Keep scratch folders out of examples/.
  • Disks the lab creates (size: without overlay) are written next to lab.yaml. Ignore them with a .gitignore that lists *.asif.

Conventions ​

These are the rules from examples/README.md. They let any examples run at the same time.

Convention
Lab nameThe folder name without the number, for example ospf-triangle
NAT switch subnetLab NN uses 10.(100+NN).0.0/24, for example lab 14 uses 10.114.0.0/24. Extra switches use 10.(100+NN).1.0/24, .2.0/24, ...
AddressesThe Mac is .1 (vmnet takes the first host). Nodes start at .11
MAC addresses52:54:00:NN:<node>:<nic>: node numbers from 01, NIC numbers from 00
DHCPA reservation for every switch NIC, so the README can name its address before vz up
mgmt NICEvery node's first NIC, on the NAT switch: SSH and package downloads. Exercise traffic uses the other NICs
Loginlab / lab on the console and over SSH, with passwordless sudo
Disk~/.vz/images/debian-13-genericcloud-arm64.raw with overlay: true, unless the lab is about something else. debian-13-generic-arm64.raw when it needs a display or VirtioFS

lab.yaml ​

Start with the schema modeline and a two-line header:

yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/rayanparsa/vz/refs/heads/main/schema/27.json
# 12 Point-to-point link: Two VMs joined by a cable: no switch, no Mac in the path, every frame passes unchanged.
# See README.md in this folder.
schemaVersion: 27
name: point-to-point-link

nodes:
  - name: a
    cpus: 1
    memory: 1GiB
    consoleLog: true
    disks:
      - { path: ~/.vz/images/debian-13-genericcloud-arm64.raw, overlay: true }
    init: ./init/a
    interfaces:
      - { name: mgmt, attach: switch/mgmt, mac: "52:54:00:12:01:00" }
      - { name: p2p, attach: link/a-b, mac: "52:54:00:12:01:01" }
  • Use the flow style ({ ... }) for disks, interfaces and reservations, as the other examples do.
  • Quote MAC addresses.
  • Set consoleLog: true so users can read the boot with vz node logs.
  • Point disks at ~/.vz/images/... with overlay: true, so the base image is never written to.

Cloud-init seeds ​

Each node has init: ./init/<node>, a folder with:

  • user-data: a #cloud-config that creates the lab user and installs what the lab needs.
  • network-config: netplan v2 that matches each NIC by MAC and names it after the lab file's interface.
yaml
version: 2
ethernets:
  mgmt:
    match: { macaddress: "52:54:00:01:01:00" }
    set-name: mgmt
    dhcp4: true
    dhcp-identifier: mac

dhcp-identifier: mac makes the guest's DHCP client id its MAC, so vmnet's reservation applies. vz writes meta-data itself (instance-id and hostname) when the folder has none. See Cloud-init.

Start the user-data header with the lab and node, and say the password is for a local lab only:

yaml
#cloud-config
# 01 Single VM: node vm1.
# Login on the console and over SSH: lab / lab. Fine for a local lab only.

README.md ​

Every example README has these sections, in this order:

SectionContent
# NN Title and one sentenceThe same sentence as the lab.yaml header and the index table
## What you practiceThree or four bullets: the vz features and the networking ideas
## TopologyA mermaid flowchart LR with the Mac, switches, links and nodes, then a table: Node, Image, CPUs / memory, Addresses, Role
## Before you startThe exact vz image pull ... commands
## Run itcd examples/NN-name, vz validate, vz up, vz node ls, and how to log in
## Try itCommands to run, each with a comment that says what to look for
## NotesOptional: caveats, how a feature works, what to change
## Clean upvz down and vz destroy --yes

Copy the topology diagram style from an existing lab, for example examples/01-single-vm/README.md:

markdown
```mermaid
flowchart LR
    mac(["Mac"])
    sw_mgmt{{"switch mgmt<br/>10.101.0.0/24<br/>NAT to the internet"}}
    mac --- sw_mgmt
    n_vm1["vm1<br/>Your first VM"]
    sw_mgmt ---|"mgmt 10.101.0.11"| n_vm1
```

TIP

If first boot installs packages, say so in "Run it" ("give it a minute or two after vz up returns"). It is the most common reason a new user thinks a lab is broken.

Add it to the index ​

Add a row to the matching section table in examples/README.md: link, the one-sentence description, the node count and any outside tools (Ansible, Terraform, kubectl).

Check it ​

bash
make schema-check                     # every example against the JSON Schema
cd examples/NN-short-name
../../.build/debug/vz validate    # semantic rules, no warnings ideally
../../.build/debug/vz up

Then follow your own README from top to bottom on a clean state (vz destroy --yes first). Every command in "Try it" should do what its comment says.

WARNING

Examples ship in releases. Never commit real keys or passwords. The SSH keys under examples/*/ansible/ are throwaway lab keys, and must stay that way.

See also ​