Skip to content

Commit

Permalink
lxc-ls: Cache groups and show bygroup in autostart
Browse files Browse the repository at this point in the history
This makes sure we only query lxc.group once and then reuse that list
for filtering, listing groups and autostart.

When a container is auto-started only as part of a group, autostart will
now show by-group instead of yes.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
stgraber committed May 2, 2014
1 parent 4724cf8 commit 52b0a7d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/lxc/lxc-ls.in
Expand Up @@ -235,11 +235,15 @@ def get_containers(fd=None, base="/", root=False):
except:
continue

if args.groups:
if args.groups or "autostart" in args.fancy_format \
or "groups" in args.fancy_format:
try:
set_has = set(container.get_config_item("lxc.group"))
groups = container.get_config_item("lxc.group")
except KeyError:
set_has = set()
groups = []

if args.groups:
set_has = set(groups)

for group in args.groups:
set_must = set(group.split(","))
Expand Down Expand Up @@ -275,18 +279,17 @@ def get_containers(fd=None, base="/", root=False):

if 'groups' in args.fancy_format:
entry['groups'] = "-"
try:
groups = container.get_config_item("lxc.group")
if len(groups) > 0:
entry['groups'] = ", ".join(groups)
except KeyError:
pass
if len(groups) > 0:
entry['groups'] = ", ".join(groups)

if 'autostart' in args.fancy_format:
entry['autostart'] = "NO"
try:
if container.get_config_item("lxc.start.auto") == "1":
entry['autostart'] = "YES"
if len(groups) > 0:
entry['autostart'] = "BY-GROUP"
else:
entry['autostart'] = "YES"
except KeyError:
pass

Expand Down

0 comments on commit 52b0a7d

Please sign in to comment.