Skip to main content

A scripting-friendly tool to manage virtual machines with libvirt.

Project description

Virtomate

Virtomate is a handy command-line application for managing virtual machines with libvirt. It runs on any Unix-like system with Python 3.10 and libvirt 9.0 (or newer) installed.

Accomplish complex tasks like cloning virtual machines with ease:

$ virtomate domain-clone --mode linked ubuntu-24.04 my-clone

Or run a command on the guest without SSH:

$ virtomate -p guest-run ubuntu-24.04 -- apt-get update
{
  "exit_code": 0,
  "signal": null,
  "stderr": null,
  "stderr_truncated": false,
  "stdout": "Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease\nHit:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease\nHit:3 http://archive.ubuntu.com/ubuntu noble-backports InRelease\nHit:4 http://security.ubuntu.com/ubuntu noble-security InRelease\nReading package lists...\n",
  "stdout_truncated": false
}

Virtomate's scripting-friendly interface makes automating administrative tasks a breeze. Pipe its JSON output to jq to extract the information you need and combine it with any other tool. Emptying a storage pool becomes a single line of code:

$ virtomate volume-list boot | jq '.[].name' | xargs -i virsh vol-delete {} --pool boot

Even if virtual machines are running on a remote host, don't let that stop you. Virtomate can connect to other hosts using remote URIs:

$ virtomate -c qemu+ssh://ubuntu@10.0.7.3/system -p domain-list
[
  {
    "name": "ubuntu-24.04",
    "state": "running",
    "uuid": "b901fbbb-1012-495d-a32d-90a8ddaa50a7"
  }
]

Learn more at https://virtomate.org/.

Installation

$ pipx install virtomate

For more installation options, see the Virtomate documentation.

Getting Help

If you need help, please start a discussion on GitHub.

Contributing

Please see the contribution guide.

Development

Prerequisites

To run the complete test suite, including the functional tests, you need a machine with an x86 CPU running Linux. Other operating systems like BSD or macOS might work but have not been tested.

Preparation

To run the complete test suite, including the functional tests, you have to build a couple of virtual machine images and configure libvirt accordingly. This is an optional step, and you can skip it if you do not want to run the functional tests.

Install libvirt, QEMU

Refer to the instructions of the respective Linux distribution:

Check that the command-line tools virsh and qemu-img are on PATH and working.

Create Storage Pools

The test suite expects the presence of the following storage pools:

  • default in /var/lib/libvirt/images
  • nvram in /var/lib/libvirt/qemu/nvram

If they do not exist, you can create them as follows:

$ virsh pool-define-as default dir --target /var/lib/libvirt/images
$ virsh pool-autostart default
$ virsh pool-build default
$ virsh pool-start default

$ virsh pool-define-as nvram dir --target /var/lib/libvirt/qemu/nvram
$ virsh pool-autostart nvram
$ virsh pool-build nvram
$ virsh pool-start nvram

Create Virtual Machine Images

The functional tests require some virtual machine images to run. There are Packer templates in packer/ to create them in a couple of minutes:

$ pushd packer
$ packer build simple-bios.pkr.hcl
$ packer build simple-uefi.pkr.hcl
$ popd

Packer will save the virtual machine images to packer/dist.

Then, import them into libvirt by running:

$ sudo ./prepare-pool.sh packer/dist

Create a Build

$ rye build

This will create a source distribution (.tar.gz) and a wheel (.whl) in the folder dist of the source root.

Run the Tests

To run the unit tests, run:

$ rye test

Run the Functional Tests

WARNING: Running the functional tests can cause data loss. The test suite will treat all virtual machines and storage volumes whose names start with virtomate- as test artefacts and delete them after each test.

To run the functional tests, activate the virtual environment with source .venv/bin/activate (on Unix-like operating systems) or . .\env\Scripts\activate.ps1 on Windows. Then run:

$ rye test -- --functional

Functional tests require a working libvirt installation with QEMU. See the section Preparation above.

By default, the functional tests connect to qemu:///system. If your local user cannot access qemu:///system, adding it to the group libvirt is usually sufficient.

To run the functional tests against a different libvirt instance, define the environment variable LIBVIRT_DEFAULT_URI accordingly. See the libvirt documentation on Connection URIs on how to do this.

License

Virtomate is licensed under the GNU General Public License, version 2 only.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

virtomate-0.1.1.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

virtomate-0.1.1-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file virtomate-0.1.1.tar.gz.

File metadata

  • Download URL: virtomate-0.1.1.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for virtomate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d95dc192c06bc72f373ccf3265d43731ec9614e77e3ffe4ce84fc761bf6f425a
MD5 fe286ec79b407c822efc5caa977fdaeb
BLAKE2b-256 be9b963004a96479d115003305a4eeade53f0d80d300d6a48925640f5500c7dd

See more details on using hashes here.

File details

Details for the file virtomate-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: virtomate-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for virtomate-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01ecaf32af0e9b5f661b24a8660c4d0163f1583eeeca288da728d6bae440f8b3
MD5 d28f9f7092ae891a96905fcee73b9960
BLAKE2b-256 07d34cb1364b4b508b66ac132c51fde30ce7f1f3332b01b4de06560b12e8e9ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page