]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
python: Update the python scripts for lxcpath
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 21 Feb 2013 20:11:29 +0000 (15:11 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 21 Feb 2013 21:32:34 +0000 (16:32 -0500)
This adds -P/--lxcpath to the various python scripts.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc-device
src/lxc/lxc-ls
src/lxc/lxc-start-ephemeral.in
src/python-lxc/lxc/__init__.py.in

index db9399d2afb1322802b2adb829510f14e5f07743..b194b056fe7af85c1b3d1dac110007d6668d5dc7 100644 (file)
@@ -47,6 +47,9 @@ parser.add_argument("-n", dest="container", metavar="CONTAINER",
                     help=_("Name of the container to add the device to"),
                     required=True)
 
+parser.add_argument("-P", "--lxcpath", dest="lxcpath", metavar="PATH",
+                    help=_("Use specified container path"), default=None)
+
 # Commands
 subparsers = parser.add_subparsers()
 subparser_add = subparsers.add_parser('add', help=_('Add a device'))
@@ -76,7 +79,8 @@ if not args.name:
     args.name = args.device
 
 ## Check that the container is ready
-container = lxc.Container(args.container)
+container = lxc.Container(args.container, args.lxcpath)
+
 if not container.running:
     parser.error("The container must be running.")
 
index 98b786167048b41c069f34839b0bceeec0d61993..92a4e536aab909be4dc7d776d6fb7e375ad3a799 100644 (file)
@@ -92,6 +92,9 @@ parser = argparse.ArgumentParser(description=_("LXC: List containers"),
 parser.add_argument("-1", dest="one", action="store_true",
                     help=_("list one container per line (default when piped)"))
 
+parser.add_argument("-P", "--lxcpath", dest="lxcpath", metavar="PATH",
+                    help=_("Use specified container path"), default=None)
+
 parser.add_argument("--active", action="store_true",
                     help=_("list only active containers "
                            "(same as --running --frozen)"))
@@ -138,7 +141,7 @@ if not os.geteuid() == 0 and (args.fancy or args.state):
 
 # List of containers, stored as dictionaries
 containers = []
-for container_name in lxc.list_containers():
+for container_name in lxc.list_containers(config_path=args.lxcpath):
     entry = {}
     entry['name'] = container_name
 
@@ -151,7 +154,7 @@ for container_name in lxc.list_containers():
         containers.append(entry)
         continue
 
-    container = lxc.Container(container_name)
+    container = lxc.Container(container_name, args.lxcpath)
 
     # Filter by status
     if args.state and container.state not in args.state:
index e11919fb45df7a15561256b6c3a746baf575b8b8..3e2a5d35bf9ab400effd6c0a6a6d5cc724a1c542 100644 (file)
@@ -64,6 +64,9 @@ container when exiting (with ctrl-a-q).
 If no COMMAND is given and -d is used, the name and IP addresses of the
 container will be printed to the console."""))
 
+parser.add_argument("--lxcpath", "-P", dest="lxcpath", metavar="PATH",
+                    help=_("Use specified container path"), default=None)
+
 parser.add_argument("--orig", "-o", type=str, required=True,
                     help=_("name of the original container"))
 
@@ -104,16 +107,21 @@ if not os.geteuid() == 0:
                    % (sys.argv[0])))
 
 # Load the orig container
-orig = lxc.Container(args.orig)
+orig = lxc.Container(args.orig, args.lxcpath)
 if not orig.defined:
     parser.error(_("Source container '%s' doesn't exist." % args.orig))
 
 # Create the new container paths
-dest_path = tempfile.mkdtemp(prefix="%s-" % args.orig, dir="@LXCPATH@")
+if not args.lxcpath:
+    lxc_path = lxc.default_config_path
+else:
+    lxc_path = args.lxcpath
+
+dest_path = tempfile.mkdtemp(prefix="%s-" % args.orig, dir=lxc_path)
 os.mkdir(os.path.join(dest_path, "rootfs"))
 
 # Setup the new container's configuration
-dest = lxc.Container(os.path.basename(dest_path))
+dest = lxc.Container(os.path.basename(dest_path), args.lxcpath)
 dest.load_config(orig.config_file_name)
 dest.set_config_item("lxc.utsname", dest.name)
 dest.set_config_item("lxc.rootfs", os.path.join(dest_path, "rootfs"))
index 151a5058d4e4c9746734bd8b6f1aee90ae98fd2c..e262c23c2e41a8367115861375ae57c0d03c34f0 100644 (file)
@@ -238,7 +238,8 @@ class Container(_lxc.Container):
         if not self.running:
             return False
 
-        attach = ["lxc-attach", "-n", self.name]
+        attach = ["lxc-attach", "-n", self.name,
+                  "-P", self.get_config_path()]
         if namespace != "ALL":
             attach += ["-s", namespace]
 
@@ -299,7 +300,8 @@ class Container(_lxc.Container):
         if not self.running:
             return False
 
-        if subprocess.call(["lxc-console", "-n", self.name, "-t", "%s" % tty],
+        if subprocess.call(["lxc-console", "-n", self.name, "-t", "%s" % tty,
+                            "-P", self.get_config_path()],
                            universal_newlines=True) != 0:
             return False
         return True