- Programming Assignment 2 - Build your own auto-scaling client server application using the libvirt API
- Problem Statement PDF (https://www.cse.iitb.ac.in/~cs695/pa/pa2.html)
- Demo Video
-
Features:
- Real time CPU utilization graph
- Increase the number of server VM's in case of overload
- Decrease the number of server VM's in case of low load
- Inform the client program (which plays the role of load balancer) in case of VM failures
-
CPU utilization graph plotted in real time by the autoscaler
- The part to the right of
0on the x-axis is the deciding factor for the action taken by the autoscaler
- The part to the right of
-
To run/test the program
- Create a VM in Virtual Machine Manager and put the
server.pycode in it. - Configure the VM to autostart the
server.pyprogram as soon as the OS boots. - Create multiple clones of the same VM and follow a proper naming convention. The numbering should start from 0
- Example:
AnyPrefix-0000,AnyPrefix-0001,AnyPrefix-0002 - Write about this naming convention inside the
client.conffile
- Example:
- Launch the first VM -
AnyPrefix-0000 - Open terminal and run
client.py,client_communicator.py,auto_scaler.py - Use
client_communicator.pyto configure theclient.pyat runtime. Supported functionalities:- Add server syntax =
+ <IP_ADDRESS> <PORT>- Here, IP Address and Port Number are of the server program.
- Remove server syntax =
- <IP_ADDRESS> <PORT>- Here, IP Address and Port Number are of the server program.
- Remove all servers =
clear_servers - Refresh the servers list =
refresh- libvirt API is used for checking the list of online VM's and those VM's whose name prefix does not match with the one mentioned in the
client.confare removed from the list.
- libvirt API is used for checking the list of online VM's and those VM's whose name prefix does not match with the one mentioned in the
- Change client's request/query generation speed:
lowmidhighcustom 0.3<--- here, 0.3 can be replaced with any floating point value
- Add server syntax =
- View the realtime graph plotted by the
auto_scaler.pyto get an insight into the working of the autoscaler
- Create a VM in Virtual Machine Manager and put the
- All configuration files are stored in JSON format
server.pyconfiguration is stored inserver.confclient.pyconfiguration is stored inclient.conf- This same file is used by
auto_scaler.pyas well because, theclient.pyin this assignment is equivalent to a load balancer in real life client_communicator.pyalso uses the same configuration file
- This same file is used by
- The client-server communication message configuration is stored in
message.conf big-endianformat in used for numbers when converted to bytes4 bytes - unsigned intis used to represent client request integers8 bytes - unsigned long longis used to represent server response integers
# virsh is the main interface for managing virsh guest domains.
virsh -V
virsh -c qemu:///system list # connect locally as root to the daemon supervising QEMU and KVM domains
virsh -c qemu:///session list # connect locally as a normal user to his own set of QEMU and KVM domains
# ---
# libvirt internals
cd /var/lib/libvirt
ls -l images
ls -l /etc/libvirt/libvirt.conf
cp /etc/libvirt/libvirt.conf ~/.config/libvirt/
# ---
# Network commands
virsh dumpxml ubuntu18.04
virsh net-list
virsh net-dhcp-leases default
virsh domifaddr ubuntu18.04-1
route
- Installation
- https://help.ubuntu.com/community/KVM/Installation
# Commands used on Linux Mint 20 sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager sudo adduser `id -un` libvirt # sudo adduser $USER libvirt # sudo usermod -aG libvirt $USERNAME sudo adduser `id -un` kvm # sudo adduser $USER kvm # sudo usermod -aG kvm $USERNAME # Probably reboot/restart needed # Check the installation virsh -c qemu:///system list sudo ls -la /var/run/libvirt/libvirt-sock ls -l /dev/kvm service libvirtd status
- To install libvirt python library in virtual environment/conda
- https://stackoverflow.com/questions/45473463/pip-install-libvirt-python-fails-in-virtualenv
sudo apt-get install libvirt-dev
- https://pypi.org/project/libvirt-python/
pip install libvirt-python
- https://stackoverflow.com/questions/45473463/pip-install-libvirt-python-fails-in-virtualenv
- https://unix.stackexchange.com/questions/599651/whats-the-purpose-of-kvm-libvirt-and-libvirt-qemu-groups-in-linux
- https://help.ubuntu.com/community/KVM/Installation
- Introduction
- libvirt
- Client Server Programming
- https://uynguyen.github.io/2018/04/30/Big-Endian-vs-Little-Endian/
- https://stackoverflow.com/questions/21017698/converting-int-to-bytes-in-python-3
- https://stackoverflow.com/questions/34009653/convert-bytes-to-int
- https://www.geeksforgeeks.org/python-convert-string-to-bytes/
- https://tutorialedge.net/python/udp-client-server-python/
- https://www.studytonight.com/network-programming-in-python/working-with-udp-sockets
- https://pythontic.com/modules/socket/udp-client-server-example
- Other references
- https://www.machinelearningplus.com/python/python-logging-guide/
- https://stackoverflow.com/questions/40468370/what-does-cpu-time-represent-exactly-in-libvirtvirsh
- https://stackoverflow.com/questions/19057915/libvirt-fetch-ipv4-address-from-guest
- https://unix.stackexchange.com/questions/33191/how-to-find-the-ip-address-of-a-kvm-virtual-machine-that-i-can-ssh-into-it
- https://www.cyberciti.biz/faq/find-ip-address-of-linux-kvm-guest-virtual-machine/
