Virt-manager as an online service

It so happened that I needed a tool to manage my virtual machines outside the office, and at the same time, a Linux machine was not always at hand. Previously, I had to actively use Putty and the console utility virsh, which was very annoying not so much to manage virtual machines as to create them. At first, he wrote bash scripts to optimize his actions, but this was not always convenient.

Then I began to learn Python along the way, everything that was scripted in bash began to translate into Python. And then the idea came up to write a web interface for managing your virtual machines in the office, well, and those that spin for personal purposes. Since personal needs were being addressed, it was originally planned to hide such a thing on a web server, there was no talk of public even in thoughts. But after two weeks of intensive work on the task, when an almost no big web project was drawn up, a friend suggested putting it all in the public domain for which he allocated me a virtual machine for the project.

Project


WebVirtMgr is a centralized virtual machine management service. The main technologies used are: KVM hypervisor and libvirt virtualization management library. Creating, installing, backing up, configuring, and starting virtual machines are implemented as an easy-to-learn web interface. To organize the screen forwarding of virtual machines into a browser window, a VNC client is used through an SSH tunnel.

Technology


All logic is written in Python using the Django framework. Python interacts with the hypervisor using the Libvirt library. The default hypervisor is KVM.

How is it all set up


To work, we need a server with any Linux OS distribution installed. True, some features of libvirt are not supported in Debian \ Ubuntu, unlike RedHat family distributions, namely working with network interfaces. Although this is not affected by the bridge (br0), you can configure the console to flush network interfaces for virtual machines through the console. The following is an example of how to configure CentOS 6.2, and how to configure Ubuntu can be found at this link .

First things first, install the KVM and libvirt packages:

# yum -y install kvm libvirt

uncomment the line in the file / etc / sysconfig / libvirtd the following line:

# Listen for TCP / IP connections
# NB. must setup TLS / SSL keys prior to using this
LIBVIRTD_ARGS = "- listen"

in the file /etc/libvirt/libvirtd.conf uncomment the lines:

listen_tls = 0
listen_tcp = 1

run the libvirtd daemon:

# service libvirtd start

create a user to manage your virtual machines, where fred username:
# saslpasswd2 -a libvirt fred
Password: xxxxxx
Again (for verification): xxxxxx

If you want your virtual machines to look outside, then the instructions for setting up a bridge for your network interfaces are here .

Then we go to the site itself , register, confirm the registration, log in.

Before adding a virtualization server to the WebVirtMgr service, check the iptables settings (Ubuntu - ufw) and make a test connection to your hypervisor from the console:

# virsh -c qemu + tcp: // your_server_IP / system nodeinfo
Please enter your authentication name: fred
Please enter your password: xxxxxx
CPU model: x86_64
CPU (s): 2
CPU frequency: 2611 MHz
CPU socket (s): 1
Core (s) per socket: 2
Thread (s) per core: 1
NUMA cell (s): 1
Memory size: 2019260 kB

if you did not see errors, but saw information about the system, then feel free to add your virtualization server to the service and manage virtual machines.

Conclusion


When writing the project, I got real experience with Django and Python, which I really liked. I hope that what happens will benefit someone else besides me, I will be very pleased if this is true. Even if you didn’t like anything, there is something to work on. If you have suggestions or recommendations, or maybe questions, then you are welcome.

PS: Panel WebVirtMgr to install on your server.

Also popular now: