Package: virt-lightning
🗲 spawn Cloud instances on libvirt!🗲You want to spawn local VM quickly.. Like... really quickly. You want them to be as generical as possible. Actually you would like to reuse some existing cloud images!This is the right tool for you.Virt-Lightning exposes a CLI inspired by the Cloud and Vagrant.
It can also prepare the Ansible inventory file.This is handy to quickly validate a new Ansible playbook, or a role on a large number of environments.example: less than 30 seconds to spawn an instance ⚡In a nutshell:echo"- distro: centos-7">virt-lightning.yaml
vlup
vlansible_inventory>inventory
ansibleall-mping-iinventoryexample: or 75 seconds for 10 nodes lab ⚡During this recording, we:use the list of distribution to generate a virt-lightning.yaml file.we then create a environment based on this fileonce the environment is ready, we generate an Ansible inventory fileand we use it to call Ansible's ping module on all the host.Pre-requirementsPython 3.8 or greater.The Python3 binding for libvirt, the package is probably calledpython3-libvirt.You can also just build the binding during the install, in this case, you will need to install some packages first:dnf install libvirt-devel python3-devel(Fedora/RHEL)apt install libvirt-dev python3-dev(Debian/Ubuntu)You make also want to installpython3-urwidif you want to get the fancy list of VM. This dependency is optional.Libvirt must be running, most of the time you just need to run:sudo systemctl start --now libvirtdFinally, be sure your user can access the system libvirt daemon, e.g with:virsh -c qemu:///systemInstallationpip3install--uservirt-lightningIf you use Ubuntu, you will need the--no-depsargument (See:https://github.com/pypa/pip/issues/4222).virt-lightningwill be installed in ~/.local/bin/. Add it in your$PATHif
it's not already the case. For instance if you use:echo"export PATH=$PATH:~/.local/bin/">>~/.bashrcsource~/.bashrcFetch some imagesBefore you start your first VM, you need to fetch the images. To do so,
you just use thevl fetchcommand:$vlfetchfedora-32Actionsvlis an alias forvirt-lightning, you can us both. In the rest of the document
we use the shortest version.vl distro_listList the distro images that can be used. Its output is compatible withvl up. You can initialize a new configuration with:vl distro_list > virt-lightning.yaml.vl upvirt-lightningwill read thevirt-lightning.yamlfile from the current directory and prepare the associated VM.vl downDestroy all the VM managed by Virt-Lightning.vl startStart a specific VM, without reading thevirt-lightning.yamlfile.vl stopStop just one VM.vl statusList the VM, their IP and if they are reachable.vl ansible_inventoryExport an inventory in the Ansible format.vl sshShow up a menu to select a host and open a ssh connection.vl consoleLikevl sshbut with the serial console of the VM.vl viewerLikevl consolebut with the SPICE console of the VM. Requiresvirt-viewer.vl fetchFetch a VM image.You can find here a list of the available images. You can also update the custom configuration to add a private image hub.ConfigurationGlobal configurationIf~/.config/virt-lightning/config.iniexists, Virt-Lightning will read
its configuration there.[main]network_name=virt-lightningroot_password=rootstorage_pool=virt-lightningnetwork_auto_clean_up=Truessh_key_file=~/.ssh/id_rsa.pubnetwork_name: if you want to use an alternative libvirt networkroot_password: the root passwordstorage_pool: if you want to use an alternative libvirt storage poolnetwork_auto_clean_up: if you want to automatically remove a network when runningvirt-lightning downssh_key_file: if you want to use an alternative public keyprivate_hub: if you need to set additional url from where images should be retrieved, update the configuration file~/.config/virt-lightning/config.iniadding the following[main]
private_hub=url1,url2VM configuration keysA VM can be tuned at two different places with the following keys:distro: the name of the base distro image to use, it's the only mandatory parameter.name: the VM namememory: the amount of memory to dedicate to the VMvcpus: the number of vcpu to dedicate to the VMroot_password: the root password in clear textssh_key_file: the path of the public key for connecting to the VMgroups: this list of groups will be used if you generate an Ansible inventory.disks: a list of disks to create and attach to the VM. The first one is used as the root disk. Default to[{"size": 15}]sizethe size of the disk in GB. Default is1.networks: a list of network to attach to the VM. The default is: one virtio interface attached tovirt-lightningnetwork.network: the name of the libvirt network. Default is the keynetwork_namefrom the configuration (virt-lightningby default). The key cannot be used withbridge.ipv4: a static IPv4. Default is a dynamic IPv4 address.nic_model: the libvirt driver to use. Default isvirtiomac: an optional static MAC address, e.g: '52:54:00:71:b1:b6'bridge: optional, the name of a bridge to connect too. This key replace thenetworkkey.virtualport_type: The type of the virtualport, currently, this is can be used withbridge.Example: avirt-lightning.yamlfile:-name:esxi-vcenterdistro:esxi-6.7memory:12000root_disk_size:30vcpus:2root_password:'!234AaAa56'groups:['all_esxi']-name:esxi1distro:esxi-6.7memory:4096vcpus:1root_password:'!234AaAa56'groups:['all_esxi','esxi_lab']-name:esxi2distro:esxi-6.7memory:4096vcpus:1root_password:'!234AaAa56'groups:['all_esxi','esxi_lab']-name:centos-7distro:centos-7networks:-network:defaultipv4:192.168.122.50bootcmd:-yum update -yExample: connect to an OpenvSwitch bridge-name:controllerdistro:fedora-35-bridge:my-ovs-bridge-namevirtualport_type:openvswitchYou can also associate some parameters to the distro image itselfcat/var/lib/virt-lightning/pool/upstream/esxi-6.7.yaml
username:root
python_interpreter:/bin/python
memory:4096networks:-network:virt-lightningnic_model:virtio-network:defaultnic_model:e1000Example: working with snapshotsUser can create a snapshot of VM to restore it later. Default configuration ofvirt-lightningsupports snapshots both
for running and powered off VMs.qcow2disk format used allows diskspace-wise incremental snapshotting, keeping only
updated storage blocks.virshtool supports it by CLI,virt-managerprovides a neat GUI supporting the most of
the features# create first snapshot of running machinevirshsnapshot-create-as--domainvm_name--namesnapshot_1# create second snapshotvirshsnapshot-create-as--domainvm_name--namesnapshot_2# validate that both of them were savedvirshsnapshot-listvm_name# and revert to the first onevirshsnapshot-revertvm_name--snapshotnamesnapshot_1=======Developmentinstall libvirt-dev package:Debian/Ubuntu:apt-getinstallpython3-venvpython3-devpkg-configgcclibvirt-devFedora/RHEL:dnfinstallpython3-develgcclibvirt-develYou can run a development copy in a virtual env:python3-mvenv/tmp/vl-dev-venv
./tmp/vl-dev-venv/bin/activate
pip3install-rrequirements.txt
pip3install-e/path/to/my-virt-lightning-copy
vlThe changes that are introduce in /path/to/my-virt-lightning-copy should be visible when you run vl from within the virtual env.
running test will require:pip3install-rtest-requirements.txt