List all template VMs?

154 views
Skip to first unread message

johannes...@gmail.com

unread,
Nov 5, 2014, 8:33:07 AM11/5/14
to qubes...@googlegroups.com
Hello,

I'm setting out to manage an entire qubes setup using ansible.

One of the steps I would like to automate is to update the template machines present.

Is there an easy way to get their names on the CLI?

And BTW: what do the name-bracketing characters in "=>[TEMPLATE]" imply?

Thank you for your time.

Sincerely, Joh

Marek Marczykowski-Górecki

unread,
Nov 5, 2014, 2:50:22 PM11/5/14
to johannes...@gmail.com, qubes...@googlegroups.com
On Wed, Nov 05, 2014 at 05:33:07AM -0800, johannes...@gmail.com wrote:
> Hello,
>
> I'm setting out to manage an entire qubes setup using ansible.
>
> One of the steps I would like to automate is to update the template machines present.
>
> Is there an easy way to get their names on the CLI?

Currently only two ways:
- parsing output of qvm-ls (type colum, or better - updateable flag)
- with simple python code, like this:
from qubes.qubes import QubesVmCollection
qc = QubesVmCollection()
qc.lock_db_for_reading()
qc.load()
qc.unlock_db()
for vm in qc.values():
if vm.is_template():
print vm.name

> And BTW: what do the name-bracketing characters in "=>[TEMPLATE]" imply?

Brackets means "template", arrow means "default template".

--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

Marek Marczykowski-Górecki

unread,
Nov 6, 2014, 2:42:15 PM11/6/14
to johannes...@gmail.com, qubes...@googlegroups.com
On Thu, Nov 06, 2014 at 08:59:27AM +0300, johannes...@gmail.com wrote:
> On Wednesday 05 November 2014 20:50:15 Marek Marczykowski-Górecki wrote:
> > On Wed, Nov 05, 2014 at 05:33:07AM -0800, johannes...@gmail.com wrote:
> > > Hello,
> > >
> > > I'm setting out to manage an entire qubes setup using ansible.
> > >
> > > One of the steps I would like to automate is to update the template
> > > machines present.
> > >
> > > Is there an easy way to get their names on the CLI?
> >
> > Currently only two ways:
> > - parsing output of qvm-ls (type colum, or better - updateable flag)
> > - with simple python code, like this:
> > from qubes.qubes import QubesVmCollection
> > qc = QubesVmCollection()
> > qc.lock_db_for_reading()
> > qc.load()
> > qc.unlock_db()
> > for vm in qc.values():
> > if vm.is_template():
> > print vm.name
> >
> > > And BTW: what do the name-bracketing characters in "=>[TEMPLATE]" imply?
> >
> > Brackets means "template", arrow means "default template".
> Wouldn't that imply that
> qvm-ls | grep -oP '\[\K[^\]]+'
> Should work fine?

Hmm, indeed it should just work.

Bahtiar Gadimov

unread,
Nov 8, 2014, 6:59:04 AM11/8/14
to Marek Marczykowski-Górecki, johannes...@gmail.com, qubes...@googlegroups.com
2014-11-06 20:42 GMT+01:00 Marek Marczykowski-Górecki
<marm...@invisiblethingslab.com>:
> On Thu, Nov 06, 2014 at 08:59:27AM +0300, johannes...@gmail.com wrote:
>> On Wednesday 05 November 2014 20:50:15 Marek Marczykowski-Górecki wrote:
>> > On Wed, Nov 05, 2014 at 05:33:07AM -0800, johannes...@gmail.com wrote:
>> > > Hello,
>> > >
>> > > I'm setting out to manage an entire qubes setup using ansible.

How do you manage your vms via ansible? Did you write a plugin which
uses qvm-run?

>> > > One of the steps I would like to automate is to update the template
>> > > machines present.

I wrote a zsh script for this:

#!/usr/bin/env zsh
local -a targets
targets=( $( qvm-ls|grep Yes|cut -d'|' -f1,7|grep -v ' \- $'|tr -d '
{}[]<>='|cut -d'|' -f1) )
for t in $targets; do
if [[ $t == dom0 ]]; then
sudo qubes-dom0-update
else
print -P "%F{0}%K{7}[Updating $t]%k%f"
for tm in {xfce4-terminal,gnome-terminal,xterm}; do # we do
not know what kind of terminal is installed in the machine
qvm-run --auto -qp --user=root $t "$tm -e 'yum update -y'" && break
print -P "%K{1}Error in $t%k assuming $tm not found"
done
command qvm-shutdown $t
fi
done
wait

You are probably interested in line 3.

In general the qvm-ls tool is suboptimal. I noticed the following issues:

- There is no way to find out if a template needs to be updated (I
just grep all machines which are updateable, and just try to update
them)
- Each time i use qvm-ls my whole terminal explodes with thousand of
bar characters, if it's not wide enough.
- Also i miss the abillity to show only running machines.

So i wrote a ZSH script which displays the same information cleaner:
https://gist.github.com/kalkin/d2c1f837618294671267 (with qls -a it
shows all machines).

@Marek
Perhaps this would be a good output format, which could be adopted by
qvm-ls? I could come up with a patch if you like.

Sorry for partly hijacking this thread :). I hope i could help.
kalkin

Marek Marczykowski-Górecki

unread,
Nov 8, 2014, 6:25:50 PM11/8/14
to Bahtiar Gadimov, johannes...@gmail.com, qubes...@googlegroups.com
Generally qvm-ls is meant to be user tool, not scripts backend. For this
you can use simple python scripts, as I've written earlier in this
thread.
But indeed, sometimes it would be easier to write one-liner in bash
instead of python, especially if someone isn't familiar with python.
Should we introduce machine-readable qvm-ls output format? Any
suggestions for the format? CSV?

> So i wrote a ZSH script which displays the same information cleaner:
> https://gist.github.com/kalkin/d2c1f837618294671267 (with qls -a it
> shows all machines).
>
> @Marek
> Perhaps this would be a good output format, which could be adopted by
> qvm-ls? I could come up with a patch if you like.
>
> Sorry for partly hijacking this thread :). I hope i could help.
> kalkin

Wojciech Zygmunt Porczyk

unread,
Nov 10, 2014, 3:30:44 PM11/10/14
to Marek Marczykowski-Górecki, Bahtiar Gadimov, johannes...@gmail.com, qubes...@googlegroups.com
On Sun, Nov 09, 2014 at 12:25:40AM +0100, Marek Marczykowski-Górecki wrote:
> Should we introduce machine-readable qvm-ls output format? Any
> suggestions for the format? CSV?

1) Let's get rid of the ASCII art table anyway. It contributes nothing.
Compare it to `xl list`, `virsh list` etc.

2) Make „flags” field for boolean (and close to boolean) attributes,
like „internal”, „include in backups” and even „running”.

3) Let user choose freely from available columns (in addition to current
switches like -n). Cf. `ps -o`. Let him/her(/it in case of software)
choose even arbitrary variables aka properties. It's really easier than
it sounds.

4) Introduce simple filters like "templates", "only running", "HVM" etc.
(vm.__class__.__name__ == ...)

5) Do it in R3, for #853 (Qubes Admin API).


--
regards, _.-._
Wojciech Porczyk .-^' '^-.
Invisible Things Lab |'-.-^-.-'|
| | | |
I do not fear computers, | '-.-' |
I fear lack of them. '-._ : ,-'
-- Isaac Asimov `^-^-_>

Marek Marczykowski-Górecki

unread,
Nov 10, 2014, 7:10:11 PM11/10/14
to Bahtiar Gadimov, johannes...@gmail.com, qubes...@googlegroups.com
On Mon, Nov 10, 2014 at 09:30:38PM +0100, Wojciech Zygmunt Porczyk wrote:
> On Sun, Nov 09, 2014 at 12:25:40AM +0100, Marek Marczykowski-Górecki wrote:
> > Should we introduce machine-readable qvm-ls output format? Any
> > suggestions for the format? CSV?
>
> 1) Let's get rid of the ASCII art table anyway. It contributes nothing.
> Compare it to `xl list`, `virsh list` etc.
>
> 2) Make „flags” field for boolean (and close to boolean) attributes,
> like „internal”, „include in backups” and even „running”.
>
> 3) Let user choose freely from available columns (in addition to current
> switches like -n). Cf. `ps -o`. Let him/her(/it in case of software)
> choose even arbitrary variables aka properties. It's really easier than
> it sounds.
>
> 4) Introduce simple filters like "templates", "only running", "HVM" etc.
> (vm.__class__.__name__ == ...)
>
> 5) Do it in R3, for #853 (Qubes Admin API).

Agree. Care to add a comment in the ticket?

johannes...@gmail.com

unread,
Nov 11, 2014, 1:13:01 PM11/11/14
to Marek Marczykowski-Górecki, qubes...@googlegroups.com
On Wednesday 05 November 2014 20:50:15 Marek Marczykowski-Górecki wrote:
> On Wed, Nov 05, 2014 at 05:33:07AM -0800, johannes...@gmail.com wrote:
> > Hello,
> >
> > I'm setting out to manage an entire qubes setup using ansible.
> >
> > One of the steps I would like to automate is to update the template
> > machines present.
> >
> > Is there an easy way to get their names on the CLI?
>
> Currently only two ways:
> - parsing output of qvm-ls (type colum, or better - updateable flag)
> - with simple python code, like this:
> from qubes.qubes import QubesVmCollection
> qc = QubesVmCollection()
> qc.lock_db_for_reading()
> qc.load()
> qc.unlock_db()
> for vm in qc.values():
> if vm.is_template():
> print vm.name
>
> > And BTW: what do the name-bracketing characters in "=>[TEMPLATE]" imply?
>
> Brackets means "template", arrow means "default template".
Wouldn't that imply that
qvm-ls | grep -oP '\[\K[^\]]+'
Should work fine?

Sincerely, Joh

Wojciech Zygmunt Porczyk

unread,
Nov 12, 2014, 9:29:36 AM11/12/14
to Marek Marczykowski-Górecki, Bahtiar Gadimov, johannes...@gmail.com, qubes...@googlegroups.com
On Tue, Nov 11, 2014 at 01:10:02AM +0100, Marek Marczykowski-Górecki wrote:
> On Mon, Nov 10, 2014 at 09:30:38PM +0100, Wojciech Zygmunt Porczyk wrote:
> > On Sun, Nov 09, 2014 at 12:25:40AM +0100, Marek Marczykowski-Górecki wrote:
> > > Should we introduce machine-readable qvm-ls output format? Any
> > > suggestions for the format? CSV?
> >
> > 1) Let's get rid of the ASCII art table anyway. It contributes nothing.
> > Compare it to `xl list`, `virsh list` etc.
> >
> > 2) Make „flags” field for boolean (and close to boolean) attributes,
> > like „internal”, „include in backups” and even „running”.
> >
> > 3) Let user choose freely from available columns (in addition to current
> > switches like -n). Cf. `ps -o`. Let him/her(/it in case of software)
> > choose even arbitrary variables aka properties. It's really easier than
> > it sounds.
> >
> > 4) Introduce simple filters like "templates", "only running", "HVM" etc.
> > (vm.__class__.__name__ == ...)
> >
> > 5) Do it in R3, for #853 (Qubes Admin API).
>
> Agree. Care to add a comment in the ticket?

I think it should be separate ticket: https://wiki.qubes-os.org/ticket/923
Reply all
Reply to author
Forward
0 new messages