A comprehensive hands-on lab environment for learning Juniper Mist API automation using Python. This project provides interactive Jupyter-style notebooks (.py files) that demonstrate how to automate Juniper Mist operations including device adoption, site configuration, and network management.
- Overview
- What are Python Jupyter Notebooks?
- Prerequisites
- Installation
- Configuration
- Running the Labs
- Project Structure
- Available Labs
- Troubleshooting
- Resources
This project contains interactive Python labs that teach you how to:
- Authenticate with the Juniper Mist API
- Adopt and manage network devices (SSR routers, EX switches, Access Points)
- Perform CRUD operations on sites and configurations
- Use both the
requestslibrary and themistapiPython package - Automate Day 1 and Day 2 network operations
Jupyter Notebooks are interactive documents that combine live code, visualizations, and narrative text. They allow you to:
- Write and execute code in cells
- See results immediately below each code cell
- Mix code with documentation using Markdown
- Iterate and experiment interactively
Learn more:
This project uses Python files (.py) as notebooks instead of traditional .ipynb files. This approach offers several advantages:
- ✅ Better version control (plain text, easy to diff)
- ✅ Works with standard Python tools
- ✅ No JSON metadata clutter
- ✅ Can be run as scripts or interactively
How it works:
- Files use special
# %%cell markers to define code cells - VS Code's Jupyter extension recognizes these markers
- You get the same interactive experience as
.ipynbfiles - Code can be executed cell-by-cell or all at once
Learn more:
-
Python 3.8 or higher
- Download: python.org/downloads
- Verify installation:
python --versionorpython3 --version
-
Visual Studio Code
- Download: code.visualstudio.com
-
Git (optional, for cloning)
- Download: git-scm.com
-
Make (optional, for using Makefile)
- Windows: Install via Chocolatey (
choco install make) or use Git Bash - macOS: Pre-installed with Xcode Command Line Tools
- Linux: Usually pre-installed (
sudo apt install makeon Ubuntu/Debian)
- Windows: Install via Chocolatey (
Install these extensions in VS Code:
-
Python Extension (Required)
- Extension ID:
ms-python.python - Install: Open VS Code → Extensions (Ctrl+Shift+X) → Search "Python" → Install
- Extension ID:
-
Jupyter Extension (Required)
- Extension ID:
ms-toolsai.jupyter - Install: Extensions → Search "Jupyter" → Install
- Extension ID:
-
Pylance (Recommended, usually installed with Python extension)
- Extension ID:
ms-python.vscode-pylance - Provides enhanced IntelliSense and type checking
- Extension ID:
Installation Steps:
# Option 1: Install via VS Code UI
# 1. Open VS Code
# 2. Click Extensions icon (or press Ctrl+Shift+X)
# 3. Search for "Python" and click Install
# 4. Search for "Jupyter" and click Install
# Option 2: Install via command line
code --install-extension ms-python.python
code --install-extension ms-toolsai.jupyter
code --install-extension ms-python.vscode-pylance- Active Juniper Mist account with API access
- Organization ID and API token
- Access to Mist-managed devices (for device adoption labs)
# Option 1: Clone with Git
git clone https://github.com/yourusername/eg-juniper-mist-automation-lab.git
cd eg-juniper-mist-automation-lab
# Option 2: Download ZIP
# Download from GitHub and extract to your desired locationThis project uses uv for fast Python package management.
Windows (PowerShell):
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | shOr use the Makefile:
make install-uvLearn more about uv: docs.astral.sh/uv
Option A: Using Makefile (Recommended)
# Complete setup (creates venv + installs dependencies)
make setup
# Or step by step:
make venv # Create virtual environment
make install # Install dependenciesOption B: Manual Setup
# Create virtual environment
uv venv .venv
# Activate virtual environment
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
# Install dependencies
uv pip install -r requirements.txt
# Register Jupyter kernel
uv run python -m ipykernel install --user --name=eg-juniper-mist --display-name="Python (Mist Lab)"# Check installed packages
uv pip list
# Run tests (optional)
make test
# or
uv run pytest tests/ -vCopy the example file and add your credentials:
# Windows
copy .env.example .env
# macOS/Linux
cp .env.example .envOpen .env in your editor and add your Mist API token:
# .env file
MIST_API_TOKEN=your_actual_api_token_hereHow to get your API token:
- Log in to manage.mist.com
- Go to Organization → Settings → API Tokens
- Click "Create Token"
- Give it a name and admin privileges
- Copy the token to your
.envfile
.env file to version control. It's already in .gitignore.
Edit config/env.yml with your environment-specific values:
# config/env.yml
host: api.ac2.mist.com # Your Mist API host
org_id: your_org_id_here # Will be auto-populated by Lab 04
ap1_mac: your_ap1_mac_here # Your AP MAC address
ex1_mac: your_ex1_mac_here # Your switch MAC address
ex_ip: 10.210.6.82 # Your switch IP
ex_gateway: 10.210.6.86 # Your gateway IP
mgmt_vlan: "3630" # Your management VLAN
vlan_1: "3680" # Your VLAN 1
vlan_2: "3681" # Your VLAN 2
# SSR MACs will be auto-populated by Lab 04
ssr1_mac: your_ssr1_mac_here
ssr2_mac: your_ssr2_mac_here
ssr3_mac: your_ssr3_mac_here
ssr4_mac: your_ssr4_mac_hereNote: Many values (like org_id and SSR MAC addresses) will be automatically populated when you run Lab 04.
-
Open the project folder in VS Code:
code . -
Open a lab file:
- Navigate to
labs/04_Performing_Juniper_Mist_Operations_With_REST_API/lab.py - VS Code will recognize it as a Jupyter notebook (due to
# %%markers)
- Navigate to
-
Select the Python kernel:
- Click on the kernel selector in the top-right corner
- Choose "Python (Mist Lab)" or your
.venvPython interpreter
Interactive Execution (Recommended):
- Click the
▶️ "Run Cell" button above each# %%marker - Or use keyboard shortcuts:
Shift+Enter: Run current cell and move to nextCtrl+Enter: Run current cell and stayAlt+Enter: Run current cell and insert new cell below
Run All Cells:
- Click "Run All" at the top of the file
- Or use Command Palette (Ctrl+Shift+P) → "Jupyter: Run All Cells"
Run as Script:
# Activate virtual environment first
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
# Run the lab
python labs/04_Performing_Juniper_Mist_Operations_With_REST_API/lab.py- Variables Explorer: View all variables in the current session
- Output: See results immediately below each cell
- Debugging: Set breakpoints and debug interactively
- Plots: Visualizations appear inline (if using matplotlib/bokeh)
Learn more:
eg-juniper-mist-automation-lab/
├── .venv/ # Virtual environment (created during setup)
├── config/
│ └── env.yml # Non-secret configuration
├── labs/
│ ├── 04_Performing_Juniper_Mist_Operations_With_REST_API/
│ │ └── lab.py # Lab 04: API basics
│ └── data/ # Lab data and screenshots
│ ├── L04/
│ ├── L05/
│ ├── L07/
│ ├── L08/
│ ├── L09/
│ └── L10/
├── tests/
│ ├── conftest.py # Pytest configuration
│ ├── test_L04_integration.py # Lab 04 tests
│ └── test_L05_integration.py # Lab 05 tests
├── utils/
│ ├── __init__.py
│ ├── config.py # Configuration loader
│ └── mist_engine.py # Mist API utilities
├── .env # Your secrets (create from .env.example)
├── .env.example # Template for .env
├── .gitignore # Git ignore rules
├── Makefile # Build automation
├── README.md # This file
└── requirements.txt # Python dependencies
File: labs/04_Performing_Juniper_Mist_Operations_With_REST_API/lab.py
Topics Covered:
- Setting up API authentication
- Discovering organization ID
- Adopting SSR routers and EX switches
- Listing and managing sites
- CRUD operations with
requestslibrary - CRUD operations with
mistapipackage - Saving configuration for future labs
Prerequisites:
- Mist API token configured in
.env - Access to Mist organization
- SSR routers and EX switches available for adoption
Problem: "No kernel found" or kernel selector shows no options
Solution:
# Reinstall ipykernel
uv pip install ipykernel
uv run python -m ipykernel install --user --name=eg-juniper-mist --display-name="Python (Mist Lab)"
# Restart VS CodeProblem: ModuleNotFoundError: No module named 'mistapi'
Solution:
# Ensure virtual environment is activated
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
# Reinstall dependencies
make install
# or
uv pip install -r requirements.txtProblem: ImportError when running cells
Solution:
- Ensure you've selected the correct Python kernel (Python (Mist Lab))
- Restart the kernel: Command Palette → "Jupyter: Restart Kernel"
- Check that virtual environment is activated
Problem: 401 Unauthorized or authentication errors
Solution:
- Verify your API token in
.envis correct - Check token hasn't expired in Mist portal
- Ensure no extra spaces in
.envfile - Reload environment: Restart VS Code or kernel
Problem: junos-eznc installation fails
Solution:
# Install system dependencies (Ubuntu/Debian)
sudo apt install -y libffi-dev libssl-dev libxml2-dev libxslt1-dev python3-dev
# Then reinstall
make install- VS Code Jupyter Documentation: code.visualstudio.com/docs/datascience/jupyter-notebooks
- Mist API Documentation: doc.mist-lab.fr
- mistapi Package: PyPI - mistapi
Quick reference for available make commands:
make help # Show all available commands
make setup # Complete setup (venv + install)
make venv # Create virtual environment only
make install # Install dependencies
make sync # Sync dependencies (faster)
make test # Run pytest tests
make clean # Remove virtual environment
make reinstall # Clean and setup from scratch
make activate # Show activation command
make add PACKAGE=name # Add a new package
make remove PACKAGE=name # Remove a package-
Jupyter Notebooks:
-
Juniper Mist:
-
Python Tools:
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Happy Learning! 🚀
For questions or issues, please open an issue on GitHub.
