[PATCH v2] virsh: Allow listing just domain IDs

Michal Prívozník mprivozn at redhat.com
Sat Nov 7 10:43:05 UTC 2020


On 11/6/20 2:59 PM, Martin Kletzander wrote:
> On Thu, Oct 22, 2020 at 04:41:18PM +0200, Michal Privoznik wrote:
>> Some completers for libvirt related tools might want to list
>> domain IDs only. Just like the one I've implemented for
>> virt-viewer [1]. I've worked around it using some awk magic,
>> but if it was possible to just 'virsh list --id' then I could
>> drop awk.
>>
>> 1: https://www.redhat.com/archives/virt-tools-list/2019-May/msg00014.html
>>
>> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>> ---
>>
>> Diff to v1:
>> - Documented the new switch in the manpage
>> - Allowed --id to be used with --all
>>
>> docs/manpages/virsh.rst      | 21 +++++++++---------
>> tools/virsh-domain-monitor.c | 42 +++++++++++++++++++++++++-----------
>> 2 files changed, 39 insertions(+), 24 deletions(-)
>>
>> diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
>> index d34a1c8684..848e1a6458 100644
>> --- a/docs/manpages/virsh.rst
>> +++ b/docs/manpages/virsh.rst
>> @@ -621,7 +621,7 @@ list
>>
>>    list [--inactive | --all]
>>         [--managed-save] [--title]
>> -        { [--table] | --name | --uuid }
>> +        { [--table] | --name | --uuid | --id }
>>         [--persistent] [--transient]
>>         [--with-managed-save] [--without-managed-save]
>>         [--autostart] [--no-autostart]
>> @@ -758,16 +758,15 @@ If *--managed-save* is specified, then domains 
>> that have managed save state
>> in the listing. This flag is usable only with the default *--table* 
>> output.
>> Note that this flag does not filter the list of domains.
>>
>> -If *--name* is specified, domain names are printed instead of the table
>> -formatted one per line. If *--uuid* is specified domain's UUID's are 
>> printed
>> -instead of names. Flag *--table* specifies that the legacy 
>> table-formatted
>> -output should be used. This is the default.
>> -
>> -If both *--name* and *--uuid* are specified, domain UUID's and names
>> -are printed side by side without any header. Flag *--table* specifies
>> -that the legacy table-formatted output should be used. This is the
>> -default if neither *--name* nor *--uuid* are specified. Option
>> -*--table* is mutually exclusive with options *--uuid* and *--name*.
>> +If *--name* is specified, domain names are printed instead of the
>> +table formatted one per line. If *--uuid* is specified domain's UUID's
>> +are printed instead of names. If *--id* is specified then domain's ID's
>> +are printed indead of names. However, it is possible to combine
>> +*--name*, *--uuid* and *--id* to select only desired fields for
>> +printing. Flag *--table* specifies that the legacy table-formatted
>> +output should be used, but it is mutually exclusive with *--name*,
>> +*--uuid* and *--id*. This is the default and will be used if neither of
>> +*--name*, *--uuid* or *--id* is specified.
>>
> 
> Didn't you want to add something like the following?
> 
>    If neither *--name* nor *--uuid* is specified, but *--id* is, then 
> only active
>    domains are listed, even with the *--all* parameter as otherwise the 
> output
>    would just contain bunch of lines with just *-1*. >
> Otherwise the code is very unclear for no reason.

Yes, this behaviour is not documented. Mostly because I don't expect 
regular users to use 'virsh list --id'. It was meant for completers, 
e.g. virt-viewer has --id argument and its completer could list domain 
IDs. Is it okay if I squash your suggestion in and push? Or do you want 
me to send v3?

Michal




More information about the libvir-list mailing list