📜 ⬆️ ⬇️

Virt-manager as an online service

It so happened that I needed a tool to manage my virtual computers out of the office and it wasn’t always a Linux machine at hand. Previously, we had to actively use Putty and the virsh console utility, which was very annoying even not so much the management of virtuals as their creation. At first, I wrote bash scripts to optimize my actions, but this was not always convenient.

Here I also began to learn Python along the way, everything that was written in bash began to be translated into Python. And then the idea arose to write a web interface to manage your virtual computers in the office, well, and those that spin for personal purposes. Since personal needs were resolved, it was originally planned to hide such a thing on my web server, there was no talk of public even in thoughts. But after two weeks of intensive work on the task, when almost a large web project was drawn, a friend suggested putting it all in open access, for which he gave me a virtual server for the project.

Project


WebVirtMgr centralized virtual machine management service. The main technologies used are: KVM hypervisor and libvirt virtualization management library. Creation, installation, backup, configuration and launch of virtual machines are implemented as an easy-to-learn web interface. To organize screen forwarding of virtual machines to the browser window, the VNC client is used through an SSH tunnel.

Technology


All logic is written in Python using the Django framework. For interaction of Python'a with a hypervisor library Libvirt is used. The default hypervisor is KVM.
')

How is all this customizable


To work we need a server with any Linux distribution installed. However, in Debian \ Ubuntu, some functions of libvirt are not supported, unlike the distributions of the RedHat family, namely, work with network interfaces. Although this has nothing to do with a bridge (br0) for throwing network interfaces for virtual machines, you can also configure it via the console. The following is an example of setting up CentOS 6.2, and how to configure Ubuntu can be found at this link .

All in order, install the KVM and libvirt packages:

 # yum -y install kvm libvirt

Let's open the following line in the / etc / sysconfig / libvirtd file:

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

in the /etc/libvirt/libvirtd.conf file, we uncover 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 instruction on how to configure the bridge for your network interfaces is here .

Next we go to the site itself , register, confirm 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: // IP_ of your_server / 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 have not seen any errors, but have seen system information, then feel free to add your virtualization server to the service and manage virtual machines.

Conclusion


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

PS: Panel WebVirtMgr for installation on your server.

Source: https://habr.com/ru/post/135063/


All Articles