A modular Python package for migrating data from Racktables to NetBox. This tool provides comprehensive migration of network infrastructure data with extended features for a complete data transfer experience.
- Comprehensive Migration: Transfer all your Racktables data to NetBox
- Modular Architecture: Maintainable and extensible codebase for easier updates
- Site Filtering: Restrict migration to specific sites when needed
- Tenant Filtering: Restrict migration to specific tenants and associate objects with tenants
- Component Selection: Choose which components to migrate with flexible flags
- Custom Fields: Automatic setup of required custom fields in NetBox
- Extended Data Support:
- Available subnet detection and creation
- Patch cable connections
- File attachments
- Virtual services
- NAT mappings
- Load balancer configurations
- Monitoring data references
- IP ranges
Before starting, ensure you have:
- Python 3.6 or higher installed
- Access to your Racktables MySQL/MariaDB database
- A running NetBox instance (version 4.2.6 or higher) with API access
- Administrative privileges on the NetBox instance to add custom fields
The tool includes a setup script that automates the installation process:
# Clone the repository
git clone https://github.com/enoch85/racktables-to-netbox.git
cd racktables-to-netbox
# Make the setup script executable
chmod +x setup_dev.sh
# Run automated setup
./setup_dev.sh
The setup_dev.sh
script has several options:
--netbox
: Sets up a complete NetBox Docker environment with proper configuration--gitclone
: Configures minimal requirements after a git clone (default if no options specified)--package
: Sets up for package distribution--help
: Displays help message
For a complete setup with NetBox included:
./setup_dev.sh --netbox
# Clone the repository
git clone https://github.com/enoch85/racktables-to-netbox.git
cd racktables-to-netbox
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
Edit the configuration in migration/config.py
:
# NetBox API connection settings - can be overridden with environment variables
NB_HOST = os.environ.get('NETBOX_HOST', 'localhost')
NB_PORT = int(os.environ.get('NETBOX_PORT', '8000'))
NB_TOKEN = os.environ.get('NETBOX_TOKEN', 'your-api-token')
NB_USE_SSL = os.environ.get('NETBOX_USE_SSL', 'False').lower() in ('true', '1', 'yes')
# Database connection parameters - can be overridden with environment variables
DB_CONFIG = {
'host': os.environ.get('RACKTABLES_DB_HOST', 'your-racktables-db-host'),
'port': int(os.environ.get('RACKTABLES_DB_PORT', '3306')),
'user': os.environ.get('RACKTABLES_DB_USER', 'your-db-username'),
'password': os.environ.get('RACKTABLES_DB_PASSWORD', 'your-db-password'),
'db': os.environ.get('RACKTABLES_DB_NAME', 'racktables-db-name'),
'charset': 'utf8mb4',
'cursorclass': DictCursor
}
# Migration flags - control which components are processed
CREATE_VLAN_GROUPS = True
CREATE_VLANS = True
# ... additional flags
Alternatively, you can use environment variables:
# NetBox connection
export NETBOX_HOST=localhost
export NETBOX_PORT=8000
export NETBOX_TOKEN=your-api-token
export NETBOX_USE_SSL=False
# Database connection
export RACKTABLES_DB_HOST=your-racktables-db-host
export RACKTABLES_DB_PORT=3306
export RACKTABLES_DB_USER=your-db-username
export RACKTABLES_DB_PASSWORD=your-db-password
export RACKTABLES_DB_NAME=racktables-db-name
This setting is required for the migration tool to properly fetch all objects in a single request:
# Make the script executable
chmod +x scripts/max-page-size-check.sh
# Edit the script to set your NetBox Docker path
nano scripts/max-page-size-check.sh
# Run the script
./scripts/max-page-size-check.sh
# Run setup to create custom fields (only needed once)
python migration/set_custom_fields.py
# Run the migration
python migration/migrate.py
# Migrate data for a specific site only
python migration/migrate.py --site "YourSiteName"
# Migrate data with a specific tenant
python migration/migrate.py --tenant "YourTenantName"
# Migrate data for a specific site and tenant
python migration/migrate.py --site "YourSiteName" --tenant "YourTenantName"
# Run only basic migration (no extended components)
python migration/migrate.py --basic-only
# Run only extended migration components
python migration/migrate.py --extended-only
# Skip setting up custom fields
python migration/migrate.py --skip-custom-fields
# Use custom configuration file
python migration/migrate.py --config your_config.py
racktables-to-netbox/
├── migration/ # Main migration package
│ ├── __init__.py # Package initialization
│ ├── config.py # Global configuration settings
│ ├── custom_netbox.py # Compatibility wrapper for pynetbox
│ ├── db.py # Database connection and query helpers
│ ├── devices.py # Device creation and management
│ ├── interfaces.py # Interface creation and management
│ ├── ips.py # IP and network related functions
│ ├── migrate.py # Main migration script
│ ├── set_custom_fields.py # Custom fields setup
│ ├── sites.py # Site and rack related functions
│ ├── utils.py # Utility functions
│ ├── vlans.py # VLAN management functions
│ ├── vms.py # Virtual machine handling
│ ├── extended/ # Extended functionality modules
│ ├── __init__.py
│ ├── available_subnets.py # Available subnet detection
│ ├── files.py # File attachment migration
│ ├── ip_ranges.py # IP range generation
│ ├── load_balancer.py # Load balancing data
│ ├── monitoring.py # Monitoring data
│ ├── nat.py # NAT mappings
│ ├── patch_cables.py # Patch cable migration
│ └── services.py # Virtual services migration
├── scripts/ # Helper scripts
├── setup_dev.sh # Development environment setup
├── requirements.txt # Python dependencies
└── setup.py # Package setup script
Restrict migration to a specific site and/or tenant:
python migration/migrate.py --site "DataCenter1" --tenant "CustomerA"
This will:
- Only migrate objects associated with the specified site
- Associate all created objects with the specified tenant
- Create the tenant if it doesn't exist in NetBox
The tool automatically:
- Identifies gaps in IP address space
- Creates available prefixes in those gaps
- Tags them with "Available" status for easy filtering
The tool can create IP ranges based on:
- Available subnets that it detects
- Gaps between allocated IP addresses
- Empty prefixes with no allocated IPs
- Patch Cables: Migrates physical cable connections between devices
- Files: Transfers file attachments from Racktables
- Virtual Services: Migrates service configurations
- NAT: Preserves Network Address Translation relationships
- Load Balancing: Migrates load balancer configs
- Monitoring: Transfers monitoring system references
- Check the
errors
log file for detailed error messages - Ensure MAX_PAGE_SIZE=0 is set in your NetBox configuration
- Verify database connectivity and permissions
- Make sure custom fields are properly created
-
Database Connection Issues
- Verify credentials in
config.py
- Check network connectivity to database server
- Ensure database port is accessible
- Verify credentials in
-
NetBox API Connection Issues
- Verify API token has appropriate permissions
- Check network connectivity to NetBox server
- Confirm API is enabled in NetBox settings
-
Memory or Performance Issues
- Try running parts of the migration by adjusting flags in
config.py
- Increase Python process memory limit
- Consider filtering by site with the
--site
parameter
- Try running parts of the migration by adjusting flags in
GNU General Public License v3.0