Skip to content

tmunzer/mist_library

mist_library

Utilities and example Python scripts that use the Mist Cloud APIs (via the mistapi package) to automate configuration, backups, imports and reporting for Mist organizations and sites.

This repository collects small, focused scripts that are ready to run and easy to adapt for your environment.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Highlights

  • Collection of scripts for: configuration, EVPN, device operations, org/site backups & restores, imports, and reports.
  • Uses the mistapi Python package for authentication and API calls.
  • Scripts accept an environment file or interactive credentials and support dry-run modes where applicable.

Quick start

Prerequisites:

  • Python 3.8+ (recommend 3.9+)
  • A Mist API token or username/password with appropriate privileges
  • Repository checked out locally

Install dependencies (recommended in a virtualenv):

python -m pip install -r requirements.txt

Run a script example (prints help):

python scripts/orgs/org_conf_deploy.py -h

Or run with a specific environment file:

python scripts/orgs/org_conf_deploy.py -e my_env_file

Environment file

You can store credentials and common options in an environment file. By default the scripts look for ~/.mist_env (scripts commonly use ENV_FILE = "~/.mist_env") but you can pass -e /path/to/env to use a different file.

Authoritative env vars:

  • MIST_HOST — Mist API host (for example api.mist.com).
  • MIST_APITOKEN — API token (preferred authentication).
  • MIST_USER / MIST_PASSWORD — username / password fallback when no token is provided.
  • MIST_VAULT_MOUNT_POINT, MIST_VAULT_PATH, MIST_VAULT_TOKEN, MIST_VAULT_URL — Vault integration variables used by mistapi when retrieving secrets from a HashiCorp Vault instance.
  • CONSOLE_LOG_LEVEL, LOGGING_LOG_LEVEL — optional numeric logging levels used in several scripts (not required by mistapi itself, but useful to control verbosity).

If no credentials are present in the env file, most scripts will prompt interactively for missing values or fall back to the mistapi login flow.

Example ~/.mist_env (minimal):

# Required: set either MIST_APITOKEN or the user/password pair
MIST_HOST=api.mist.com
MIST_APITOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Or, alternatively:
# MIST_USER=your.username@example.com
# MIST_PASSWORD=yourpassword

# Optional logging controls used by some scripts
CONSOLE_LOG_LEVEL=20
LOGGING_LOG_LEVEL=10

# Optional: Vault integration (only if you use HashiCorp Vault with mistapi)
# MIST_VAULT_URL=https://vault.example.com
# MIST_VAULT_TOKEN=xxxxx
# MIST_VAULT_MOUNT_POINT=secret
# MIST_VAULT_PATH=secret/data/mist

Notes:

  • The list above for mistapi env vars was verified against the installed mistapi package (v0.57.x). If you pin or use an older mistapi version, the available behavior may differ; several scripts in this repo include a MISTAPI_MIN_VERSION constant — check the script header for compatibility notes.

Repository layout

  • scripts/ — main scripts grouped by topic (configuration, orgs, sites, devices, exports, reports, nac, clients)
  • utils/ — helper utilities (e.g. encryption)
  • v-tool/ — additional tooling
  • requirements.txt — Python dependencies

Each script contains a short header describing purpose, options and examples. Run any script with -h for usage details.

Example workflows

  • Backup an organization configuration:
python scripts/orgs/org_conf_backup.py -e ~/.mist_env --org-id <ORG_ID>
  • Deploy a saved org configuration (dry-run first):
python scripts/orgs/org_conf_deploy.py -e ~/.mist_env --file backup.json --dry-run
  • Import guests from CSV into a site:
python scripts/clients/import_guests.py -e ~/.mist_env --site <SITE_ID> --csv guests.csv

Finding scripts

There are many scripts. Here are a few high-level categories (see scripts/ for the full list):

  • Configuration: scripts/configuration/ (webhooks, auto-assignment, AP auto-upgrade)
  • EVPN helpers: scripts/configuration/evpn_topology/
  • Orgs / Backups: scripts/orgs/ (backup, deploy, clone, inventory)
  • Devices: scripts/devices/ (AP, gateway, switch helpers)
  • Imports: scripts/clients/, scripts/nac/, scripts/sites/ (CSV-driven imports)
  • Reports / Exports: scripts/reports/, scripts/exports/

Scripts index

Below is a full index of scripts included in this repository. Each entry contains a short description and a relative link to the script.

Organization / backup / deploy

Org admins

Configuration

EVPN helpers

Devices

AP helpers

Gateway helpers

Switch helpers

Clients / NAC / Imports

Sites

Exports & Reports

Reports

Utilities

Contributing

Contributions are welcome. Good ways to help:

  • Open issues for bugs or feature requests
  • Send small, focused pull requests that include a short description and example usage
  • Add or update script documentation at the top of the script file

When editing scripts, keep backwards compatibility where possible and include tests or a smoke-check if you add complex logic.

About

Python scripts demoing Mist APIs possibilities.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors 6

Languages