Code Monkey home page Code Monkey logo

simple-vmcontrol's Introduction

Simple VM Control UI

Very minimal web UI for creating and deleting Libvirt/KVM VMs.

I wrote this quick and dirty system because it seemed the existing web UIs there were for Libvirt/KVM had more dependencies than I wanted to have installed on my VM host. This system is therefore fairly self contained and only dependant on Python and Lighttpd, besides Libvirt and KVM itself of course. No other libraries needed.

As this system was written specifically for a VM host I had, I took the shortcut of hardcoding some paths:

  • VM disk images will be created in /srv/vm/
  • OS installation ISO image files are expected to be in /srv/iso/

Screenshot

Server setup

My VM host is a basic Debian 7 installation.

Installation

cd /usr/lib
git clone https://github.com/allanrbo/simple-vmcontrol.git

mkdir -p /var/www/html/cgi-bin
ln -s /usr/lib/simple-vmcontrol/cgi-bin/vmcontrol.py /var/www/html/cgi-bin/vmcontrol.py

Allow the web server to switch to root to run the control commands by adding the following to /etc/sudoers

www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/listvm.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/createvm.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/deletevm.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/mountiso.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/startvm.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/stopvm.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/createdatadisk.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/deletedatadisk.py
www-data ALL=NOPASSWD: /usr/lib/simple-vmcontrol/vmcontrol/setautostart.py

Web server setup

Installed lighttpd:

apt-get install lighttpd python
lighttpd-enable-mod cgi
lighttpd-enable-mod ssl
lighttpd-enable-mod auth
cd /etc/lighttpd/
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=server" -x509 -days 3650 -out server.crt
cat server.crt server.key > server.pem
chmod 400 server.pem

Configured lighttpd by adding a file /etc/lighttpd/conf-enabled/myserver.conf:

# Only allow https on vmcontrol.py
$HTTP["scheme"] == "http" {
    $HTTP["url"] =~ "^/cgi-bin/vmcontrol.py" {
         url.access-deny = ("")
    }
}

# Require login for vmcontrol.pyn
$HTTP["url"] =~ "^/cgi-bin/vmcontrol.py" {
    auth.backend = "htpasswd"
    auth.backend.htpasswd.userfile = "/etc/lighttpd/htpasswd"
    auth.require = ( "" => (
        "method"  => "basic",
        "realm"   => "",
        "require" => "valid-user"
    ))
}

Created the file /etc/lighttpd/htpasswd with credentials I wanted to use (for example use http://aspirine.org/htpasswd_en.html ).

Restarted Lighttpd for changes to take effect:

/etc/init.d/lighttpd restart

KVM and Libvirt setup

Installed KVM and Libvirt:

apt-get install qemu-kvm virtinst bridge-utils libvirt-clients libvirt-daemon-system

Modified /etc/network/interfaces

allow-hotplug eno1
iface eno1 inet manual

auto br0
iface br0 inet dhcp
    bridge_ports eno1

Created folder for VM disk images and relocated folder containing save states:

mkdir /srv/iso
mkdir /srv/vm
mv /var/lib/libvirt/ /srv/libvirt ; ln -s /srv/libvirt /var/lib/libvirt

Modified /etc/init.d/libvirt-guests

ON_BOOT=start
ON_SHUTDOWN=suspend

License

Simple VM Control UI is licensed under the MIT license.

simple-vmcontrol's People

Contributors

allanrbo avatar

Watchers

James Cloos avatar  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.