Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

Virtual Lab Environment Manager

gestiona-pc1.py is a Python script designed to automate the creation, configuration, and management of a virtualized network environment. Its main purpose is to deploy a Load Balancer (LB) scenario using QEMU/KVM (libvirt), configurable web servers, and virtual bridges, simplifying the setup of complex network labs for testing and educational purposes.

πŸ’‘ Main Objective

The primary goal is to provide a single command-line interface to manage a complete load balancing scenario, including:

  • Automated VM Provisioning: Create disk images (.qcow2) and definition files (.xml) from templates.
  • Network Setup: Configure Linux bridges (LAN1, LAN2) and host routing to interconnect the scenario.
  • Service Configuration: Automatically configure networking (IPs, gateways, hostnames) and critical services like HAProxy.
  • Lifecycle Management: Handle VM start, stop, reboot, and complete destruction of the virtual lab.

The resulting architecture consists of a client LAN (LAN1) separated from a server farm LAN (LAN2) by the load balancer.

πŸ› οΈ Technology and Dependencies

Core Technologies

  • Virtualization Backend: QEMU/KVM managed via libvirt (virsh).
  • Disk Image Management: qemu-img to create copy-on-write images from a base.
  • VM Configuration: libguestfs-tools (virt-copy-in, virt-edit) for VM customization before first boot.
  • Network Abstraction: Linux Bridges (brctl) to define virtual LANs.
  • Load Balancing Service: HAProxy configured in Round Robin mode.

Python Requirements

  • sys, os, json, subprocess
  • lxml for programmatic manipulation of libvirt XML files
  • logging for structured debug and informational output

πŸš€ Usage Guide

python3 gestiona-pc1.py <command> [sub-parameters]

Key Commands

Command Description Example
create Builds the entire scenario. Configurable with the number of servers (1-5) and debug flag. python3 gestiona-pc1.py create 3 debug
start Boots the VMs and opens an xterm console for interaction. python3 gestiona-pc1.py start lb
stop Shuts down the specified VM(s) using virsh shutdown. python3 gestiona-pc1.py stop s1
destroy CLEANUP: Stops all VMs, undefines them, deletes all generated files (.qcow2, .xml, etc.), and removes the bridges. python3 gestiona-pc1.py destroy
monitor Provides real-time status or diagnostics of a VM. python3 gestiona-pc1.py monitor lb cpu
reboot Restarts the specified VM(s). python3 gestiona-pc1.py reboot
--help Displays the full usage guide. python3 gestiona-pc1.py --help

Monitor Sub-Parameters

The monitor command requires a VM name (c1, lb, or sX) and a function:

Function Description
ping Performs a 5-packet connectivity test from the host to the VM.
info Displays detailed VM information (virsh dominfo) in a live watch window.
estado Shows the current power state of the VM (virsh domstate) in a live watch window.
cpu Displays VM CPU statistics (virsh cpu-stats) in a live watch window.

πŸ“ Artifacts Generated

The following files and configurations are created by the create command and removed by the destroy command:

  • gestiona-pc1.json – Stores scenario configuration (number of servers, debug flag).
  • <VM>.qcow2 – VM disk images (c1.qcow2, lb.qcow2, sX.qcow2).
  • <VM>.xml – libvirt VM definition files.
  • LAN1, LAN2 – Virtual Linux bridges.
  • Temporary configuration files used for VM customization:
    • hosts
    • hostname
    • interfaces
    • haproxy.cfg
    • rc.local
    • index.html

About

Project developed as the final project for the Data Centers and Service Provision course, which is taken during the fourth year of the Bachelor's Degree in Telecommunication Technologies and Services Engineering.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages