Giter Club home page Giter Club logo

vfio-vm-switcher's Introduction

VFIO VM Switcher

Allow control of VFIO virtual machines from within VFIO virtual machines.

This is designed for situations where you have multiple VM definitions which use the same hardware, so only one can be powered on at a time.

This is a simple API which runs on the host, and allows the guest ask for itself to be shut down, and have a different VM booted up instead. This allows the user to swap between VM's without switching mouse/keyboard/monitor input to the host operating system.

Installation notes

Substitute the username mike for your own username where applicable. The script assumes you are in the libvirt group and can control VM's.

Build the UI first:

cd ui
npm install
npm run build

Next build the python bundle.

sudo apt install libvirt-dev libpython3-dev build-essential
python3 -m venv venv/
./venv/bin/pip install -r requirements.txt
./venv/bin/pyinstaller --add-data "ui/dist/:ui/dist/" --onefile app/main.py

App is then a binary at ./dist/main

Invoking API from web

When you run the app, the work-in-progress UI becomes available at http://localhost:8000/ui/.

This is a placeholder, and can't be used for VM control yet.

Invoking API from command-line

Invocation via curl, list domains:

curl -Ss http://192.168.122.1:8000/api/domain

Ask for testbox-2 to be booted up (everything else will be shut down first)

curl -Ss -X PATCH http://192.168.122.1:8000/api/domain/testbox-2 -H 'Content-Type: application/json' -d '{"state" : "RUNNING"}'

Ask for everything to be shut off, and for the host to be powered off.

curl -Ss -X PATCH http://192.168.122.1:8000/api/host -H 'Content-Type: application/json' -d '{"state" : "SHUTOFF"}'

Assuming that the binary is in /opt/vm-switcher, it may be installed by creating the following /etc/systemd/system/vm-switcher.service:

Installation as service

[Unit]
Description=VM Switcher

[Service]
ExecStart=/opt/vm-switcher/main
WorkingDirectory=/opt/vm-switcher/
User=mike

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable vm-switcher
systemctl start vm-switcher

Note that full root permissions are not required, though to allow the script to run poweroff on the host, you will also need to create /etc/sudoers.d/00-poweroff.

mike ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff

License

The VFIO VM Switcher is licesnsed under the GNU General Public License version 2 or later. Please see the LICENSE file in this repository for details.

Some files incorporated in this project are derived from other open source codebases:

  • The favicon used for this project's web interface is derived from blobs-l.svg from [gnome-backgrounds], originally by Jakub Steiner, and is licensed under Creative Commons Attribution-ShareAlike 3.0 License.
  • The VFIO VM switcher GNOME extension in this repository is derived from a template from the GNOME shell extensions tool (a subproject of GNOME Shell), and is licensed under the GNU GPL version 2 or later.

vfio-vm-switcher's People

Contributors

mike42 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.