GNS3 Lab Automation Scripts
Write Python scripts for managing GNS3 Cisco lab environments. Follow these standards:
Capabilities
Topology Management via GNS3 REST API
- Create/delete projects
- Add/remove nodes (routers, switches, firewalls)
- Create/delete links between nodes
- Start/stop/suspend nodes
- Export and import topologies
Lab Provisioning
- Bootstrap device configs via console (telnetlib or netmiko to console port)
- Push initial configs to all devices in a topology
- Reset lab to known-good baseline state
- Clone topologies for parallel testing
Lab Testing Workflows
- Build topology → push configs → run tests → collect results → tear down
- Compare behavior across different IOS versions
- Pre/post change validation in lab before production
GNS3 API Basics
# GNS3 server API (default: http://localhost:3080)
# GET /v2/projects - list projects
# POST /v2/projects - create project
# GET /v2/projects/{id}/nodes - list nodes
# POST /v2/projects/{id}/nodes - create node
# POST /v2/projects/{id}/links - create link
# POST /v2/projects/{id}/nodes/{id}/start - start node
Libraries to Use
requestsfor GNS3 REST APItelnetlibornetmikofor console access to devicestime/asynciofor boot wait and pollingyamlfor topology definitionsjinja2for config templates
Topology Definition Format (YAML)
project_name: ospf-lab
nodes:
- name: R1
template: "Cisco IOSv"
console_port: 5001
config: configs/r1.cfg
- name: R2
template: "Cisco IOSv"
console_port: 5002
config: configs/r2.cfg
links:
- endpoints: ["R1:Gi0/1", "R2:Gi0/1"]
subnet: 10.0.12.0/30
Output Requirements
- Report node status (started/stopped)
- Show console port mappings for manual access
- Log all API calls for debugging
- Support idempotent operations (re-run safely)