Skip to content

spagno/truenas-vm-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TrueNAS VM Manager

A Python-based tool for automated creation and management of virtual machines on TrueNAS systems. This tool provides a template-driven approach to VM provisioning with support for different VM types and comprehensive device management.

πŸš€ Features

  • βœ… Template-based VM Creation - JSON templates for consistent VM configuration
  • βœ… Multi-VM Type Support - Separate configurations for controlplane and worker nodes
  • βœ… Configurable Storage - Flexible ZVOL pool paths and ISO management
  • βœ… Automated Device Management - Disk, network, display, and CDROM device provisioning
  • βœ… SPICE Display Integration - Remote desktop access with configurable resolution
  • βœ… Network Bridge Support - Multiple network interfaces with VIRTIO drivers
  • βœ… Error Recovery - Automatic cleanup on VM creation failures
  • βœ… Configurable Logging - Debug and monitoring capabilities
  • βœ… Environment-based Configuration - Secure credential management

πŸ“‹ Prerequisites

  • Python 3.8+ (Python 3.9+ recommended)
  • TrueNAS SCALE with API enabled
  • Git for dependency installation
  • Network access to TrueNAS system
  • Sufficient storage in configured ZVOL pool

πŸ—οΈ Project Structure

truenas-vm-manager/
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ LICENSE                   # GNU LGPL v3 license
β”œβ”€β”€ CHANGELOG.md             # Version history
β”œβ”€β”€ CONTRIBUTING.md          # Contribution guidelines
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ .env.example            # Environment variables template
β”œβ”€β”€ .gitignore              # Git ignore rules
β”œβ”€β”€ truenas-vm-manager.py   # Main application
β”œβ”€β”€ config.yaml             # VM configuration
β”œβ”€β”€ docs/                   # Documentation
β”‚   β”œβ”€β”€ ARCHITECTURE.md     # System architecture
β”‚   β”œβ”€β”€ API.md             # API reference
β”‚   β”œβ”€β”€ TROUBLESHOOTING.md # Common issues and solutions
β”‚   └── EXAMPLES.md        # Usage examples
β”œβ”€β”€ templates/             # JSON templates
β”‚   β”œβ”€β”€ vms/
β”‚   β”‚   └── vm.json        # VM base template
β”‚   └── devices/
β”‚       β”œβ”€β”€ disk.json      # Disk device template
β”‚       β”œβ”€β”€ nic.json       # Network interface template
β”‚       β”œβ”€β”€ display.json   # SPICE display template
β”‚       └── cdrom.json     # CDROM device template
└── .vscode/              # VS Code configuration
    └── launch.json       # Debug configuration

⚑ Quick Start

1. Installation

# Clone the repository
git clone https://github.com/your-username/truenas-vm-manager.git
cd truenas-vm-manager

# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt

2. Configuration

Create your environment file from the template:

cp .env.example .env

Edit .env with your TrueNAS credentials:

TRUENAS_HOST=192.168.1.100
API_USERNAME=admin
API_PASSWORD=your_secure_password
VNC_PASSWORD=spice_password

3. Configure VMs

Edit config.yaml to match your environment:

# Storage configuration
storage:
  pool_path: "your-pool/VMs"                    # ZVOL pool path
  cdrom_path: "/mnt/your-pool/your-iso.iso"     # Boot ISO path

# VM configurations
controlplane:
  count: 3
  memory: 4096
  cpu: 4
  disk:
    system: 30
  network:
    system: br0

worker:
  count: 3
  memory: 4096
  cpu: 4
  disk:
    system: 30
    storage: 600
  network:
    system: br0
    storage: br1

4. Usage

# Activate virtual environment
source venv/bin/activate

# Create VMs
python truenas-vm-manager.py create

# Destroy VMs
python truenas-vm-manager.py destroy

# Use custom configuration
python truenas-vm-manager.py create --config production.yaml --log-level DEBUG

πŸ“š Documentation

πŸ”§ Configuration

Environment Variables

Variable Description Example
TRUENAS_HOST TrueNAS server IP/hostname 192.168.1.100
API_USERNAME TrueNAS API username admin
API_PASSWORD TrueNAS API password your_secure_password
VNC_PASSWORD SPICE display password spice_access_password

Storage Configuration

The storage section in config.yaml defines paths for VM storage and boot media:

storage:
  pool_path: "seagate/VMs"                     # Base path for ZVOL creation
  cdrom_path: "/mnt/seagate/ubuntu-server.iso" # ISO file for VM boot

VM Types

Each VM type supports different configurations:

  • controlplane: Kubernetes control plane nodes
  • worker: Kubernetes worker nodes with additional storage

πŸš€ Advanced Usage

Custom Templates

Templates are located in templates/ directory and can be customized:

  • vms/vm.json - Base VM configuration
  • devices/disk.json - Storage device template
  • devices/nic.json - Network interface template
  • devices/display.json - SPICE display template
  • devices/cdrom.json - CDROM device template

Multiple Configurations

Use different configuration files for different environments:

# Development environment
python truenas-vm-manager.py create --config dev.yaml

# Production environment
python truenas-vm-manager.py create --config production.yaml

# Testing with debug logging
python truenas-vm-manager.py create --config test.yaml --log-level DEBUG

πŸ› Troubleshooting

For common issues and solutions, see TROUBLESHOOTING.md.

Quick Fixes

  • Connection issues: Verify TrueNAS API is accessible and credentials are correct
  • Template errors: Ensure all template files exist and contain valid JSON
  • Storage errors: Check ZVOL pool exists and has sufficient space
  • Network errors: Verify bridge interfaces exist in TrueNAS

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Setup

# Clone repository
git clone https://github.com/your-username/truenas-vm-manager.git
cd truenas-vm-manager

# Create development environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Install development tools
pip install black flake8 mypy pytest

πŸ“„ License

This project is licensed under the GNU Lesser General Public License v3.0 - see the LICENSE file for details.

πŸ”— Links

πŸ“Š Status

License Python Platform


Made with ❀️ for the TrueNAS community

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages