[lxc-users] Wildcard in lxd commands?
Janne Savikko
janne.savikko at aalto.fi
Thu Mar 17 13:01:13 UTC 2016
On 03/17/2016 01:03 AM, zztest at openmailbox.org wrote:
> On 2016-03-16 11:12, Serge Hallyn wrote:
>> Quoting zztest at openmailbox.org (zztest at openmailbox.org):
>>> Will wildcards be supported in lxd commands? For example, I'd like
>>> to do this:
>>>
>>> $ lxc info host:*
>>>
>>> or
>>>
>>> $ lxc info host:web*
>>>
>>> and get info on all containers/containers starting with "web" on host.
>>>
>>> Is there a quick/easy way to do something similar now?
>>
>> See 'lxc help list'. Filters should get you what you want.
>
> How would I use that in a command? For example would I stop dozens of
> containers whose names begin with "web" using the filter?
>
lxc list is not the easiest to parse
(https://github.com/lxc/lxd/issues/882). List uses tablewriter
(https://github.com/olekukonko/tablewriter) to format output, but it
does not have option to output e.g. CSV (sure you can use comma as a
column separator, but you get whitespaces because columns data is
variable length).
You can not use filters to list running or stopped containers. Lxc start
or stop do not support filters, only container name (or names). You
though can always pipe commands if you want to stop dozens of containers
whose names begin with "web" (note! lxc list keyword filter compares
from the start of the name, so "lxc list eb" does not work in this case):
$ lxc list web|grep RUNNING|awk '{ print $2 }'|xargs lxc stop
More information about the lxc-users
mailing list