A cli util based arround the GN3v3 api
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
GNS3 API Util
A command-line utility for interacting with the GNS3 API, designed especially for setting up educational environments. This tool streamlines common API operations—such as authentication, GET, POST, and DELETE requests—against a GNS3 server, making it easier to automate and manage classes, exercises, users, groups, and more in your network emulation labs.
Table of Contents
Features
- Educational Environment Setup: Easily create and manage classes and exercises for students.
- Interactive CLI: Use fuzzy search and interactive prompts for selecting users, groups, and more.
- Automation: Scriptable for bulk operations and integration into CI/CD or lab provisioning.
- Web-based Class Generator: Launch a local web UI to generate class JSON for bulk student creation.
- Comprehensive API Coverage: Supports most GNS3 v3 API endpoints for GET, POST, DELETE.
- Remote SSL Setup: Install and configure HTTPS (via Caddy reverse proxy) on your GNS3 server remotely over SSH with a single command.
Installation
Using uv (Recommended)
uv is a fast Python package manager and virtual environment tool.
-
Install uv (if not already installed):
pip install uv
-
Create a virtual environment and install gns3util:
uv venv venv source venv/bin/activate uv pip install gns3util
Or, for user installs (no root required):
uv pip install --user gns3util
From PyPI
Install the latest release directly from PyPI:
pip install gns3util
Or, for user installs (no root required):
pip install --user gns3util
From Source
-
Clone the Repository
git clone https://github.com/Stefanistkuhl/gns3-api-util.git cd gns3-api-util
-
(Optional) Create a Virtual Environment
Using uv:
uv venv venv source venv/bin/activate
Or with standard venv:
python -m venv venv source venv/bin/activate
-
Install the Project
pip install -e .
Dependencies
The following Python packages are required and will be installed automatically:
For enhanced interactive selection, you can also install fzf (optional):
# On Ubuntu/Debian
sudo apt install fzf
# Or via Homebrew (macOS/Linux)
brew install fzf
# Or via winget (Windows)
winget install --id=junegunn.fzf
Usage
After installing, the utility can be executed directly from the command line using the entry point gns3util.
Authentication
You can authenticate to the GNS3 server using several methods:
- Flags:
Use--usernameand--password(or-uand-p) to provide credentials directly.gns3util --server http://localhost:3080 --username admin --password secret ...
- Environment Variables:
SetGNS3_USERNAMEandGNS3_PASSWORDin your environment.export GNS3_USERNAME=admin export GNS3_PASSWORD=secret gns3util --server http://localhost:3080 ...
- Standard Input:
If you omit the password, you will be prompted securely for it via stdin.
Running the CLI
At a minimum, provide the --server (or -s) option with the URL of your GNS3 server:
gns3util --server http://<GNS3_SERVER_ADDRESS>
Install HTTPS/SSL on GNS3 Server (Remote)
You can set up HTTPS for your GNS3 server using the built-in install ssl command, which connects to your server via SSH and installs/configures Caddy as a reverse proxy. This enables secure access to your GNS3 server with SSL.
Usage
gns3util --server http://<GNS3_SERVER_ADDRESS> install ssl <user> [OPTIONS]
<user>: The SSH username for the remote server.
Options
-
-p, --port INTEGER
SSH port (default: 22). -
-k, --key PATH
Path to a custom SSH private key file. -
-rp, --reverse-proxy-port INTEGER
Port for the reverse proxy to use (default: 443). -
-gp, --gns3-port INTEGER
Port of the GNS3 Server (default: 3080). -
-d, --domain TEXT
Domain to use for the reverse proxy (default: none). -
-s, --subject TEXT
Subject for the SSL certificate (default:/CN=localhost).
Format:/C=COUNTRY/ST=STATE/L=CITY/O=ORG/OU=UNIT/CN=NAME/emailAddress=EMAIL -
-fa, --firewall-allow TEXT
Allow only a given subnet to access the GNS3 server port (e.g.,10.0.0.0/24).
Requires--firewall-block. -
-fb, --firewall-block
Block all connections to the GNS3 server port except those allowed by--firewall-allow. -
-i, --interactive
Edit all options interactively in your editor before running. -
-v, --verbose
Enable extra logging.
Example
gns3util --server http://10.10.10.10 install ssl ubuntu -k ~/.ssh/id_ed25519 -d mylab.example.com -fa 10.0.0.0/24 -fb
This will:
- Connect to
10.10.10.10as userubuntuusing the specified SSH key. - Set up Caddy as a reverse proxy on port 443 for the GNS3 server on port 3080.
- Use
mylab.example.comas the domain. - Restrict GNS3 server port access to the
10.0.0.0/24subnet.
Interactive Mode
To edit all options in your editor before running:
gns3util --server http://10.10.10.10 install ssl ubuntu --interactive
Script Location
The script that is pushed and executed on the remote server can be found in the source tree at:
src/gns3util/resources/setup_https.sh
You can review or modify this script as needed before running the command.
Requirements & Notes
- The remote user must be
rootor have passwordlesssudoprivileges. - Only works on Linux servers.
- The command will attempt to use SSH keys from
~/.sshor a custom path, and will fall back to password authentication if needed.
Main Commands
The CLI supports several subcommands to interact with the GNS3 API:
- auth: Manage authentication (login, status).
- get: Perform GET requests (list users, groups, projects, etc).
- post: Perform POST requests (create resources, run actions).
- delete: Perform DELETE requests (remove users, groups, projects, etc).
- create: High-level creation commands for classes, exercises, and more.
- add: Add members/resources to groups or pools.
- update: Update resources with new data.
- fuzzy: Interactive fuzzy-finder commands for selecting users/groups.
- stream: Stream notifications from the GNS3 server.
Educational Workflow
1. Create a Class (with Students)
You can launch a local web UI to generate a class JSON and bulk-create students:
gns3util --server http://localhost:3080 create class --create
Or use an existing JSON file:
gns3util --server http://localhost:3080 create class path/to/class.json
2. Exercise Management
Create an exercise for a class:
gns3util --server http://localhost:3080 create exercise <class_name> <exercise_name>
Delete an exercise interactively:
gns3util --server http://localhost:3080 delete exercise
Non-interactive deletion for exercises:
Use the correct flags as defined in the CLI:
-n, --non_interactive <value>: Run the command non-interactively.-c, --set_class <class>: Set the class from which to delete the exercise.-g, --set_group <group>: Set the group from which to delete the exercise.-a, --delete_all: Delete all exercises.
Example:
gns3util --server http://localhost:3080 delete exercise --non_interactive yes --set_class MyClass --set_group MyGroup
Delete all exercises in a class:
gns3util --server http://localhost:3080 delete exercise --set_class MyClass --set_group MyGroup --delete_all
3. Delete a Class or Exercise
Delete a class and all its students interactively:
gns3util --server http://localhost:3080 delete class
Non-interactive deletion:
You can delete a class directly by specifying its name with the --non_interactive flag:
gns3util --server http://localhost:3080 delete class --non_interactive MyClass
Delete all classes:
To delete all classes non-interactively, use the --delete_all flag:
gns3util --server http://localhost:3080 delete class --delete_all
Delete all exercises of a class:
To delete all exercises of a class when deleting the class, use the --delete_exercises flag:
gns3util --server http://localhost:3080 delete class --non_interactive MyClass --delete_exercises
4. Interactive Fuzzy Search
Find users or groups with fuzzy search:
gns3util --server http://localhost:3080 fuzzy user-info
gns3util --server http://localhost:3080 fuzzy group-info
Help
You can view the help text by using the --help option:
gns3util --help
Or for any subcommand:
gns3util <subcommand> --help
This will display usage information and options for each command.
Command Reference
Below is a list of all subcommands grouped by their command groups:
auth (Authentication)
loginstatus
get (GET API endpoints)
versioniou-licensestatisticsmeusersprojectsgroupsrolesprivilegesacl-endpointsacltemplatessymbolsimagesdefault-symbolscomputesappliancespoolsuseruser-groupsprojectproject-statsproject-lockedgroupgroup-membersrolerole-privilegestemplatecomputedocker-imagesvirtualbox-vmsvmware-vmsimages_by_pathsnapshotsappliancepoolpool-resourcesdrawingssymbolacl-rulelinksnodesnodenode-linkslinklink-filtersdrawingusernames-and-idsuai
post (POST API endpoints)
controller reloadcontroller shutdownimage install_imgproject duplicate_templateproject project_closeproject project_openproject project_lockproject project_unlocknode start_nodesnode stop_nodesnode suspend_nodesnode reload_nodesnode nodes_console_resetcompute connect_computeimage upload_imgproject project_importproject project_write_filenode node_isolatenode node_unisolatenode node_console_resetlink reset_linklink stop_link_capturesnapshot snapshot_restoreimage add_applience_versionnode duplicate_nodelink start_link_captureclassexercisecheck_versionuser_authenticate
delete (DELETE API endpoints)
prune_imagesusercomputeprojecttemplateimageaclrolegrouppoolpool_resourcelinknodedrawingrole_privuser_from_groupsnapshotclassexercise
create (High-level creation commands)
usergrouproleacltemplateprojectproject_loadadd_poolcreate_computeqemu_imgnodelink_createdrawing_createsnapshot_createadd_applience_versioncreateproject_node_from_templatedisk_imgnode_fileclassexercise
add (Add resources/members)
group_memberressouce_to_pool
update (Update resources)
iou_licensemeusergroupacltemplateprojectcomputepoolrolerole_privsnodedrawinglinkdisk_image
fuzzy (Interactive fuzzy-finder commands)
user-infouigroup-infogigroup-info-with-usernamesgimuser-info-and-group-membershipuigchpwchange-password
stream (Notification streaming)
notificationsproject-id
install (Remote installation commands)
ssl— Install and configure HTTPS (Caddy reverse proxy) on the remote GNS3 server via SSH.
For more details, see the PyPI page or the GitHub repository.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gns3util-0.7.6.tar.gz.
File metadata
- Download URL: gns3util-0.7.6.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7137da65b7d8d1498bc678f5e55b71cc1abc1cb5ff06d59644436dbb0f268540
|
|
| MD5 |
9567fffdae019eff39186cdfb92c5901
|
|
| BLAKE2b-256 |
4f16b5bb085eb7cc465041c6b35c906350912a02a785200f7cd87c6f917cbdec
|
File details
Details for the file gns3util-0.7.6-py3-none-any.whl.
File metadata
- Download URL: gns3util-0.7.6-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
604f902b83d2b009ba023067a9d72c3bae02c3ecc46564869fa83b33841e72ba
|
|
| MD5 |
55de632a8180c6cd6827608607946e13
|
|
| BLAKE2b-256 |
0596f8033671a1b3b29c7c3ece6ef245dfea280bd0d4accdea29a8a9b6146a09
|