Skip to main content

Our KVM solution, clulstered and self hosted

Project description

ourkvm

Our KVM solution. Cluster, API and local tools all in one.

API

The API is a rest API enabled by running python -m ourkvm --api
The API is built using FastAPI.

The API requires authentication and uses OpenID connect and JWT for SSO.
This is done using fastapi_resource_server.

The API will support numerous day-to-day activities such as creating, managing and migrating machines between your cluster.

Cluster

The cluster is a feature being developer where the aim is to be able to share resources using KVM in a sensible way. Priority will be on static load balancing, but the goal is to have live balancing between cluster nodes.

Tools

The library ships with a Python module that can produce local resources such as Qemu disk images, Virtual Machine templates, configuration and .service files.

Creating a local virtual machine

$ python -m ourkvm \
    --machine-name testmachine \
    --namespace testmachine \
    --memory 4096 \
    --harddrives ./testimg.qcow2:20G,./testlarge.qcow2:40G \
    --cdroms ~/archiso/out/*.iso \
    --service /etc/systemd/system/testmachine.service \
    --config /etc/qemu.d/testmachine.cfg

The following will create a minimal virtual machine using NAT for networking, headless operation meant to be started with systemctl start testmachine.service.

Stopping a machine

$ sudo systemctl stop testmachine.service

Using the above example service of testmachine.service, the service will trigger python -m ourkvm --machine-name testmachine --stop which will attach to the Qemu QMP socket at /tmp/testmachine.qmp and execute a poweroff (followed by qemu-quit after a grace period if the machine has not yet powered off).

Adding custom networking

$ python -m ourkvm \
    --machine-name testmachine \
    --namespace testmachine \
    --memory 4096 \
    --harddrives ./testimg.qcow2:20G,./testlarge.qcow2:40G \
    --cdroms ~/archiso/out/*.iso \
    --service /etc/systemd/system/testmachine.service \
    --config /etc/qemu.d/testmachine.cfg \
    --network '[{"type": "tap", "name": "tap0", "bridge": "ns_br0", "namespace": "testmachine"}, {"type": "veth", "name": "vens0", "bridge": "test_bridge", "veth_pair": "vens0_ns"}, {"type": "veth", "name": "vens0_ns", "bridge": "ns_br0", "namespace": "testmachine", "veth_pair": "vens0"}]'

Adding to the previous example, this will add networking according to the following JSON layout:

[
    {
        "type": "tap",
        "name": "tap0",
        "bridge": "ns_br0",
        "namespace": true
    },
    {
        "type": "veth",
        "name": "vens0",
        "bridge": "test_bridge",
        "veth_pair": "vens0_ns"
    },
    {
        "type": "veth",
        "name": "vens0_ns",
        "bridge": "ns_br0",
        "namespace": true,
        "veth_pair": "vens0"
    }
]

This creates several network components. Beginning from the top of the JSON file (but backwards logically):

  1. A tap0 interface attached to the virtual machine
  2. A bridge ns_br0 connecting tap0 to it
  3. Moving the above two interfaces into a namespace called testmachine
  4. Creating a veth-pair of vens0<-->vens0_ns
  5. Creating a bridge called test_bridge
  6. Adding vens0 to the test_bridge
  7. Moving vens0_ns into the namespace testmachine

Creating a network chain that looks like the following:
[host] test_bridge <--> vens0--|--vens0_ns <--> ns_br0 <--> tap0 [vm].
The API will take care of creating the elaborate network infrastructure, but the CLI does the work for now.

Note: the namespace declaration in the network struct is True and will get automatically converted to the --namespace definition. Specific namespace names can be supplied here instead of the VM should connect between multiple namespaces using bridges or veth interfaces.

Contributing

We use tabs over spaces. We follow pep8 to some extent using Flake8 (see .flake8 for exceptions). We follow strict typing using mypy with the --strict parameter and we require every function to have a associated pytest function under /tests/.

We welcome PR's on any addition/change. They might not all make it, but we develop straight against main which is our master branch. Occational vX.y.z-dev branch might appear to fix an older version while a major release is being on the way. PR's will not be merged until the three GitHub workflows (flake8, mypy and pytest) have completed successfully.

Help

Feel free to open a issue if you think it's a bug or you want to suggest an improvement.

Discussions

Open a discussion on a topic you believe is relevant to discuss or talk about surrounding ourkvm, if it doesn't fit the #help section.

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

python-ourkvm-0.0.13.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

python_ourkvm-0.0.13-py2.py3-none-any.whl (27.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-ourkvm-0.0.13.tar.gz.

File metadata

  • Download URL: python-ourkvm-0.0.13.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python-ourkvm-0.0.13.tar.gz
Algorithm Hash digest
SHA256 d15d9ae084d2388ecc95273db7a308b0e339951977c64149bfee960a97800240
MD5 19b25e2025fe70f4a9b043ffeb6e3000
BLAKE2b-256 c1fc8c94e1c28d3b2cf88a9fa8d792bc6e967280b324a26e0908f1e9056d088e

See more details on using hashes here.

Provenance

File details

Details for the file python_ourkvm-0.0.13-py2.py3-none-any.whl.

File metadata

  • Download URL: python_ourkvm-0.0.13-py2.py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python_ourkvm-0.0.13-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8307b390891075c235ff32ba86a0e210a4bd1a4d5124f80993665e12716a146b
MD5 275ed3e7d5a6a44fea18aa5a83fc5b33
BLAKE2b-256 87f52e5e61e1283272d6f02fcae17d4ac18d43692fca8c2cfce5b94ebc57e9fd

See more details on using hashes here.

Provenance

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