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.2.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: virtomate-0.1.2.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for virtomate-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a1a04ccfd081d209afd9fb0dbe61ff64f60aa2b07f609fe4da22f84980a69361
MD5 801fb67fc9cc6b5e7124bb305d247e2f
BLAKE2b-256 e2adb145f30da4c0305495450e24292c191fcaaed7e7424b8b8c74363d8a1efe

See more details on using hashes here.

Provenance

The following attestation bundles were made for virtomate-0.1.2.tar.gz:

Publisher: build.yml on aahlenst/virtomate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

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

File hashes

Hashes for virtomate-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9549f409895e299acde7ccb0e19e2a36ed060b7dcf8ee233f3f2b2b8fc7cf981
MD5 a96c9c099a38c73ab088079a29de6490
BLAKE2b-256 7a0d6db54407daf58e12606c7ba3af6bf29e65411a54196428522625429547ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for virtomate-0.1.2-py3-none-any.whl:

Publisher: build.yml on aahlenst/virtomate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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