From: Stéphane Graber Date: Fri, 2 May 2014 17:19:46 +0000 (-0400) Subject: lxc-ls: Cache groups and show bygroup in autostart X-Git-Tag: lxc-1.1.0.alpha1~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52b0a7d983e93e3c05eb152128f0fd70e31a5483;p=thirdparty%2Flxc.git 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: Stéphane Graber --- diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in index 64dd12193..d1faaa216 100755 --- a/src/lxc/lxc-ls.in +++ b/src/lxc/lxc-ls.in @@ -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(",")) @@ -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