From: Stéphane Graber Date: Mon, 16 Dec 2013 20:09:07 +0000 (-0500) Subject: lxc-ls: Add workaround for nested containers X-Git-Tag: lxc-1.0.0.beta2~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfd149a646bf7ada7e896e07494e5cde0859e437;p=thirdparty%2Flxc.git lxc-ls: Add workaround for nested containers When accessing nested containers, hardcode the path to their config. Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- diff --git a/src/lxc/lxc-ls b/src/lxc/lxc-ls index e35852592..b2eea2a10 100755 --- a/src/lxc/lxc-ls +++ b/src/lxc/lxc-ls @@ -88,7 +88,7 @@ def getTerminalSize(): return int(cr[1]), int(cr[0]) -def getSubContainers(container, lxcpath): +def getSubContainers(container): with open(os.devnull, "w") as fd: fdnum, path = tempfile.mkstemp() os.remove(path) @@ -162,7 +162,9 @@ if not sys.stdout.isatty(): args.one = True # Set the lookup path for the containers -lxcpath = os.environ.get('NESTED', args.lxcpath) +# This value will contain the full path for a nested containers +# use args.lxcpath if you need the value relative to the container +nest_lxcpath = os.environ.get('NESTED', args.lxcpath) # Turn args.fancy_format into a list args.fancy_format = args.fancy_format.strip().split(",") @@ -196,7 +198,7 @@ if args.nesting: # List of containers, stored as dictionaries containers = [] -for container_name in lxc.list_containers(config_path=lxcpath): +for container_name in lxc.list_containers(config_path=nest_lxcpath): entry = {} entry['name'] = container_name @@ -211,6 +213,10 @@ for container_name in lxc.list_containers(config_path=lxcpath): container = lxc.Container(container_name, args.lxcpath) + if 'NESTED' in os.environ: + container.load_config(os.path.join(nest_lxcpath, container_name, + "config")) + if container.controllable: state = container.state else: @@ -272,7 +278,7 @@ for container_name in lxc.list_containers(config_path=lxcpath): # Nested containers if args.nesting and container.state == "RUNNING": - sub = getSubContainers(container, args.lxcpath) + sub = getSubContainers(container) if sub: for entry in sub: if 'nesting_parent' not in entry: