Skip to main content

A CLI frontend for libvirt.

Project description

fvirt - A command-line frontend for libvirt.

fvirt is a command-line frontend for libvirt that is intended to fill a similar role to the virsh frontend, but be more human-friendly and require less scripting to cover some very common use cases.

It also includes enhanced Python bindings for the libvirt API that wrap the low-level official bindings in a more Pythonic manner, making it nicer to work with libvirt from Python.

What does it do?

fvirt CLI

The fvirt CLI tool can:

  • List libvirt objects in much greater detail than virsh, with configurable columns and color highlighting of some values. For example, when listing domains, it can include everything that virsh list does, as well as extra info like the generation ID, the OS type, the CPU architecture, and the domain ‘title’.
  • Perform most common lifecycle operations on libvirt objects, including defining, starting, stopping, and undefining them.
  • Use a custom timeout to wait for domains to shut down. This cleanly encapsulates a relatively common use case which requires scripting to work with virsh, allowing for much simpler scripts.
  • Modify libvirt object XML using XSLT documents. This allows complex programmatic editing of domain configuration without needing complex scripting to extract the XML, process it, and then feed it back in to libvirt to redefine the object.
  • Match objects to operate on using XPath expressions and Python regexes. Special options are provided to simplify matching on commonly used properties, such as domain architecture or storage pool type. This matching works with a significant majority of commands provided by fvirt, allowing you to easily operate on groups of objects in bulk.
  • Generate object configurations from relatively simple YAML or JSON templates describing the object properties.
  • Still interoperate cleanly with virsh. fvirt stores no state client-side, so there’s nothing to get out of sync relative to what virsh would see or operate on. This means you can use fvirt as your primary frontend for libvirt, but still pop out to virsh when you need to do something fvirt doesn’t support without having to worry about it possibly causing fvirt to stop working.

fvirt.libvirt

The libvirt bindings included with fvirt provide a number of enhancements over the official bindings for Python, including:

  • Hypervisor connections support the context manager protocol.
  • Hypervisor objects provide iterator and mapping access to objects like domains and storage pools, including reference-counted automatic connection management.
  • Storage pools provide iterator and mapping access to their volumes.
  • Object states are enumerables (like they are in the C API) instead of a somewhat opaque list of integer constants (like they are in libvirt-python).
  • Object XML is directly accessible as lxml Element objects.
  • Things that should logically return an empty sequence when nothing is matched usually do so, in contrast to libvirt-python often returning None instead.
  • libvirt URIs are objects that can be easily modified to change things like the driver or host, as opposed to being strings you have to manipulate with regexes.
  • Many common properties of objects are accessible using regular attribute access instead of requiring either method calls or manual lookup in the object’s XML config. This includes writability for many of these properties (though this currently does not work for transient objects).

What doesn’t it do?

fvirt is designed first and foremost as a lightweight frontend for libvirt. libvirt provides a huge amount of functionality, much of which is actually never used by most users. fvirt does not support a lot of that less commonly used functionality, both because it’s a potential source of confusion for some users, and because it makes fvirt itself eaasier to maintain and more robust.

Currently, fvirt and fvirt.libvirt also do not support working with most libvirt objects other than domains, storage pools, and volumes. This is because that functionality is what I specifically needed for my own usage, thus it was the first thing I implemented. I plan to expand this further to at least include netowrks and network interfaces, but it’s not a priority at the moment.

Installation

fvirt is packaged on the Python Package Index with the package name fvirt. It can be easily installed using any Python packag emanagement tool that works with pypi. As usual with Python packages, use of a virtual environment is highly recommended.

The actual CLI tool is installed as a script with the name fvirt.

fvirt requires Python 3.11 or newer, and installation will also usually require the tools needed to build the libvirt-python package.

Contributing

fvirt's dependencies are managed using Poetry. Assuming you have Poetry installed and have cloned the repository, you can set up almost everything that’s needed for development by running poetry install --all-extras

In addition to the Python dependencies, a number of tests in our test suite require additional tooling, specifically a usable local install of libvirt (including virtqemud) and a working install of QEMU’s full system emulation tooling. Full details can be found in the README.md file in the tests directory of the repository.

Licensing

fvirt is licensed under a modified version of the MIT license commonly known as the ‘MIT +no-false-attribs license'. This license is a free software license and is GPL compatible, but is not formally FSF or OSI approved.

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

fvirt-0.1.1.tar.gz (109.2 kB view details)

Uploaded Source

Built Distribution

fvirt-0.1.1-py3-none-any.whl (155.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fvirt-0.1.1.tar.gz
  • Upload date:
  • Size: 109.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.7.0-gentoo

File hashes

Hashes for fvirt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 004a0ec1d03c6f9b5425023a31d016f78cd2c47be956591db69f3a86b3cd1d01
MD5 6c169dc5ee1c36688e70c820f1b3d245
BLAKE2b-256 d17c1d9de0674b638ffe5b72674671608857db1dcf866247b7aa8dce38a9a181

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fvirt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 155.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.7.0-gentoo

File hashes

Hashes for fvirt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 932e787e6fce1ec32885356d93e7a4af721b0f374f0a14aa9dcc36b736f3214e
MD5 d19cafe630ed00a2728768efeea383b3
BLAKE2b-256 7bef06a9e576701413d4512af6478d642ada3a1e1bf124e1dd0c949b1a324f66

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