TL;DR: qvm-ls
tweaks
I wanted these options:
- Unix like Wildcard support for VM selection. e.g.
qvm-ls fedora*
,qvm-ls *template
, …
Since using grep with Regex is not always convenient (and is considerably slower). - A comprehensive
pref
output format for qvm-ls - Filtering of VMs based on their class or label
- Filtering of VMs based on internal or servicevm features key.
So I implemented them here.
Table of Content
- Background to my
qubesadmin.tools
tweaks qvm-ls
tweaks.- Historic technical decisions, Shared libraries, Easter eggs.
- Other parts of
qubes-core-admin-client
repository.
Background
I felt that the good old qvm-ls(1)
is no more sufficient for my needs and decided to tweak it a little bit. It is not always convenient to pipe qvm-ls
output through various coreutils (grep, awk, sed, …). This is how I found this gem of Qubes repositories.
Historic technical decisions, Shared libraries, Easter eggs.
The upstream repository has very interesting educational and sometimes fun parts. If you have ever opened qvm-ls
(or most other qvm admin tools) in a text editor, you should have recognized that strangely they are almost empty Python scripts, only importing the main code as a library. Actual code is stored in qubesadmin.tools library of qubes-core-admin-client repository as individual .py files. There is a historic commit in setup.py doing this to just save 100 milliseconds since Python libraries are compiled on import rather than interpreted entry points. Considering many Qubes user are still on 2nd Gen Intel CPUs, it is justifiable. Otherwise if you copy the qvm_ls.py
to your ~/bin
directory, rename it to anything, make it executable and add a #!/usr/bin/python3
line on top of the file, it will work exactly like the original qvm-ls. And you can add most of your Tweaks directly inside it. But that would be ugly. Since they are already libraries, I easily imported them and derived new classes with modifications only to routines I needed. There is already a nice hint by Mark inviting adding new formats (and actually a rather simple disabled perf format). I needed maxmem
which was Todo in original file so I implemented it. Adding of filtering options is straight forward with Python argparse and some simple code.
Wildcard support was not as easy as VMNAME input is handled via QubesArgumentParser
, VmNameAction
& VmNameGroup
classes of shared part of qubesadmin.tools
library. On the positive side, if you implement them there, you can use them for all other qubesadmin.tools which support it (qvm-start
, qvm-pause,
qvm-remove`, …). And it runs much faster because of fewer API calls.
time qvm-ls-tt fedora*
takes just 618 milliseconds on this machine whereas
time qvm-ls | grep -e '^\(fedora\|NAME\).*'
takes 2268 milliseconds.
The Easter egg is these nice quotes inside the spinner.py
inserted by Marek & Wojtek Porczyk. It made my day. It made me write my own spinner with braille alphabet.