<arg choice="opt">--stopped</arg>
<arg choice="opt">-f</arg>
<arg choice="opt">-F <replaceable>format</replaceable></arg>
+ <arg choice="opt">-g <replaceable>groups</replaceable></arg>
<arg choice="opt">--nesting</arg>
<arg choice="opt">filter</arg>
</cmdsynopsis>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <option><optional>-g, --groups <replaceable>groups</replaceable></optional></option>
+ </term>
+ <listitem>
+ <para>
+ Comma separated list of groups the container must have to be displayed.
+ The parameter may be passed multiple times.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term>
<option><optional>--nesting</optional></option>
# Constants
FIELDS = ("name", "state", "interfaces", "ipv4", "ipv6", "autostart", "pid",
- "memory", "ram", "swap")
-DEFAULT_FIELDS = ("name", "state", "ipv4", "ipv6", "autostart")
+ "memory", "ram", "swap", "groups")
+DEFAULT_FIELDS = ("name", "state", "ipv4", "ipv6", "groups", "autostart")
# Begin parsing the command line
parser = argparse.ArgumentParser(description=_("LXC: List containers"),
default=",".join(DEFAULT_FIELDS),
help=_("comma separated list of fields to show"))
+parser.add_argument("-g", "--groups", type=str, action="append",
+ metavar="GROUPS",
+ help=_("groups (comma separated) the container must "
+ "be a member of"))
+
parser.add_argument("--nesting", dest="nesting", action="store_true",
help=_("show nested containers"))
parser.error(_("Showing nested containers requires setns to the "
"PID namespace which your kernel doesn't support."))
+## Check that -g is passed alongside -f
+if args.groups and not args.fancy:
+ parser.error(_("Group filtering requires fancy formatting."))
+
# Set the actual lxcpath value
if not args.lxcpath:
args.lxcpath = lxc.default_config_path
except:
continue
+ if args.groups:
+ try:
+ set_has = set(container.get_config_item("lxc.group"))
+ except KeyError:
+ set_has = set()
+
+ for group in args.groups:
+ set_must = set(group.split(","))
+ if not set_must - set_has:
+ break
+ else:
+ continue
+
if container.controllable:
state = container.state
else:
elif container.init_pid != -1:
entry['pid'] = str(container.init_pid)
+ 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 'autostart' in args.fancy_format:
entry['autostart'] = "NO"
try:
if container.get_config_item("lxc.start.auto") == "1":
entry['autostart'] = "YES"
-
- groups = container.get_config_item("lxc.group")
- if len(groups) > 0:
- entry['autostart'] = "YES (%s)" % ", ".join(groups)
except KeyError:
pass