lxc-ls: Cache groups and show bygroup in autostart

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: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 4724cf84
...@@ -235,11 +235,15 @@ def get_containers(fd=None, base="/", root=False): ...@@ -235,11 +235,15 @@ def get_containers(fd=None, base="/", root=False):
except: except:
continue continue
if args.groups: if args.groups or "autostart" in args.fancy_format \
or "groups" in args.fancy_format:
try: try:
set_has = set(container.get_config_item("lxc.group")) groups = container.get_config_item("lxc.group")
except KeyError: except KeyError:
set_has = set() groups = []
if args.groups:
set_has = set(groups)
for group in args.groups: for group in args.groups:
set_must = set(group.split(",")) set_must = set(group.split(","))
...@@ -275,18 +279,17 @@ def get_containers(fd=None, base="/", root=False): ...@@ -275,18 +279,17 @@ def get_containers(fd=None, base="/", root=False):
if 'groups' in args.fancy_format: if 'groups' in args.fancy_format:
entry['groups'] = "-" entry['groups'] = "-"
try: if len(groups) > 0:
groups = container.get_config_item("lxc.group") entry['groups'] = ", ".join(groups)
if len(groups) > 0:
entry['groups'] = ", ".join(groups)
except KeyError:
pass
if 'autostart' in args.fancy_format: if 'autostart' in args.fancy_format:
entry['autostart'] = "NO" entry['autostart'] = "NO"
try: try:
if container.get_config_item("lxc.start.auto") == "1": 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: except KeyError:
pass pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment