Metadata-Version: 2.4
Name: gns3ctl
Version: 0.1.5
Summary: CLI for controlling a GNS3 server — projects, nodes, links, templates — via the GNS3 REST API
Author-email: Jakob Holst <code@jakobholst.dk>
License: MIT
Project-URL: Homepage, https://gitlab.com/jakobholst/gns3ctl
Project-URL: Repository, https://gitlab.com/jakobholst/gns3ctl
Keywords: gns3,network,simulator,cli,automation,rest,api
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Networking
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28
Requires-Dist: pyyaml>=6.0

# gns3ctl

`gns3ctl` drives a [GNS3](https://www.gns3.com/) server from the command
line via its REST API. It covers the day-to-day things you'd otherwise
have to click through in the GUI: list / open / close projects, see
and operate on nodes (start / stop / reload / suspend), inspect links,
templates and computes.

| Command            | Purpose                                                          |
|--------------------|------------------------------------------------------------------|
| `gns3ctl`          | Main CLI with subcommands (projects, nodes, links, …)            |
| `gns3ctl-setup`    | Interactive first-run: writes `GNS3_*` exports to your shell rc  |

## Install

```bash
pip install gns3ctl
```

## Configure

### Quickest: `gns3ctl-setup`

```bash
gns3ctl-setup
```

Prompts for URL, user, password, default project; writes an idempotent
export block into `~/.zshrc` / `~/.bashrc` / `~/.bash_profile`.

### Env vars

| Variable                | Meaning                                                |
|-------------------------|--------------------------------------------------------|
| `GNS3_URL`              | Base URL, e.g. `http://localhost:3080`                 |
| `GNS3_USER`             | Basic-auth username (omit for open servers)            |
| `GNS3_PASSWORD`         | Basic-auth password                                    |
| `GNS3_API_VERSION`      | `v3` (default; JWT bearer) or `v2` (HTTP Basic Auth)   |
| `GNS3_VERIFY_SSL`       | `false` to skip TLS verification                       |
| `GNS3_DEFAULT_PROJECT`  | Id or name used when `--project` is omitted            |

### YAML (fallback)

A stub is written to `~/.local/etc/gns3ctl/config.yaml` on first run if
`GNS3_URL` isn't exported. Env vars always win.

## Usage

```bash
# Test credentials (defaults to admin/admin if unset)
gns3ctl login test

# Server info
gns3ctl version

# Projects
gns3ctl projects list
gns3ctl projects open  my-lab
gns3ctl projects close my-lab

# Nodes (requires a project — --project or GNS3_DEFAULT_PROJECT)
gns3ctl --project my-lab nodes list
gns3ctl --project my-lab nodes start R1
gns3ctl --project my-lab nodes stop  --all
gns3ctl --project my-lab nodes reload R1
gns3ctl --project my-lab nodes suspend R1

# Links / templates / computes
gns3ctl --project my-lab links list
gns3ctl templates list
gns3ctl computes list

# JSON output, overriding the server URL
gns3ctl --url http://gns3.lab:3080 --json projects list

# Self-signed GNS3 server
gns3ctl --insecure projects list

# Dry-run: print the curl command(s) instead of hitting the server.
# For v3 it emits the token-exchange recipe plus the actual call(s):
gns3ctl --curl --project my-lab nodes start R1
#   # GNS3 v3 uses JWT bearer tokens — fetch one first:
#   TOKEN=$(curl -s -X POST -H 'Content-Type: application/json' \
#     -d '{"username":"admin","password":"admin"}' \
#     http://localhost:3080/v3/access/users/authenticate | jq -r .access_token)
#   # then:
#   curl -X POST -H "Authorization: Bearer $TOKEN" \
#     http://localhost:3080/v3/projects/my-lab/nodes/R1/start

## Auth

GNS3 2.x uses HTTP Basic Auth (what `curl -u user:pass` sends).
GNS3 3.x uses a JWT bearer token — `gns3ctl` POSTs username/password to
`/v3/access/users/authenticate` and uses the returned `access_token`
as `Authorization: Bearer …` on subsequent calls. Defaults are
`admin / admin` and `v3`; override with env vars.
```

Project and node refs accept either the id or the name — `gns3ctl`
resolves the name against `GET /projects` or `GET /nodes` and uses the
id for the subsequent call.

## Exit codes

| Code | Meaning                                              |
|------|------------------------------------------------------|
| 0    | Success                                              |
| 1    | GNS3 server returned an error (auth, 4xx, 5xx, etc.) |
| 2    | Usage / configuration problem                        |

## License

MIT
