GithubHelp home page GithubHelp logo

0x7f9 / kvm-hotplug Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dvaoru/kvm-autoconnect-usb

0.0 0.0 0.0 12 KB

This is a Python script that automates the process of connecting a USB device to a KVM virtual machine.

License: Apache License 2.0

Python 100.00%

kvm-hotplug's Introduction

kvm-autoconnect-usb

This is a Python script that automates the process of connecting a USB device to a KVM virtual machine. The USB device will be automatically attached to the guest when it is connected to the host and detached when it is disconnected.

Deploy the script

Download:

wget https://github.com/dvaoru/kvm-autoconnect-usb/releases/latest/download/kvm-autoconnect-usb.py

Make executable:

sudo chmod +x kvm-autoconnect-usb.py

Usage

Run the script on the KVM host machine.

For starting monitoring a USB device and autoconnection to a virtual machine:

sudo python kvm-autoconnect-usb.py start <usb_vendor_id>:<usb_model_id> <vm_domain_name>

Example:

sudo python kvm-autoconnect-usb.py start 03f0:002a my_debian_vm

For stopping monitoring a USB device and autoconnection to a virtual machine:

sudo python kvm-autoconnect-usb.py stop <usb_vendor_id>:<usb_model_id> <vm_domain_name>

Example:

sudo python kvm-autoconnect-usb.py start 03f0:002a my_debian_vm

For getting a list of USB devices that are automatically connected to the guest:

sudo python kvm-autoconnect-usb.py list

For stopping autoconnecting all USB devices:

sudo python kvm-autoconnect-usb.py clear

How it works under the hood

The script creates a udev rules file /etc/udev/rules.d/80-kvm-autoconnect-usb.rules for monitoring connecting and disconnecting USB devices, and creates a bash file /usr/local/bin/kvm-autoconnect-script.sh to attach and detach the devices to virtual machine by using virsh.

Inspired by

Feedback

If you have any question, email me at [email protected]

kvm-hotplug's People

Contributors

dvaoru 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.