osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new to python - like to write a script with the libvirt-python 5.3.0 package


On 03Jun2019 16:32, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>On Mon, 3 Jun 2019 17:05:52 +0200 (CEST), "Lentes, Bernd"
><bernd.lentes at helmholtz-muenchen.de> declaimed the following:
>>I wrote a shellscript to create consistent images of the virtual 
>>machines each night, using the bash and virsh (the libvirt shell).
>>Script is running fairly fine, but i need to extend it.
>>I'm thinking of rewriting it in python, i think that would be a good practise.
>>Inside the script i'm using things like "virsh start, virsh shutdown, virsh
>>snaphot-list, virsh snapshot, virsh snapshot-delete, virsh domblklist, 
>>virsh blockcommit, virsh list, virsh define ..." 
>
>	The big thing I see is that all of those are separate invocations to
>command line operations. That gets clunky with Python (spawn a new process
>for each command, handle output from it, etc.).

Note of course that his shell script is doing that too, though "invoke a 
separate command" is pretty much the shell's core function :-)

>>Can i use all the possibilities i have in virsh in that 
>>libvirt-package ?
>
>	https://libvirt.org/bindings.html	indicates that there is a Python
>binding to the actual libvirt library. On a Debian system, apt-get appears
>to be able to find something [...]
>	Using the API means you will not be invoking "virsh" commands
>themselves. You will have to become familiar with the API equivalent to the
>commands you were using.

Or he could just "python3 -m pip install libvirt-python", since it is 
published on PyPI.

Cheers,
Cameron Simpson <cs at cskk.id.au>