Package: pylibvirt
What is pylibvirtPylibvirt is a tools based on python-libvirt api.
The goal are to create virtual machines, networks, volumes and storage more easily
using yaml description file.How to create template fileThe template must contain at least the provider.After you can declare just what you need.If you just want to create a Storage on your target you can just add storage element.All properties used in the yaml are the same as those used in libvirtProviderCurrently the only tested provider is Qemu/KvmThe URI format is the same as libvirt api.provider:uri:qemu+ssh://root@ip/systemnetworkModeis the type of network, values can be nat, route, open, hostdev and False for
isolated networknetwork:-network_name:mode:natdomain:networkip4_cidr:ipv4_format_cidrdhcp_start:first_ip_to_usedhcp_stop:last_ip_to_usestorageOnlydirstorage have been testedstorage:-storage_name:pool_type:dirpath:storage_pathvolumepool is the storage name declared in libvirt or previously in yaml.name is the end name set to the volume. It’s this name that must used in domain section.The _key_ has no effect you can set what you want.If you want to clone an existing volume or a previouslly create volume you can
use the clone argument with the name of the volume. The two volumes must be in the same
pool.volume:-_key_:disk_format:qcow2capacity:30size_unit:Gpool:storage_namename:volume_namedomain_key_ is the name of the VM, choose what you want.Except the following key [‘memory’, ‘boot_order’, ‘DiskDevice’, ‘domain_type’,‘Feature’, ‘Os’]all other key must be the name of a class in pylibvirt/modules/devicesThe class is called dynamically with the parameters.
Example if you want to add Rng module add an item call RngDevice (class in
pylibvirt/modules/devices/rng.py)RngDevice:-first_rng_device:-arg_class:value-second_rng_device- model:virtio- backend_model:random- host_device:/dev/my_custom_randomdomain:-_key_:boot_order:-cdrom-hdmemory:mem_unit:Gmax_memory:4Os:arch:x86_64machine:q35os_type:hvmFeature:# Features list: https://libvirt.org/formatdomain.html#hypervisor-features-acpi-kvm:hidden:state:'on'poll-control:state:'on'CpuDevice:cpu_model:hostmodel_args:fallback:allowvcpu:2vcpu_args:placement:staticGraphicDevice:-spice_server:graphic_type:spiceVideoDevice:-screen:model_type:qxlram:66500DiskDevice:-disk:volume:debian-10-2.qcow2driver:qemubus:scsipool:data-cdrom:volume:debian-10.10.0-amd64-netinst.isopool:dataNetworkInterfaceDevice:-default:net_interface:defaultnet_type:networkmodel:e1000eHow to installRequirementsYou need to install the following packages on your system to install python-libvirt in a virtualenvFedoraRPM dependenciesdnfinstallpython3-develpkgconfiglibvirt-develpipinstallpylibvirtDebianDEB dependenciesaptinstallpython3-devpkg-configlibvirt-devpipinstallpylibvirtHow to useCli usagepylibvirt-t/path/to/template.ymlUse in python codeTo use pylibvirt in your python code you can do:call manager and set file pathimportpylibvirtpylibvirt.Manager(template='path_to_file')or call manager and directly pass template objectimportpylibvirtpylibvirt.Manager(template=[yamlobject])Create your external moduleIf you want to create your own pylibvirt modules you must create a class that inherits fromfrompylibvirt.modules.devicesimportDeviceand implement methodgenerate_data(self)In your setup.py you must register itfromsetuptoolsimportsetupsetup(name='cute_snek',entry_points={'pylibvirt_modules':['ClassName = ModuleName',],})If you use poetry configure your toml like this[tool.poetry.plugins."pylibvirt_modules"]ClassName='ModuleName'You can find example of modules in pylibvirt/modules/devices