Skip to content

Modern IP Address Management (IPAM) system with Flask REST API, Bootstrap UI, and enterprise-grade security. Built on Chainguard distroless containers with 0 vulnerabilities.

Notifications You must be signed in to change notification settings

tuxpeople/python-ipam

Repository files navigation

Python IPAM - IP Address Management System

A modern, web-based IP Address Management (IPAM) system built with Flask, SQLite, Bootstrap, and DataTables.

Features

  • 🌐 Network Management: Manage IP networks with CIDR notation
  • πŸ–₯️ Host Management: Track IP addresses, hostnames, and MAC addresses
  • πŸ”Œ REST API: Complete RESTful API with Swagger UI documentation
  • πŸ“Š Dashboard: Clear overview of network utilization
  • πŸ” Advanced Search: DataTables integration for efficient data filtering
  • πŸ“± Responsive Design: Bootstrap 5 for modern, mobile-friendly UI
  • 🐳 Container-ready: Docker support for easy deployment
  • βœ… Fully Tested: Comprehensive unit tests with pytest

Local Development with pyenv

Prerequisites

  1. Install pyenv (if not already installed):

    macOS with Homebrew:

    brew install pyenv

    Linux/macOS with curl:

    curl https://pyenv.run | bash
  2. Shell Configuration (for bash/zsh):

    echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(pyenv init -)"' >> ~/.bashrc
    echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
    source ~/.bashrc

Setup

  1. Clone repository:

    git clone <repository-url>
    cd ipam
  2. Install and activate Python version:

    pyenv install 3.13
    pyenv local 3.13
  3. Create virtual environment:

    python -m venv venv
    source venv/bin/activate  # Linux/macOS
    # or
    venv\\Scripts\\activate  # Windows
  4. Install dependencies:

    pip install -r requirements.txt
  5. Configure environment variables:

    cp .env.example .env
    # Edit .env as needed
  6. Initialize database:

    python3 -c "from ipam import create_app; from ipam.extensions import db; app = create_app(); app.app_context().push(); db.create_all()"
  7. Start application:

    python app.py

    The application will be available at:

Running Tests

# Run all tests
pytest

# Tests with coverage report
pytest --cov=app --cov-report=html

# Run specific tests
pytest tests/test_models.py

# Tests in watch mode (with pytest-watch)
pip install pytest-watch
ptw

Docker Deployment

Production Container (Chainguard Distroless)

The production Docker image is built on Chainguard distroless Python images for maximum security:

Security Features:

  • βœ… 0 CRITICAL/HIGH vulnerabilities (Trivy scanned)
  • βœ… Multi-stage build with minimal attack surface
  • βœ… Distroless runtime (no shell, package manager)
  • βœ… Runs as nonroot user (UID 65532)
  • βœ… Includes SBOM (Software Bill of Materials)
  • βœ… Python 3.13

Image Details:

  • Size: ~50-100MB (vs 200-300MB for standard Python images)
  • Base: cgr.dev/chainguard/python:latest (distroless)
  • Registry: ghcr.io/tuxpeople/python-ipam
# Pull and run production image
docker pull ghcr.io/tuxpeople/python-ipam:latest
docker run -d -p 5000:5000 \
  -v $(pwd)/ipam.db:/app/ipam.db \
  ghcr.io/tuxpeople/python-ipam:latest

# Or use Docker Compose
docker-compose up -d

# With custom .env file
cp .env.example .env
# Edit .env for production settings
docker-compose up -d

Development

# Development environment with hot-reload
docker-compose --profile dev up

# Or build locally
docker build -t python-ipam:dev .
docker run -p 5000:5000 python-ipam:dev

REST API

The complete REST API is available at /api/v1. Interactive API documentation (Swagger UI) can be found at http://localhost:5000/api/v1/docs

Main Endpoints:

Networks:

  • GET /api/v1/networks - List all networks with filtering and pagination
  • GET /api/v1/networks/{id} - Get specific network
  • POST /api/v1/networks - Create new network
  • PUT /api/v1/networks/{id} - Update network
  • DELETE /api/v1/networks/{id} - Delete network

Hosts:

  • GET /api/v1/hosts - List all hosts with filtering and pagination
  • GET /api/v1/hosts/{id} - Get specific host
  • POST /api/v1/hosts - Create new host
  • PUT /api/v1/hosts/{id} - Update host
  • DELETE /api/v1/hosts/{id} - Delete host

IP Management:

  • GET /api/v1/ip/networks/{id}/next-ip - Get next available IP
  • GET /api/v1/ip/networks/{id}/available-ips - List all available IPs
  • GET /api/v1/ip/{ip_address} - Query IP address status

See API.md for complete documentation

Project Structure

ipam/
β”œβ”€β”€ app.py                 # Flask application entry point
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ pytest.ini            # Pytest configuration
β”œβ”€β”€ Dockerfile            # Docker container definition
β”œβ”€β”€ docker-compose.yml    # Docker Compose configuration
β”œβ”€β”€ .env.example          # Example environment variables
β”œβ”€β”€ ipam/                 # Main application package
β”‚   β”œβ”€β”€ __init__.py       # Application Factory
β”‚   β”œβ”€β”€ extensions.py     # Flask extensions (SQLAlchemy)
β”‚   β”œβ”€β”€ models.py         # Database models
β”‚   β”œβ”€β”€ forms.py          # WTForms
β”‚   β”œβ”€β”€ config.py         # Configuration
β”‚   β”œβ”€β”€ api/              # REST API Blueprint
β”‚   β”‚   β”œβ”€β”€ __init__.py   # API Blueprint and Swagger
β”‚   β”‚   β”œβ”€β”€ models.py     # API serialization models
β”‚   β”‚   β”œβ”€β”€ networks.py   # Network endpoints
β”‚   β”‚   β”œβ”€β”€ hosts.py      # Host endpoints
β”‚   β”‚   └── ip_management.py  # IP management endpoints
β”‚   └── web/              # Web Interface Blueprint
β”‚       β”œβ”€β”€ __init__.py   # Web Blueprint
β”‚       └── routes.py     # Web routes
β”œβ”€β”€ templates/            # HTML Templates (Jinja2)
β”‚   β”œβ”€β”€ base.html         # Base template
β”‚   β”œβ”€β”€ index.html        # Dashboard
β”‚   β”œβ”€β”€ networks.html     # Network overview
β”‚   β”œβ”€β”€ hosts.html        # Host overview
β”‚   β”œβ”€β”€ add_network.html  # Add network
β”‚   β”œβ”€β”€ add_host.html     # Add host
β”‚   β”œβ”€β”€ edit_network.html # Edit network
β”‚   └── edit_host.html    # Edit host
β”œβ”€β”€ exporters/            # Export plugins
β”‚   β”œβ”€β”€ base_exporter.py  # Base exporter class
β”‚   β”œβ”€β”€ csv_exporter.py   # CSV export
β”‚   β”œβ”€β”€ json_exporter.py  # JSON export
β”‚   └── dnsmasq_exporter.py  # DNSmasq config export
β”œβ”€β”€ importers/            # Import plugins
β”‚   β”œβ”€β”€ base_importer.py  # Base importer class
β”‚   β”œβ”€β”€ csv_importer.py   # CSV import
β”‚   └── json_importer.py  # JSON import
└── tests/                # Test suite
    β”œβ”€β”€ conftest.py       # Pytest fixtures
    β”œβ”€β”€ test_models.py    # Model tests
    β”œβ”€β”€ test_routes.py    # Route tests
    β”œβ”€β”€ test_forms.py     # Form tests
    β”œβ”€β”€ test_database.py  # Database tests
    β”œβ”€β”€ test_export_import.py  # Export/Import tests
    └── test_crud_operations.py  # CRUD tests

Database Schema

Networks Table

  • id - Primary Key
  • network - Network address (e.g., "192.168.1.0")
  • cidr - CIDR suffix (e.g., 24)
  • broadcast_address - Broadcast address
  • name - Network name (optional)
  • domain - DNS domain (optional)
  • vlan_id - VLAN ID (optional)
  • description - Description (optional)
  • location - Location (optional)

Hosts Table

  • id - Primary Key
  • ip_address - IP address (unique)
  • hostname - Hostname (optional)
  • cname - DNS alias/CNAME (optional)
  • mac_address - MAC address (optional)
  • description - Description (optional)
  • status - Status (active/inactive/reserved)
  • network_id - Foreign Key to Networks

Development Guidelines

  1. Code Style: Follow PEP 8
  2. Tests: Write tests for new features
  3. Commits: Use meaningful commit messages
  4. Branches: Use feature branches for new development

Technology Stack

  • Backend: Flask 3.1, SQLAlchemy 2.0, Flask-RESTX
  • Frontend: Bootstrap 5, jQuery, DataTables
  • Database: SQLite (production-ready for small to medium deployments)
  • Testing: pytest, pytest-flask (96 tests)
  • Containerization: Docker (Chainguard distroless), Docker Compose
  • Security: Trivy scanning, SBOM generation, multi-stage builds
  • CI/CD: GitHub Actions (tests, security scans, docs deployment)

License

[Specify license here]

Contributing

Contributions are welcome! Please create issues for bug reports or feature requests.

About

Modern IP Address Management (IPAM) system with Flask REST API, Bootstrap UI, and enterprise-grade security. Built on Chainguard distroless containers with 0 vulnerabilities.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •  

Languages