[lxc-devel] [PATCH] lxc-ls: Cache groups and show bygroup in autostart

Stéphane Graber stgraber at ubuntu.com
Fri May 2 20:34:08 UTC 2014


On Fri, May 02, 2014 at 08:23:27PM +0000, Serge Hallyn wrote:
> Quoting Stéphane Graber (stgraber at ubuntu.com):
> > 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 at ubuntu.com>
> 
> Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
> 
> > ---
> >  src/lxc/lxc-ls.in | 23 +++++++++++++----------
> >  1 file changed, 13 insertions(+), 10 deletions(-)
> > 
> > diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in
> > index 64dd121..d1faaa2 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)
> 
> If not args.groups but autostart in args.fancy_format, you won't have set
> groups to [] but will be using it here to set set_has. 

I don't understand.

If args.groups is set (-g is passed) or any of autostart or groups are
in fancy_format, then groups will be set to the right value.

set_has is only relevant and used when comparing the set of groups
provided on the command line with those the container has, so that part
only applies if args.groups is set.


What did I miss?

> >  
> >                  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
> >  
> > -- 
> > 1.9.1
> > 
> > _______________________________________________
> > lxc-devel mailing list
> > lxc-devel at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-devel
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140502/6c3a260c/attachment-0001.sig>


More information about the lxc-devel mailing list