]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-ls: Add workaround for nested containers
authorStéphane Graber <stgraber@ubuntu.com>
Mon, 16 Dec 2013 20:09:07 +0000 (15:09 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 19 Dec 2013 20:53:15 +0000 (21:53 +0100)
When accessing nested containers, hardcode the path to their config.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc-ls

index e358525925e18a1ee735bdbf48a5d86a26950fcf..b2eea2a10e4c0580d6e3d8663b27f1ee25aa3dfe 100755 (executable)
@@ -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: