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
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 toolsNNis the next free two-digit number.vz init --exampleaccepts the whole folder name, the number (14) or the part after the number (ospf-triangle).- Every folder with a
lab.yamlis an example. Keep scratch folders out ofexamples/. - Disks the lab creates (
size:withoutoverlay) are written next tolab.yaml. Ignore them with a.gitignorethat lists*.asif.
Conventions
These are the rules from examples/README.md. They let any examples run at the same time.
| Convention | |
|---|---|
| Lab name | The folder name without the number, for example ospf-triangle |
| NAT switch subnet | Lab 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, ... |
| Addresses | The Mac is .1 (vmnet takes the first host). Nodes start at .11 |
| MAC addresses | 52:54:00:NN:<node>:<nic>: node numbers from 01, NIC numbers from 00 |
| DHCP | A reservation for every switch NIC, so the README can name its address before vz up |
mgmt NIC | Every node's first NIC, on the NAT switch: SSH and package downloads. Exercise traffic uses the other NICs |
| Login | lab / 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-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: trueso users can read the boot withvz node logs. - Point disks at
~/.vz/images/...withoverlay: 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-configthat creates thelabuser 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.
version: 2
ethernets:
mgmt:
match: { macaddress: "52:54:00:01:01:00" }
set-name: mgmt
dhcp4: true
dhcp-identifier: macdhcp-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:
#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:
| Section | Content |
|---|---|
# NN Title and one sentence | The same sentence as the lab.yaml header and the index table |
## What you practice | Three or four bullets: the vz features and the networking ideas |
## Topology | A mermaid flowchart LR with the Mac, switches, links and nodes, then a table: Node, Image, CPUs / memory, Addresses, Role |
## Before you start | The exact vz image pull ... commands |
## Run it | cd examples/NN-name, vz validate, vz up, vz node ls, and how to log in |
## Try it | Commands to run, each with a comment that says what to look for |
## Notes | Optional: caveats, how a feature works, what to change |
## Clean up | vz down and vz destroy --yes |
Copy the topology diagram style from an existing lab, for example examples/01-single-vm/README.md:
```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
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 upThen 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.