[PATCH] virsh: Allow listing just domain IDs

Michal Prívozník mprivozn at redhat.com
Tue Oct 20 13:47:51 UTC 2020

On 10/20/20 3:14 PM, Peter Krempa wrote:
> On Tue, Oct 20, 2020 at 15:02:07 +0200, Michal Privoznik wrote:
>> On 10/20/20 2:46 PM, Peter Krempa wrote:
>>> On Tue, Oct 20, 2020 at 12:27:27 +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.
>>> IMO completing numeric IDs doesn't make much sense, they aren't
>>> descriptive at all and I don't really see a point for users using them
>>> on a commandline. If you are expanding both names and IDs then you'll
>>> have twice as much completion suggestions on an empty string.
>>> Is there a case where it would actually make sense? Specifically in
>>> virsh we almost always accept id/name/UUID interchangably for a
>>> 'domain'.
>> As I'm saying in the commit message - virt-viewer accepts --id, I don't
>> expect ID completer to ever be implemented for virsh because as you say,
>> domnames and/or uuids are accepted universally.
> Okay, I've seen that you've mentioned the completer for virt-viewer but
> I didn't realize it has an explicit --id. It makes sense though since VM
> name allows numeric names, so if a completer suggests both names and ids
> it might end up very confusing.

No, the --name switch is the default; so virt-viewer<TAB><TAB> will 
offer you only the names. Only if you type virt-viewer --id<TAB><TAB> 
you are presented with IDs and IDs only.

And of course mixing IDs with names is horrible thing to do (and I had 
that on mind when writing the virt-viewer completer), but so is UUID and 
name mixing. That is why in virsh we only run name completer and only 
for "domname" command we run UUID completer.

> A potential alternative resolution to my other reply reviewing the code
> would be to make 'virsh list --id' mutually exclusive with '--name' or
> '--uuid'. That would make it usable with a completer completing IDs and
> wouldn't hopefully give anyone false ideas of using it to fetch all 3
> identifiers for completion.

I'll think about it for v2. Thanks!


More information about the libvir-list mailing list