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>
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'))
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.")
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)"))
# 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
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:
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"))
% (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"))
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]
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